从资源组定义的标签命名tag1
(这样做是通过门户网站),我在Visual Studio中的下列部署模板:获取从资源组标签在Azure的资源管理器模板
{
"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')]"
}
}
我得到这个错误:
... 'The language expression property 'tags' doesn't exist, available properties are '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。
我通过门户创建了标签,并在运行部署之前验证标签是否存在。但是,如果标签不存在同样的错误,那么你是对的。有趣的发现:出于某种原因,当我部署时,标签**被清除。你如何设置你的标签?通过门户或PowerShell或REST? – edteke
我通过门户设置 – juvchan
我也是,有趣的发现:我看到你也从门户运行部署模板,我从Visual Studio运行它。它从门户网站运行,不适用于Visual Studio。看起来Visual Studio在部署导致问题时会清除资源组标记。这是一个不同的问题 – edteke