Skip to content

Commit 7c44623

Browse files
committed
fix what if
1 parent 15ae4f1 commit 7c44623

3 files changed

Lines changed: 39 additions & 70 deletions

File tree

alz/azuredevops/pipelines/bicep/templates/cd-template.yaml

Lines changed: 7 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,9 @@ stages:
5454
parameters:
5555
serviceConnection: '${service_connection_name_plan}'
5656

57-
- task: AzurePowerShell@5
58-
displayName: 'Check for First Deployment'
59-
inputs:
60-
azureSubscription: '${service_connection_name_plan}'
61-
pwsh: true
62-
azurePowerShellVersion: LatestVersion
63-
ScriptType: "InlineScript"
64-
Inline: |
65-
$intRootMgId = "$(INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID)"
66-
67-
$managementGroups = Get-AzManagementGroup
68-
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
69-
70-
$firstDeployment = $true
71-
72-
if($intRootMg -eq $null) {
73-
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment. We must skip what-if for some deployments since their dependent resources do not exist yet."
74-
} else {
75-
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
76-
$firstDeployment = $false
77-
}
78-
79-
Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$firstDeployment"
57+
- template: ./helpers/bicep-first-deployment-check.yaml
58+
parameters:
59+
serviceConnection: '${service_connection_name_plan}'
8060

8161
%{ for script_file in script_files ~}
8262
- $${{ if eq(parameters['${script_file.name}'], true) }}:
@@ -131,34 +111,14 @@ stages:
131111
parameters:
132112
parametersFileName: $(PARAMETERS_FILE_NAME)
133113

134-
- task: AzurePowerShell@5
135-
displayName: 'Check for First Deployment'
136-
inputs:
137-
azureSubscription: '${service_connection_name_apply}'
138-
pwsh: true
139-
azurePowerShellVersion: LatestVersion
140-
ScriptType: "InlineScript"
141-
Inline: |
142-
$intRootMgId = "$(MANAGEMENT_GROUP_ID_PREFIX)$(INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID)$(MANAGEMENT_GROUP_ID_POSTFIX)"
143-
144-
$managementGroups = Get-AzManagementGroup
145-
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
146-
147-
$firstDeployment = $true
148-
149-
if($intRootMg -eq $null) {
150-
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment."
151-
} else {
152-
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
153-
$firstDeployment = $false
154-
}
155-
156-
Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$firstDeployment"
157-
158114
- template: ./helpers/bicep-installer.yaml
159115
parameters:
160116
serviceConnection: '${service_connection_name_apply}'
161117

118+
- template: ./helpers/bicep-first-deployment-check.yaml
119+
parameters:
120+
serviceConnection: '${service_connection_name_apply}'
121+
162122
%{ for script_file in script_files ~}
163123
- $${{ if eq(parameters['${script_file.name}'], true) }}:
164124
- template: ./helpers/bicep-deploy.yaml

alz/azuredevops/pipelines/bicep/templates/ci-template.yaml

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -70,29 +70,9 @@ stages:
7070
parameters:
7171
serviceConnection: '${service_connection_name_plan}'
7272

73-
- task: AzurePowerShell@5
74-
displayName: 'Check for First Deployment'
75-
inputs:
76-
azureSubscription: '${service_connection_name_plan}'
77-
pwsh: true
78-
azurePowerShellVersion: LatestVersion
79-
ScriptType: "InlineScript"
80-
Inline: |
81-
$intRootMgId = "$(MANAGEMENT_GROUP_ID_PREFIX)$(INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID)$(MANAGEMENT_GROUP_ID_POSTFIX)"
82-
83-
$managementGroups = Get-AzManagementGroup
84-
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
85-
86-
$firstDeployment = $true
87-
88-
if($intRootMg -eq $null) {
89-
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment. We must skip what-if for some deployments since their dependent resources do not exist yet."
90-
} else {
91-
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
92-
$firstDeployment = $false
93-
}
94-
95-
Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$firstDeployment"
73+
- template: ./helpers/bicep-first-deployment-check.yaml
74+
parameters:
75+
serviceConnection: '${service_connection_name_plan}'
9676

9777
%{ for script_file in script_files ~}
9878
- template: ./helpers/bicep-deploy.yaml
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
parameters:
3+
- name: serviceConnection
4+
type: string
5+
6+
steps:
7+
- task: AzurePowerShell@5
8+
displayName: 'Check for First Deployment'
9+
inputs:
10+
azureSubscription: $${{ parameters.serviceConnection }}
11+
pwsh: true
12+
azurePowerShellVersion: LatestVersion
13+
ScriptType: "InlineScript"
14+
Inline: |
15+
$intRootMgId = "$(MANAGEMENT_GROUP_ID_PREFIX)$(INTERMEDIATE_ROOT_MANAGEMENT_GROUP_ID)$(MANAGEMENT_GROUP_ID_POSTFIX)"
16+
17+
$managementGroups = Get-AzManagementGroup
18+
$intRootMg = $managementGroups | Where-Object { $_.Name -eq $intRootMgId }
19+
20+
$firstDeployment = $true
21+
22+
if($intRootMg -eq $null) {
23+
Write-Warning "Cannot find the $intRootMgId Management Group, so assuming this is the first deployment."
24+
} else {
25+
Write-Host "Found the $intRootMgId Management Group, so assuming this is not the first deployment."
26+
$firstDeployment = $false
27+
}
28+
29+
Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$firstDeployment"

0 commit comments

Comments
 (0)