Created
April 21, 2021 08:43
-
-
Save justinyoo/e27d3ddc8d868a1c16293f8286b3ff67 to your computer and use it in GitHub Desktop.
Bicep Refreshed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bicep CLI | |
bicep build azuredeploy.bicep | |
# Azure CLI | |
az bicep build --file azuredeploy.bicep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Get-ChildItem -Path **/*.bicep -Recurse | ForEach-Object { | |
az bicep build --file $_.FullName | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ARM template file | |
az deployment group create \ | |
--name <deployment_name> \ | |
--resource-group <resource_group_name> \ | |
--template-file azuredeploy.json \ | |
--parameters @azuredeploy.parameters.json | |
# Bicep file | |
az deployment group create \ | |
--name <deployment_name> \ | |
--resource-group <resource_group_name> \ | |
--template-file azuredeploy.bicep \ | |
--parameters @azuredeploy.parameters.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bicep CLI | |
bicep decompile azuredeploy.json | |
# Azure CLI | |
az bicep decompile --file azuredeploy.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Without decorators | |
param storageAccountSku string { | |
allowd: [ | |
'Standard_GRS' | |
'Standard_LRS' | |
] | |
default: 'Standard_LRS' | |
} | |
// With decorators | |
@allowed([ | |
'Standard_GRS' | |
'Standard_LRS' | |
]) | |
param storageAccountSku string = 'Standard_LRS' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param location = resourceGroup().location | |
resource webapp 'Microsoft.Web/sites@2020-12-01' = if (location == 'koreacentral') { | |
... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param webapps array = [ | |
'dev' | |
'test' | |
'prod' | |
] | |
// Use array only | |
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for name in webapps: { | |
name: 'my-webapp-${name}' | |
... | |
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use both array and index | |
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for (name, index) in webapps: { | |
name: 'my-webapp-${name}-${index + 1}' | |
... | |
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use range | |
resource webapp 'Microsoft.Web/sites@2020-12-01' = [for i in range(0, 10): { | |
name: 'my-webapp-${index + 1}' | |
... | |
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// storageAccount.bicep | |
param resourceName string | |
param location string = resourceGroup().location | |
resource st 'Microsoft.Storage/storageAccounts@2021-02-01' = { | |
name: resourceName | |
location: location | |
... | |
} | |
output id string = st.id | |
output name string = st.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// consumptionPlan.bicep | |
param resourceName string | |
param location string = resourceGroup().location | |
resource csplan 'Microsoft.Web/serverfarms@2020-12-01' = { | |
name: resourceName | |
location: location | |
... | |
} | |
output id string = csplan.id | |
output name string = csplan.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// functionApp.bicep | |
param resourceName string | |
param location string = resourceGroup().location | |
param storageAccountId string | |
param storageAccountName string | |
param consumptionPlanId string | |
resource fncapp 'Microsoft.Web/sites@2020-12-01' = { | |
name: resourceName | |
location: location | |
... | |
properties: { | |
serverFarmId: consumptionPlanId | |
... | |
siteConfig: { | |
appSettings: [ | |
{ | |
name: 'AzureWebJobsStorage' | |
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccountId, '2021-02-01').keys[0].value}' | |
} | |
... | |
] | |
} | |
} | |
} | |
output id string = fncapp.id | |
output name string = fncapp.name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// azuredeploy.bicep | |
param resourceName string | |
param location string = resourceGroup().location | |
module st './storage-account.bicep' = { | |
name: 'StorageAccountProvisioning' | |
params: { | |
name: resourceName | |
location: location | |
} | |
} | |
module csplan './consumption-plan.bicep' = { | |
name: 'ConsumptionPlanProvisioning' | |
params: { | |
name: resourceName | |
location: location | |
} | |
} | |
module fncapp './function-app.bicep' = { | |
name: 'FunctionAppProvisioning' | |
params: { | |
name: resourceName | |
location: location | |
storageAccountId: st.outputs.id | |
storageAccountName: st.outputs.name | |
consumptionPlanId: csplan.outputs.id | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment