![](/img/trans.png)
[英]Azure ARM Template - accessing a resource Id created by one ARM template in another ARM template
[英]Passing the output from one arm deployment resource linked template to another
我正在使用一系列json ARM模板來部署Azure VM,並且在將信息從一個資源部署傳遞到另一個資源時遇到了問題。
我使用Blob存儲中的鏈接模板部署了兩種資源,一種資源本身不部署任何東西,但是返回一個填充了配置設置的對象,另一種然后將配置設置的輸出作為參數傳遞給另一個模板:
"resources": [
{
"name": "[concat(deployment().name, '-config')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('configurationTemplate')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"subscriptionParameters": { "value": "[variables('subscriptionParameters')]" }
}
}
},
{
"name": "[concat(deployment().name, '-vm')]",
"type": "Microsoft.Resources/deployments",
"apiVersion": "2016-09-01",
"properties": {
"mode": "Incremental",
"templateLink": {
"uri": "[variables('vmTemplate')]",
"contentVersion": "1.0.0.0"
},
"parameters": {
"configuration": { "value": "[reference(concat(deployment().name, '-config').outputs.configuration.value)]" },
"vmName": { "value": "[parameters('vmName')]" },
"vmSize": { "value": "[parameters('vmSize')]" },
"os": { "value": "[parameters('os')]" },
"managedDiskTier": { "value": "[parameters('managedDiskTier')]" },
"dataDisksToProvision": { "value": "[parameters('dataDisksToProvision')]" },
"dataDiskSizeGB": { "value": "[parameters('dataDiskSizeGB')]" },
"domainJoined": { "value": "[parameters('domainJoined')]" },
"localAdminUsername": { "value": "[parameters('localAdminUsername')]" },
"localAdminPassword": { "value": "[parameters('localAdminPassword')]" },
"numberOfNics": { "value": "[parameters('numberOfNics')]" },
"subnetName": { "value": "[parameters('subnetName')]" },
"highlyAvailable": { "value": "[parameters('highlyAvailable')]" },
"availabilitySetName": { "value": "[parameters('availabilitySetName')]" },
"availabilitySetUpdateDomains": { "value": "[parameters('availabilitySetUpdateDomains')]" },
"availabilitySetFaultDomains": { "value": "[parameters('availabilitySetFaultDomains')]" }
}
}
}
],
"outputs": {
"configuration": {
"type": "object",
"value": "[reference(concat(deployment().name, '-config')).outputs.configuration.value]"
}
}
自行部署第一個資源成功,並且正確返回了輸出[reference(concat(deployment().name, '-config')).outputs.configuration.value]
,其中包含所有正確的信息並且格式正確。
如果再將第二個資源添加到混合中,則部署將失敗,並顯示以下錯誤:
08:57:41 - [ERROR] New-AzureRmResourceGroupDeployment : 08:57:41 - Error: Code=InvalidTemplate;
08:57:41 - [ERROR] Message=Deployment template validation failed: 'The template resource
08:57:41 - [ERROR] 'rcss.test.vm-0502-0757-rcss-vm' at line '317' and column '6' is not valid:
08:57:41 - [ERROR] The language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoo
08:57:41 - [ERROR] r.Expression.Expressions.JTokenExpression' can't be evaluated.. Please see
08:57:41 - [ERROR] https://aka.ms/arm-template-expressions for usage details.'.
如果我同時從該參數集和引用模板中都刪除了"configuration"
參數(引用模板中的所有內容均已注釋掉,以確保我們僅測試參數的傳遞),則部署成功,表明問題與參數字符串"[reference(concat(deployment().name, '-config').outputs.configuration.value)]"
的解析有關。
關於在鏈接模板參數集的上下文中是否需要以特定方式引用部署資源中的輸出對象,誰能提供任何見解?
因此,在仔細檢查之后,我發現我使用的語法不正確,但解析器未報告該語法:
"[reference(concat(deployment().name, '-config').outputs.configuration.value)]"
本來應該:
"[reference(concat(deployment().name, '-config')).outputs.configuration.value]"
小學生錯誤。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.