Skip to content

Instantly share code, notes, and snippets.

@mirontoli
Last active October 20, 2025 16:56
Show Gist options
  • Save mirontoli/c1ea2cd4e81335113818edef247113d8 to your computer and use it in GitHub Desktop.
Save mirontoli/c1ea2cd4e81335113818edef247113d8 to your computer and use it in GitHub Desktop.
# execute in bash
stacks=$(az stack sub list --query "[?starts_with(name, 'stack-iac-demo')].name" -o tsv)
for name in $stacks; do az stack sub delete --name "$name" --action-on-unmanage deleteAll --yes; done
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
trigger:
- main
variables:
azureSubscription: "demo-azure-connection"
pool:
vmImage: ubuntu-latest
steps:
- task: AzureCLI@2
displayName: "Deploy Infrastructure"
inputs:
azureSubscription: "$(azureSubscription)"
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
az stack sub create \
--template-file ./infra/main.bicep \
--name stack-iac-demo \
--location westeurope \
--action-on-unmanage deleteResources \
--deny-settings-mode None
targetScope = 'subscription'
param appName string = 'iac-demo'
param location string = 'westeurope'
var resourceGroupName = 'rg-${appName}'
resource newRG 'Microsoft.Resources/resourceGroups@2024-11-01' = {
name: resourceGroupName
location: location
}
trigger:
- main
variables:
azureSubscription: "demo-azure-connection"
pool:
vmImage: ubuntu-latest
# THIS IS NEW for STEP 3: stages
stages:
- stage: DeployDEV
displayName: "Deploy to DEV"
jobs:
- deployment: DeployInfraDEV
displayName: "Deploy Infrastructure to DEV"
environment: "DEV" # The name is important
strategy:
runOnce:
deploy:
# END OF NEW for STEP 3: stages
steps:
# THIS IS NEW for STEP 3: source code
- checkout: self
displayName: "Checkout source code"
# END OF NEW for STEP 3: source code
- task: AzureCLI@2
displayName: "Deploy Infrastructure"
inputs:
azureSubscription: "$(azureSubscription)"
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
az stack sub create \
--template-file ./infra/main.bicep \
--name stack-iac-demo \
--location westeurope \
--action-on-unmanage deleteResources \
--deny-settings-mode None
trigger:
- main
variables:
azureSubscription: "demo-azure-connection"
pool:
vmImage: ubuntu-latest
stages:
- stage: DeployDEV
displayName: "Deploy to DEV"
jobs:
- template: pipelines/templates/deploy.yml
parameters:
environment: "DEV"
azureSubscription: "$(azureSubscription)"
stackName: "stack-iac-demo-dev"
parameters:
- name: environment
type: string
- name: azureSubscription
type: string
- name: stackName
type: string
- name: location
type: string
default: "westeurope"
jobs:
- deployment: DeployInfra${{ parameters.environment }}
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
environment: "${{ parameters.environment }}"
strategy:
runOnce:
deploy:
steps:
- checkout: self
displayName: "Checkout source code"
- task: AzureCLI@2
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
inputs:
azureSubscription: "${{ parameters.azureSubscription }}"
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
az stack sub create \
--template-file ./infra/main.bicep \
--name ${{ parameters.stackName }} \
--location ${{ parameters.location }} \
--action-on-unmanage deleteResources \
--deny-settings-mode None
using '../main.bicep'
param environment = 'DEV'
param appName = 'iac-demo'
param location = 'westeurope'
param resourceGroupName = 'rg-${appName}-${environment}'
targetScope = 'subscription'
// THIS IS NEW for step 5
@description('Environment name (e.g., DEV, TEST, PROD)')
@allowed(['DEV', 'TEST', 'PROD'])
param environment string = 'DEV'
// END OF NEW for step 5
param appName string = 'iac-demo'
param location string = 'westeurope'
// REPLACE THIS LINE WITH THE NEXT ONE, STEP 5
// var resourceGroupName = 'rg-${appName}'
param resourceGroupName string = 'rg-${appName}-${environment}'
resource newRG 'Microsoft.Resources/resourceGroups@2024-11-01' = {
name: resourceGroupName
location: location
}
parameters:
- name: environment
type: string
- name: azureSubscription
type: string
- name: stackName
type: string
- name: location
type: string
default: "westeurope"
jobs:
- deployment: DeployInfra${{ parameters.environment }}
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
environment: "${{ parameters.environment }}"
strategy:
runOnce:
deploy:
steps:
- checkout: self
displayName: "Checkout source code"
- task: AzureCLI@2
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
inputs:
azureSubscription: "${{ parameters.azureSubscription }}"
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
az stack sub create \
--template-file ./infra/main.bicep \
# THIS IS NEW for step 5: parameters
--parameters ./infra/parameters/${{ parameters.environment }}.bicepparam \
# END OF NEW for step 5: parameters
--name ${{ parameters.stackName }} \
--location ${{ parameters.location }} \
--action-on-unmanage deleteResources \
--deny-settings-mode None
trigger:
- main
variables:
azureSubscription: 'demo-azure-connnection'
pool:
vmImage: ubuntu-latest
stages:
- stage: DeployDEV
displayName: 'Deploy to DEV'
jobs:
- template: pipelines/templates/deploy.yml
parameters:
environment: 'DEV'
azureSubscription: '$(azureSubscription)'
stackName: 'stack-iac-demo-dev'
- stage: DeployTEST
displayName: 'Deploy to TEST'
jobs:
- template: pipelines/templates/deploy.yml
parameters:
environment: 'TEST'
azureSubscription: '$(azureSubscription)'
stackName: 'stack-iac-demo-test'
- stage: DeployPROD
displayName: 'Deploy to PROD'
jobs:
- template: pipelines/templates/deploy.yml
parameters:
environment: 'PROD'
azureSubscription: '$(azureSubscription)'
stackName: 'stack-iac-demo-prod'
using '../main.bicep'
param environment = 'PROD'
param appName = 'iac-demo'
param location = 'westeurope'
param resourceGroupName = 'rg-${appName}-${environment}'
using '../main.bicep'
param environment = 'TEST'
param appName = 'iac-demo'
param location = 'westeurope'
param resourceGroupName = 'rg-${appName}-${environment}'
@description('The name of the Static Web App')
param staticWebAppName string
@description('The location for the Static Web App')
param location string
@description('Environment name for tagging')
param environment string
@description('The SKU for the Static Web App')
@allowed(['Free', 'Standard'])
param sku string = 'Free'
resource staticWebApp 'Microsoft.Web/staticSites@2024-11-01' = {
name: staticWebAppName
location: location
tags: {
Environment: environment
}
sku: {
name: sku
tier: sku
}
properties: {}
}
targetScope = 'subscription'
@description('Environment name (e.g., DEV, TEST, PROD)')
@allowed(['DEV', 'TEST', 'PROD'])
param environment string = 'DEV'
param appName string = 'iac-demo'
param location string = 'westeurope'
param resourceGroupName string = 'rg-${appName}-${environment}'
resource newRG 'Microsoft.Resources/resourceGroups@2024-11-01' = {
name: resourceGroupName
location: location
}
//NEW FOR STEP 7
module staticWebAppModule 'modules/static-web-app.bicep' = {
name: 'staticWebAppDeployment'
scope: newRG
params: {
staticWebAppName: 'swa-iac-demo-${environment}'
location: location
environment: environment
sku: 'Free'
}
}
//END OF NEW FOR STEP 7
parameters:
- name: environment
type: string
- name: azureSubscription
type: string
- name: stackName
type: string
- name: location
type: string
default: "westeurope"
jobs:
- deployment: DeployInfra${{ parameters.environment }}
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
environment: "${{ parameters.environment }}"
strategy:
runOnce:
deploy:
steps:
- checkout: self
displayName: "Checkout source code"
- task: AzureCLI@2
displayName: "Deploy Infrastructure to ${{ parameters.environment }}"
inputs:
azureSubscription: "${{ parameters.azureSubscription }}"
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
az stack sub create \
--template-file ./infra/main.bicep \
--parameters ./infra/parameters/${{ parameters.environment }}.bicepparam \
--name ${{ parameters.stackName }} \
--location ${{ parameters.location }} \
--action-on-unmanage deleteResources \
--deny-settings-mode None
// NEW FOR STEP 8
- task: UseNode@1
inputs:
version: '22.x'
- task: Npm@1
displayName: 'Install SWA CLI'
inputs:
command: 'custom'
customCommand: 'install -g @azure/static-web-apps-cli'
- task: AzureCLI@2
displayName: 'Deploy Static Web App ${{ parameters.environment }}'
inputs:
azureSubscription: '$(azureSubscription)'
scriptType: bash
scriptLocation: inlineScript
useGlobalConfig: false
inlineScript: |
export SWA_CLI_DEPLOYMENT_TOKEN=$(az staticwebapp secrets list --name swa-iac-demo-${{ parameters.environment }} --query "properties.apiKey" -o tsv)
swa deploy ./src --env Production
// END OF NEW FOR STEP 8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment