Skip to content

Commit b2bd82b

Browse files
committed
fix first run check
1 parent 48ca0c8 commit b2bd82b

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

alz/azuredevops/pipelines/bicep/templates/helpers/bicep-first-deployment-check.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ steps:
1414
Inline: |
1515
$intRootMgId = "$(MANAGEMENT_GROUP_ID_PREFIX)$(INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID)$(MANAGEMENT_GROUP_ID_POSTFIX)"
1616
17-
$managementGroups = Get-AzManagementGroup
18-
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
17+
$managementGroup = Get-AzManagementGroup -GroupName $intRootMgId -Expand
1918
2019
$firstDeployment = $true
2120
22-
if($intRootMg -eq $null) {
21+
if($managementGroup -eq $null) {
2322
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment."
2423
} else {
25-
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
26-
$firstDeployment = $false
24+
Write-Host "Found the $intRootMgId Management Group."
25+
$children = $managementGroup.Children | Where-Object { $_.Type -eq "Microsoft.Management/managementGroups" }
26+
if($children.Count -gt 0) {
27+
Write-Host "The $intRootMgId Management Group has child management groups, so this is NOT the first deployment."
28+
$firstDeployment = $false
29+
} else {
30+
Write-Host "The $intRootMgId Management Group has NO child management groups, so assuming this is the first deployment."
31+
}
2732
}
2833
2934
Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$firstDeployment"

alz/github/actions/bicep/templates/actions/bicep-first-deployment-check/action.yaml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,21 @@ runs:
1717
inlineScript: |
1818
$intRootMgId = $env:MANAGEMENT_GROUP_ID_PREFIX + $env:INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID + $env:MANAGEMENT_GROUP_ID_POSTFIX
1919
20-
$managementGroups = Get-AzManagementGroup
21-
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
20+
$managementGroup = Get-AzManagementGroup -GroupName $intRootMgId -Expand
2221
2322
$firstDeployment = $true
2423
25-
if($intRootMg -eq $null) {
26-
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment. We must skip checking some deployments since their dependent resources do not exist yet."
24+
if($managementGroup -eq $null) {
25+
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment."
2726
} else {
28-
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
29-
$firstDeployment = $false
27+
Write-Host "Found the $intRootMgId Management Group."
28+
$children = $managementGroup.Children | Where-Object { $_.Type -eq "Microsoft.Management/managementGroups" }
29+
if($children.Count -gt 0) {
30+
Write-Host "The $intRootMgId Management Group has child management groups, so this is NOT the first deployment."
31+
$firstDeployment = $false
32+
} else {
33+
Write-Host "The $intRootMgId Management Group has NO child management groups, so assuming this is the first deployment."
34+
}
3035
}
3136
echo "firstDeployment=$firstDeployment" >> $env:GITHUB_ENV
3237
env:

0 commit comments

Comments
 (0)