77 workflow_dispatch :
88 inputs :
99 azure_location :
10- description : ' Azure region for deployment'
10+ description : " Azure region for deployment"
1111 required : true
1212 type : choice
13- default : ' canadacentral'
13+ default : " canadacentral"
1414 options :
1515 - canadacentral
1616 - canadaeast
2121 - westeurope
2222 - northeurope
2323 instance_number :
24- description : ' Instance number for resource naming'
24+ description : " Instance number for resource naming"
2525 required : true
2626 type : string
27- default : ' 002 '
27+ default : " 003 "
2828
2929permissions :
3030 attestations : write
@@ -34,22 +34,24 @@ permissions:
3434 security-events : write
3535
3636env :
37- INSTANCE_NUMBER : ${{ github.event.inputs.instance_number || '002' }}
38- AZURE_LOCATION : ${{ github.event.inputs.azure_location || 'canadacentral' }}
39- AZURE_WEBAPP_NAME : app-gh-aspnet-webapp-${{ github.event.inputs.instance_number || '002' }}
37+ DEFAULT_INSTANCE_NUMBER : " 003"
38+ DEFAULT_AZURE_LOCATION : " canadacentral"
4039 SRC_PROJECT_PATH : " /webapp01/webapp01.csproj"
4140 AZURE_WEBAPP_PACKAGE_PATH : " ./src"
4241 DOTNET_VERSION : " 9.0.x"
43- AZURE_ACR_NAME : crdevsecopscldev${{ github.event.inputs.instance_number || '002' }}
4442
4543jobs :
4644 deploy-infrastructure :
4745 name : Deploy Azure Infrastructure
4846 runs-on : ubuntu-latest
47+ env :
48+ INSTANCE_NUMBER : ${{ github.event.inputs.instance_number || 'DEFAULT_INSTANCE' }}
49+ AZURE_LOCATION : ${{ github.event.inputs.azure_location || 'DEFAULT_LOCATION' }}
4950 outputs :
5051 acr_name : ${{ steps.deploy.outputs.acr_name }}
5152 webapp_name : ${{ steps.deploy.outputs.webapp_name }}
5253 webapp_url : ${{ steps.deploy.outputs.webapp_url }}
54+ resource_group : ${{ steps.deploy.outputs.resource_group }}
5355 steps :
5456 - uses : actions/checkout@v5
5557
@@ -64,19 +66,19 @@ jobs:
6466 id : deploy
6567 shell : pwsh
6668 run : |
67- $instanceNumber = "${{ env.INSTANCE_NUMBER }}"
68- $location = "${{ env.AZURE_LOCATION }}"
69-
69+ $instanceNumber = "${{ env.INSTANCE_NUMBER }}".Replace('DEFAULT_INSTANCE', '${{ env.DEFAULT_INSTANCE_NUMBER }}')
70+ $location = "${{ env.AZURE_LOCATION }}".Replace('DEFAULT_LOCATION', '${{ env.DEFAULT_AZURE_LOCATION }}')
71+
7072 # Calculate resource names based on instance number
7173 $acrName = "crdevsecopscldev$instanceNumber"
7274 $appServicePlanName = "asp-gh-aspnet-webapp-$instanceNumber"
7375 $webAppName = "app-gh-aspnet-webapp-$instanceNumber"
7476 $resourceGroupName = "rg-gh-aspnet-webapp-$instanceNumber"
7577 $containerImage = "$acrName.azurecr.io/webapp01:latest"
76-
78+
7779 # Deployment name based only on instance number for idempotence
7880 $deploymentName = "deploy-infra-$instanceNumber"
79-
81+
8082 Write-Host "=== Azure Infrastructure Deployment ===" -ForegroundColor Cyan
8183 Write-Host "Instance Number: $instanceNumber" -ForegroundColor Green
8284 Write-Host "Location: $location" -ForegroundColor Green
@@ -85,43 +87,44 @@ jobs:
8587 Write-Host "Web App Name: $webAppName" -ForegroundColor Green
8688 Write-Host "Resource Group: $resourceGroupName" -ForegroundColor Green
8789 Write-Host "Deployment Name: $deploymentName" -ForegroundColor Green
88-
90+
8991 # Deploy using inline parameters instead of parameters file
9092 az deployment sub create `
9193 --name $deploymentName `
9294 --location $location `
93- --template-file ./infra /main.bicep `
95+ --template-file ./blueprints/gh-aspnet-webapp/bicep /main.bicep `
9496 --parameters acrName=$acrName `
9597 --parameters acrSku=Basic `
9698 --parameters appServicePlanName=$appServicePlanName `
9799 --parameters webAppName=$webAppName `
98100 --parameters location=$location `
99101 --parameters containerImage=$containerImage `
100102 --parameters resourceGroupName=$resourceGroupName
101-
103+
102104 if ($LASTEXITCODE -ne 0) {
103105 Write-Error "Deployment failed with exit code: $LASTEXITCODE"
104106 exit $LASTEXITCODE
105107 }
106-
108+
107109 Write-Host "Deployment completed successfully!" -ForegroundColor Green
108-
110+
109111 # Set outputs for subsequent jobs
110112 echo "acr_name=$acrName" >> $env:GITHUB_OUTPUT
111113 echo "webapp_name=$webAppName" >> $env:GITHUB_OUTPUT
112114 echo "webapp_url=https://$webAppName.azurewebsites.net" >> $env:GITHUB_OUTPUT
115+ echo "resource_group=$resourceGroupName" >> $env:GITHUB_OUTPUT
113116
114117 - name : Configure ACR Managed Identity
115118 shell : pwsh
116119 run : |
117120 $webAppName = "${{ steps.deploy.outputs.webapp_name }}"
118- $resourceGroupName = "rg-gh-aspnet-webapp- ${{ env.INSTANCE_NUMBER }}"
119-
121+ $resourceGroupName = "${{ steps.deploy.outputs.resource_group }}"
122+
120123 Write-Host "Configuring ACR managed identity authentication..." -ForegroundColor Yellow
121-
124+
122125 # Verify ACR managed identity configuration
123126 $config = az webapp config show --name $webAppName --resource-group $resourceGroupName --query "acrUseManagedIdentityCreds" -o tsv
124-
127+
125128 if ($config -ne "true") {
126129 Write-Host "Setting acrUseManagedIdentityCreds=true..." -ForegroundColor Cyan
127130 az webapp config set --name $webAppName --resource-group $resourceGroupName --generic-configurations '{"acrUseManagedIdentityCreds": true}'
@@ -136,6 +139,9 @@ jobs:
136139 name : Build and Deploy to Azure Web App
137140 needs : deploy-infrastructure
138141 runs-on : ubuntu-latest
142+ env :
143+ AZURE_ACR_NAME : ${{ needs.deploy-infrastructure.outputs.acr_name }}
144+ AZURE_WEBAPP_NAME : ${{ needs.deploy-infrastructure.outputs.webapp_name }}
139145 steps :
140146 # Checkout the repo
141147 - uses : actions/checkout@v5
0 commit comments