ARM 模板 resourceid() 函数失败
ARM Template resourceid() function Fails
请帮助我了解我的 Azure ARM 模板有什么问题,这是非常基本的,需要一些输入参数并打印出 resourceId。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetworkName": {
"type": "string"
},
"virtualNetworkResourceGroupName": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"location": {
"type": "string",
"metadata": {
"description": "Location to Deploy Azure Resources"
}
}
},
"resources": [],
"outputs": {
"subnetRef": {
"type": "string",
"value": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
}
}
}
提供所需参数时失败并显示以下错误消息。
参数文件
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetworkName": {
"value": "core-services-vnet"
},
"virtualNetworkResourceGroupName": {
"value": "core-networking-rg"
},
"subnetName": {
"value": "private"
},
"location": {
"value": "westus"
}
}
}
$ az deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus
Deployment failed. Correlation ID: b97a7544-2814-40c0-88c9-fbaaea2bf645. The template output 'subnetRef' is not valid: The provided value 'core-networking-rg' is not valid subscription identifier. Please see https://aka.ms/arm-template-expressions/#resourceid for usage details.
我在这里错过了什么?
谢谢,老马
问题是deployment scope。可以将部署定位到 Azure 订阅或订阅中的资源组。
在您的模板中,$schema https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
用于资源组部署,而您使用的命令 az deployment create
用于订阅级部署。订阅级部署的架构 https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#
与资源组部署的架构不同。您可以从 creating resource groups and resources at the subscription level.
获得参考
在这种情况下,您可以使用命令 az group deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus
而不是 az deployment create xxx
来解决此问题。
请帮助我了解我的 Azure ARM 模板有什么问题,这是非常基本的,需要一些输入参数并打印出 resourceId。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetworkName": {
"type": "string"
},
"virtualNetworkResourceGroupName": {
"type": "string"
},
"subnetName": {
"type": "string"
},
"location": {
"type": "string",
"metadata": {
"description": "Location to Deploy Azure Resources"
}
}
},
"resources": [],
"outputs": {
"subnetRef": {
"type": "string",
"value": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
}
}
}
提供所需参数时失败并显示以下错误消息。
参数文件
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"virtualNetworkName": {
"value": "core-services-vnet"
},
"virtualNetworkResourceGroupName": {
"value": "core-networking-rg"
},
"subnetName": {
"value": "private"
},
"location": {
"value": "westus"
}
}
}
$ az deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus
Deployment failed. Correlation ID: b97a7544-2814-40c0-88c9-fbaaea2bf645. The template output 'subnetRef' is not valid: The provided value 'core-networking-rg' is not valid subscription identifier. Please see https://aka.ms/arm-template-expressions/#resourceid for usage details.
我在这里错过了什么?
谢谢,老马
问题是deployment scope。可以将部署定位到 Azure 订阅或订阅中的资源组。
在您的模板中,$schema https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#
用于资源组部署,而您使用的命令 az deployment create
用于订阅级部署。订阅级部署的架构 https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#
与资源组部署的架构不同。您可以从 creating resource groups and resources at the subscription level.
在这种情况下,您可以使用命令 az group deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus
而不是 az deployment create xxx
来解决此问题。