|
| 1 | +--- |
| 2 | +trigger: none |
| 3 | + |
| 4 | +parameters: |
| 5 | + - name: skip_what_if |
| 6 | + displayName: 'Skip What-If Stage' |
| 7 | + type: boolean |
| 8 | + default: false |
| 9 | +%{ for script_file in script_files ~} |
| 10 | + - name: ${script_file.name} |
| 11 | + displayName: '${script_file.displayName}' |
| 12 | + type: boolean |
| 13 | + default: true |
| 14 | +%{ endfor ~} |
| 15 | + |
| 16 | +variables: |
| 17 | + PARAMETERS_FILE_NAME: 'parameters.json' |
| 18 | + |
| 19 | +stages: |
| 20 | + - stage: WhatIf |
| 21 | + displayName: 'What If' |
| 22 | + condition: ne('$${{ parameters.skip_what_if }}', true) |
| 23 | + jobs: |
| 24 | + - deployment: whatif |
| 25 | + displayName: 'What If Deployment' |
| 26 | + pool: |
| 27 | + ${agent_pool_configuration} |
| 28 | + environment: '${environment_name_plan}' |
| 29 | + strategy: |
| 30 | + runOnce: |
| 31 | + deploy: |
| 32 | + steps: |
| 33 | + - task: PowerShell@2 |
| 34 | + displayName: 'Show Parameters' |
| 35 | + inputs: |
| 36 | + targetType: 'inline' |
| 37 | + pwsh: true |
| 38 | + script: | |
| 39 | + Write-Host "Parameters:" |
| 40 | + Write-Host "skip_what_if: $${{ parameters.skip_what_if }}" |
| 41 | +%{ for script_file in script_files ~} |
| 42 | + Write-Host "${script_file.name}: $${{ parameters['${script_file.name}'] }}" |
| 43 | +%{ endfor ~} |
| 44 | + |
| 45 | + - checkout: self |
| 46 | + displayName: 'Checkout Bicep Module' |
| 47 | + |
| 48 | + - template: ./helpers/bicep-avm-variables.yaml |
| 49 | + parameters: |
| 50 | + parametersFileName: $(PARAMETERS_FILE_NAME) |
| 51 | + |
| 52 | + - task: AzurePowerShell@5 |
| 53 | + displayName: 'Check for First Deployment' |
| 54 | + inputs: |
| 55 | + azureSubscription: '${service_connection_name_plan}' |
| 56 | + pwsh: true |
| 57 | + azurePowerShellVersion: LatestVersion |
| 58 | + ScriptType: "InlineScript" |
| 59 | + Inline: | |
| 60 | + $managementGroupId = "$$(MANAGEMENT_GROUP_ID)" |
| 61 | + $intRootMgId = "$$managementGroupId-int-root" |
| 62 | + $managementGroups = Get-AzManagementGroup |
| 63 | + $intRootMg = $$managementGroups | Where-Object { $$.Name -eq $$intRootMgId } |
| 64 | +
|
| 65 | + $firstDeployment = $$true |
| 66 | +
|
| 67 | + if($$intRootMg -eq $$null) { |
| 68 | + 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." |
| 69 | + } else { |
| 70 | + Write-Host "Found the $$intRootMgId Management Group, so assuming this is not the first deployment." |
| 71 | + $$firstDeployment = $$false |
| 72 | + } |
| 73 | +
|
| 74 | + Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$$firstDeployment" |
| 75 | +
|
| 76 | + - template: ./helpers/bicep-avm-installer.yaml |
| 77 | + parameters: |
| 78 | + serviceConnection: '${service_connection_name_plan}' |
| 79 | + |
| 80 | +%{ for script_file in script_files ~} |
| 81 | +%{ if try(script_file.networkType, "") != "" ~} |
| 82 | + - $${{ if and(eq(parameters['${script_file.name}'], true), eq(variables['NETWORK_TYPE'], '${script_file.networkType}')) }}: |
| 83 | + - template: ./helpers/bicep-avm-deploy.yaml |
| 84 | + parameters: |
| 85 | + displayName: '${script_file.displayName} (Network Type: ${script_file.networkType})' |
| 86 | + serviceConnection: '${service_connection_name_plan}' |
| 87 | + templateFilePath: '${script_file.templateFilePath}' |
| 88 | + templateParametersFilePath: '${script_file.templateParametersFilePath}' |
| 89 | + managementGroupId: '${script_file.managementGroupIdVariable}' |
| 90 | + subscriptionId: '${script_file.subscriptionIdVariable}' |
| 91 | + resourceGroupName: '${script_file.resourceGroupNameVariable}' |
| 92 | + location: '$(LOCATION)' |
| 93 | + deploymentType: '${script_file.deploymentType}' |
| 94 | + firstRunWhatIf: ${script_file.firstRunWhatIf} |
| 95 | + networkType: '${script_file.networkType}' |
| 96 | + whatIfEnabled: true |
| 97 | + |
| 98 | +%{ else ~} |
| 99 | + - $${{ if eq(parameters['${script_file.name}'], true) }}: |
| 100 | + - template: ./helpers/bicep-avm-deploy.yaml |
| 101 | + parameters: |
| 102 | + displayName: '${script_file.displayName}' |
| 103 | + serviceConnection: '${service_connection_name_plan}' |
| 104 | + templateFilePath: '${script_file.templateFilePath}' |
| 105 | + templateParametersFilePath: '${script_file.templateParametersFilePath}' |
| 106 | + managementGroupId: '${script_file.managementGroupIdVariable}' |
| 107 | + subscriptionId: '${script_file.subscriptionIdVariable}' |
| 108 | + resourceGroupName: '${script_file.resourceGroupNameVariable}' |
| 109 | + location: '$(LOCATION)' |
| 110 | + deploymentType: '${script_file.deploymentType}' |
| 111 | + firstRunWhatIf: ${script_file.firstRunWhatIf} |
| 112 | + whatIfEnabled: true |
| 113 | + |
| 114 | +%{ endif ~} |
| 115 | +%{ endfor ~} |
| 116 | + |
| 117 | + - stage: Deploy |
| 118 | + displayName: 'Deploy' |
| 119 | + dependsOn: WhatIf |
| 120 | + condition: and(not(failed()), not(canceled())) |
| 121 | + jobs: |
| 122 | + - deployment: deploy |
| 123 | + displayName: 'Deploy Bicep' |
| 124 | + pool: |
| 125 | + ${agent_pool_configuration} |
| 126 | + environment: '${environment_name_apply}' |
| 127 | + strategy: |
| 128 | + runOnce: |
| 129 | + deploy: |
| 130 | + steps: |
| 131 | + - task: PowerShell@2 |
| 132 | + displayName: 'Show Parameters' |
| 133 | + inputs: |
| 134 | + targetType: 'inline' |
| 135 | + pwsh: true |
| 136 | + script: | |
| 137 | + Write-Host "Parameters:" |
| 138 | + Write-Host "skip_what_if: $${{ parameters.skip_what_if }}" |
| 139 | +%{ for script_file in script_files ~} |
| 140 | + Write-Host "${script_file.name}: $${{ parameters['${script_file.name}'] }}" |
| 141 | +%{ endfor ~} |
| 142 | + |
| 143 | + - checkout: self |
| 144 | + displayName: 'Checkout Bicep Module' |
| 145 | + |
| 146 | + - template: ./helpers/bicep-avm-variables.yaml |
| 147 | + parameters: |
| 148 | + parametersFileName: $(PARAMETERS_FILE_NAME) |
| 149 | + |
| 150 | + - task: AzurePowerShell@5 |
| 151 | + displayName: 'Check for First Deployment' |
| 152 | + inputs: |
| 153 | + azureSubscription: '${service_connection_name_apply}' |
| 154 | + pwsh: true |
| 155 | + azurePowerShellVersion: LatestVersion |
| 156 | + ScriptType: "InlineScript" |
| 157 | + Inline: | |
| 158 | + $managementGroupId = "$$(MANAGEMENT_GROUP_ID)" |
| 159 | + $intRootMgId = "$$managementGroupId-int-root" |
| 160 | + $managementGroups = Get-AzManagementGroup |
| 161 | + $intRootMg = $$managementGroups | Where-Object { $$.Name -eq $$intRootMgId } |
| 162 | +
|
| 163 | + $firstDeployment = $$true |
| 164 | +
|
| 165 | + if($$intRootMg -eq $$null) { |
| 166 | + Write-Warning "Cannot find the $$intRootMgId Management Group, so assuming this is the first deployment." |
| 167 | + } else { |
| 168 | + Write-Host "Found the $$intRootMgId Management Group, so assuming this is not the first deployment." |
| 169 | + $$firstDeployment = $$false |
| 170 | + } |
| 171 | +
|
| 172 | + Write-Host "##vso[task.setvariable variable=FIRST_DEPLOYMENT;]$$firstDeployment" |
| 173 | +
|
| 174 | + - template: ./helpers/bicep-avm-installer.yaml |
| 175 | + parameters: |
| 176 | + serviceConnection: '${service_connection_name_apply}' |
| 177 | + |
| 178 | +%{ for script_file in script_files ~} |
| 179 | +%{ if try(script_file.networkType, "") != "" ~} |
| 180 | + - $${{ if and(eq(parameters['${script_file.name}'], true), eq(variables['NETWORK_TYPE'], '${script_file.networkType}')) }}: |
| 181 | + - template: ./helpers/bicep-avm-deploy.yaml |
| 182 | + parameters: |
| 183 | + displayName: '${script_file.displayName} (Network Type: ${script_file.networkType})' |
| 184 | + serviceConnection: '${service_connection_name_apply}' |
| 185 | + templateFilePath: '${script_file.templateFilePath}' |
| 186 | + templateParametersFilePath: '${script_file.templateParametersFilePath}' |
| 187 | + managementGroupId: '${script_file.managementGroupIdVariable}' |
| 188 | + subscriptionId: '${script_file.subscriptionIdVariable}' |
| 189 | + resourceGroupName: '${script_file.resourceGroupNameVariable}' |
| 190 | + location: '$(LOCATION)' |
| 191 | + deploymentType: '${script_file.deploymentType}' |
| 192 | + firstRunWhatIf: ${script_file.firstRunWhatIf} |
| 193 | + networkType: '${script_file.networkType}' |
| 194 | + whatIfEnabled: false |
| 195 | + |
| 196 | +%{ else ~} |
| 197 | + - $${{ if eq(parameters['${script_file.name}'], true) }}: |
| 198 | + - template: ./helpers/bicep-avm-deploy.yaml |
| 199 | + parameters: |
| 200 | + displayName: '${script_file.displayName}' |
| 201 | + serviceConnection: '${service_connection_name_apply}' |
| 202 | + templateFilePath: '${script_file.templateFilePath}' |
| 203 | + templateParametersFilePath: '${script_file.templateParametersFilePath}' |
| 204 | + managementGroupId: '${script_file.managementGroupIdVariable}' |
| 205 | + subscriptionId: '${script_file.subscriptionIdVariable}' |
| 206 | + resourceGroupName: '${script_file.resourceGroupNameVariable}' |
| 207 | + location: '$(LOCATION)' |
| 208 | + deploymentType: '${script_file.deploymentType}' |
| 209 | + firstRunWhatIf: ${script_file.firstRunWhatIf} |
| 210 | + whatIfEnabled: false |
| 211 | + |
| 212 | +%{ endif ~} |
| 213 | +%{ endfor ~} |
0 commit comments