这个帖子里的另一个回答至少是误导性的。
实际上,你采取哪种方式来向模板的dependsOn属性(或任何其他属性)提供值都不重要。你甚至可以在那里放一个字符串。
"dependsOn" [
"/subscription/GUID/resourceGroups/rgName/provider/providerName/resource/resourceName"
]
显然,这是个不好的想法,但它阐明了重点。你只需要返回一个有效的资源标识符,可以以任何方式构造它(或者在脚本配置时将其作为变量传递)。
有时候当使用嵌套资源时resourceId无法工作,所以你需要连接3个变量,在这种情况下,concat可以帮助你。
而且,没有什么能阻止你把一个资源嵌套到另一个资源中:
"[concat(resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachineName'), 'SOME TEXT'))]
TLDR,您可以使用任何方法返回有效的资源标识符。
附:一个“损坏”的 resourceId 的示例,通常会正常工作:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2017-05-10",
"name": "nestedTemplate",
"resourceGroup": "xxx",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"type": "Microsoft.Storage/storageAccounts",
"apiVersion": "2017-06-01",
"name": "egw4y35hthrh35h24tz1",
"location": "eastus",
"sku": {
"name": "Standard_LRS"
},
"tags": {
"test": "[resourceId('Microsoft.Storage/storageAccounts', 'test')]"
},
"kind": "Storage",
"properties": {}
}
]
}
}
}
]
}
这必须是订阅级别的部署。
resourceId
引用模板外部的任何资源时,我会收到The resource 'XXXXX' is not defined in the template
的错误提示。 - Cocowalla