azure - ARM 模板:嵌套模板中的输出问题
问题描述
我目前面临嵌套模板的问题。当我应用我的模板时(详情如下),我从 Azure 得到这个答案:
Azure Error: InvalidTemplate
Message: Deployment template validation failed: 'The template reference 'sandbox.test.portal' is not valid: could not find template resource or resource copy with this name. Please see https://aka.ms/arm-template-expressions/#reference for usage details.'.
但是,我真的不明白为什么会出现这个问题,因为对于嵌套模板中的内容,我使用了它们在此处的文档中提供的内容:https ://github.com/Azure/azure-quickstart-templates/blob /master/101-azure-dns-new-zone/azuredeploy.json
我的 ARM 模板:
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Location for all resources."
}
},
"newZoneName": {
"type": "string",
"defaultValue": "sandbox.test.portal",
"metadata": {
"description": "The name of the DNS zone to be created. Must have at least 2 segements, e.g. hostname.org"
}
},
"newRecordName": {
"type": "string",
"defaultValue": "www",
"metadata": {
"description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN."
}
}
},
"variables": {
"publicIPAddressName": "[concat(resourceGroup().name, '-pip')]",
},
"resources": [
{
"apiVersion": "2015-06-15",
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIPAddressName')]",
"location": "[parameters('location')]",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[parameters('dnsLabelPrefix')]"
}
}
},
{
"apiVersion": "2017-05-10",
"name": "nestedTemplate",
"type": "Microsoft.Resources/deployments",
"resourceGroup": "my-rg",
"subscriptionId": "[subscription().subscriptionId]",
"properties": {
"mode": "Incremental",
"template": {
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
},
"variables": {
},
"resources": [
{
"type": "Microsoft.Network/dnszones",
"name": "[parameters('newZoneName')]",
"apiVersion": "2016-04-01",
"location": "global",
"properties": {
}
},
{
"type": "Microsoft.Network/dnszones/a",
"name": "[concat(parameters('newZoneName'), '/', parameters('newRecordName'))]",
"apiVersion": "2016-04-01",
"location": "global",
"dependsOn": [
"[parameters('newZoneName')]"
],
"properties": {
"TTL": 3600,
"ARecords": [
{
"ipv4Address": "1.2.3.4"
},
{
"ipv4Address": "1.2.3.5"
}
]
}
}
],
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(parameters('newZoneName')).nameServers]"
}
}
}
}
}
]
}
解决方案
基本上,您需要从嵌套的内联模板中删除输出,因此请删除此位:
"outputs": {
"nameServers": {
"type": "array",
"value": "[reference(parameters('newZoneName')).nameServers]"
}
}
长话短说,嵌套的内联部署很糟糕。不要使用它们。
或者将它们移动到父模板并进行真正的查找:
reference(resourceId('Microsoft.Network/dnszones', parameters('newZoneName')))
推荐阅读
- javascript - 从设计器视图调用文本的函数和存储值完成
- assembly - 为什么6502微控制器没有算术右移?
- ruby-on-rails - Rails 5 - 2 个具有相同名称的类及其调用错误的类
- amazon-web-services - 如何从cloudwatch查看日志流属于哪个ECS服务或任务?
- python - 无法为 Zipline 安装 Python 3.5 文件
- python - 来自excel报告的Python dict
- angular - Angular 的文档管理系统
- html - 在NodeJS中获取玉选择框值
- git - 如何为 VSTS 添加 GIT 子模块以用于 Visual Studio 2017
- php - 如何修复我的脚本:更新用户通行证(php mysql)(没有错误但有些东西不起作用)