使用Bicep的isPreview参数来限制what-if输出,只显示实际变更的资源。
示例代码如下:
param location string = 'eastus'
param functionAppName string
param appInsightsName string
resource appServicePlan 'Microsoft.Web/serverfarms@2018-02-01' = {
name: format('{0}-plan', functionAppName)
location: location
sku: {
name: 'P1V2'
tier: 'PremiumV2'
}
kind: 'functionapp'
properties: {
reserved: true
}
}
resource appService 'Microsoft.Web/sites@2018-02-01' = {
name: functionAppName
location: location
dependsOn: [
appServicePlan
]
properties: {
serverFarmId: appServicePlan.id
}
}
resource appInsights 'Microsoft.Insights/components@2015-05-01' = if(appInsightsName != '') {
name: appInsightsName
location: location
kind: 'web'
properties: {}
} else {
name: ''
url: ''
}
output appServiceId string = appService.id
output appInsightsId string = appInsights.id
如果这个模板被用于部署新的资源,可以设置isPreview参数为false,以获得详细和准确的what-if输出:
az deployment sub create -n --template-file --parameters functionAppName= appInsightsName= --location eastus --mode Complete --isPreview false
如果该模板被用于更新现有资源,则应该将isPreview参数设置为true,以排除不必要的噪音:
az deployment sub create -n --template-file --parameters functionAppName= appInsightsName= --location eastus --mode Incremental --isPreview true