Skip to content

Commit b7f6612

Browse files
committed
Add support for firstwhatif deployment to github
1 parent 600fd62 commit b7f6612

4 files changed

Lines changed: 35 additions & 1 deletion

File tree

alz/github/actions/bicep-avm/templates/actions/bicep-avm-deploy/action.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ inputs:
2626
deploymentType:
2727
description: 'The deployment type (managementGroup, subscription, resourceGroup)'
2828
required: true
29+
firstRunWhatIf:
30+
description: 'Run a what-if on the first run'
31+
required: false
32+
default: 'false'
2933
networkType:
3034
description: 'The network type filter'
3135
required: false
@@ -46,6 +50,22 @@ runs:
4650
$deploymentType = $env:DEPLOYMENT_TYPE
4751
$whatIfEnabled = $env:WHAT_IF_ENABLED -eq 'true'
4852
53+
# Check if we should skip what-if for first deployment
54+
$firstDeploymentString = $env:firstDeployment
55+
$firstDeployment = $true
56+
if($firstDeploymentString -eq "") {
57+
$firstDeployment = $false
58+
} else {
59+
$firstDeployment = [System.Convert]::ToBoolean($firstDeploymentString)
60+
}
61+
62+
$firstRunWhatIf = [System.Convert]::ToBoolean($env:FIRST_RUN_WHAT_IF)
63+
64+
if($whatIfEnabled -and $firstDeployment -and !$firstRunWhatIf) {
65+
Write-Warning "Skipping the What-If check as the deployment is dependent on resources that do not exist yet..."
66+
exit 0
67+
}
68+
4969
# Generate deployment name with timestamp (matching classic bicep pattern)
5070
$deploymentPrefix = "alz"
5171
$deploymentNameBase = $env:DISPLAY_NAME.Replace(" ", "-")
@@ -255,4 +275,5 @@ runs:
255275
RESOURCE_GROUP_NAME: $${{ inputs.resourceGroupName }}
256276
LOCATION: $${{ inputs.location }}
257277
DEPLOYMENT_TYPE: $${{ inputs.deploymentType }}
278+
FIRST_RUN_WHAT_IF: $${{ inputs.firstRunWhatIf }}
258279
WHAT_IF_ENABLED: $${{ inputs.whatIfEnabled }}

alz/github/actions/bicep-avm/templates/workflows/cd-template.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ jobs:
5151
subscription-id: $${{ vars.AZURE_SUBSCRIPTION_ID }}
5252
enable-AzPSSession: true
5353

54+
- name: Check for First Deployment
55+
uses: ${organization_name}/${repository_name_templates}/.github/actions/bicep-avm-first-deployment-check@main
56+
with:
57+
managementGroupId: $${{ env.MANAGEMENT_GROUP_ID }}
58+
5459
%{ for script_file in script_files ~}
5560
%{ if try(script_file.networkType, "") != "" ~}
5661
- name: 'Plan: ${script_file.displayName} (Network Type: ${script_file.networkType})'
@@ -65,6 +70,7 @@ jobs:
6570
resourceGroupName: '${script_file.resourceGroupNameVariable}'
6671
location: '$${{ env.LOCATION }}'
6772
deploymentType: '${script_file.deploymentType}'
73+
firstRunWhatIf: '${script_file.firstRunWhatIf}'
6874
networkType: '${script_file.networkType}'
6975
whatIfEnabled: 'true'
7076
%{ else ~}
@@ -80,6 +86,7 @@ jobs:
8086
resourceGroupName: '${script_file.resourceGroupNameVariable}'
8187
location: '$${{ env.LOCATION }}'
8288
deploymentType: '${script_file.deploymentType}'
89+
firstRunWhatIf: '${script_file.firstRunWhatIf}'
8390
whatIfEnabled: 'true'
8491
%{ endif ~}
8592
%{ endfor ~}

alz/github/actions/bicep-avm/templates/workflows/ci-template.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ jobs:
7171
tenant-id: $${{ vars.AZURE_TENANT_ID }}
7272
subscription-id: $${{ vars.AZURE_SUBSCRIPTION_ID }}
7373
enable-AzPSSession: true
74+
75+
- name: Check for First Deployment
76+
uses: ${organization_name}/${repository_name_templates}/.github/actions/bicep-avm-first-deployment-check@main
77+
with:
78+
managementGroupId: $${{ env.MANAGEMENT_GROUP_ID }}
7479
%{ for script_file in script_files ~}
7580

7681
- name: 'What If: ${script_file.displayName}'
@@ -84,5 +89,6 @@ jobs:
8489
resourceGroupName: '${script_file.resourceGroupNameVariable}'
8590
location: '$${{ env.LOCATION }}'
8691
deploymentType: '${script_file.deploymentType}'
92+
firstRunWhatIf: '${script_file.firstRunWhatIf}'
8793
whatIfEnabled: 'true'
8894
%{ endfor ~}

alz/github/locals.files.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ locals {
3737
subscriptionIdVariable = try("$${{ env.${script_file.subscriptionId} }}", "")
3838
resourceGroupNameVariable = try("$${{ env.${script_file.resourceGroupName} }}", "")
3939
deploymentType = script_file.deploymentType
40-
firstRunWhatIf = local.is_classic_bicep ? script_file.firstRunWhatIf : null
40+
firstRunWhatIf = script_file.firstRunWhatIf
4141
group = script_file.group
4242
networkType = try(script_file.networkType, "")
4343
} if try(script_file.networkType, "") == "" || try(script_file.networkType, "") == local.networking_type } : {}

0 commit comments

Comments
 (0)