Skip to content

Commit 18af2de

Browse files
authored
Incremented Job State validation with Sleep (#81)
1 parent c9f6319 commit 18af2de

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Tools/PowershellModule/src/Library/New-ARMObjects.ps1

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ Function New-ARMObjects
102102

103103
## Creates the Azure Resource
104104
Write-Information -MessageData " Creating $($Object.ObjectType) following the ARM Parameter File..."
105-
$Result = New-AzResourceGroupDeployment -ResourceGroupName $AzResourceGroup -TemplateFile $Object.TemplatePath -TemplateParameterFile $Object.ParameterPath -Mode Incremental -ErrorAction SilentlyContinue -ErrorVariable objerror
105+
$Result = New-AzResourceGroupDeployment -ResourceGroupName $AzResourceGroup -TemplateFile $Object.TemplatePath -TemplateParameterFile $Object.ParameterPath -Mode Incremental -ErrorAction SilentlyContinue -ErrorVariable objerror -AsJob
106106

107-
## Sets a sleep of 10 seconds after object creation to allow Azure to update creation status, and mark as "running"
108-
Start-Sleep -Seconds 10
107+
while ($Result.State -eq "Running") {
108+
## Sets a sleep of 10 seconds after object creation to allow Azure to update creation status, and mark as "running"
109+
Start-Sleep -Seconds 10
110+
}
109111

110112
## Verifies that no error occured when creating the Azure resource
111-
if($objerror) {
113+
if($objerror -or $Result.Error) {
112114
$ErrReturnObject = @{
113115
ObjectError = $objerror
116+
JobError = $Result.Error
114117
}
115118
## Creating the object following the ARM template failed.
116119
Write-Error "Failed to create Azure object." -TargetObject $ErrReturnObject

0 commit comments

Comments
 (0)