【发布时间】:2017-05-05 22:12:03
【问题描述】:
从一个定义了名为 tag1 的标记的资源组(通过门户完成),我在 Visual Studio 中有以下部署模板:
{
"name": "appsettings",
"type": "config",
"apiVersion": "2015-08-01",
"dependsOn": [
"[resourceId('Microsoft.Web/sites', variables('websiteName'))]"
],
"tags": {
"displayName": "website AppSettings"
},
"properties": {
"Setting1": "[resourceGroup().tags.tag1]",
"Setting2": "[parameters('param2')]"
}
}
我得到这个错误:
...'语言表达式属性'tags'不存在,可用属性是'id, name, location, properties'...
但是使用https://resources.azure.com 我可以看到资源组确实具有tag 属性:
{
"id": "/subscriptions/{someguid}/resourceGroups/resourceGroup1",
"name": "resourceGroup1",
"location": "brazilsouth",
"tags": {
"tag1": "test"
},
"properties": {
"provisioningState": "Succeeded"
}
}
有没有办法获取部署模板中的资源组标签?
更新
正如@juvchan 指出的那样,标签必须存在,否则会发生此错误。我创建了标签,但是从 VisualStudio 部署模板时,标签被删除,从门户网站部署时,标签被保留。这会导致不同的问题和问题。
原因是 Visual Studio 项目有一个带有这一行的 PowerShell 脚本:
#Create or update the resource group using the specified template file and template parameters file
New-AzureRmResourceGroup -Name $ResourceGroupName -Location $ResourceGroupLocation -Verbose -Force -ErrorAction Stop
但New-AzureRmResourceGroup cmdlet 不保留现有标签。意识到。解决方案:如果资源组已存在,则修改脚本不运行 cmdlet。
【问题讨论】:
标签: azure azure-resource-manager arm-template azure-resource-group