Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure ARM模板:嵌套模板中的输出存在问题_Azure_Azure Devops_Arm Template - Fatal编程技术网

Azure ARM模板:嵌套模板中的输出存在问题

Azure ARM模板:嵌套模板中的输出存在问题,azure,azure-devops,arm-template,Azure,Azure Devops,Arm Template,我目前面临嵌套模板的问题。 当我在下面应用我的模板详细信息时,我从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. P

我目前面临嵌套模板的问题。 当我在下面应用我的模板详细信息时,我从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.'.
但是,我不太明白为什么会出现这个问题,因为对于嵌套模板中的内容,我使用了它们在这里的文档中提供的内容:

我的手臂模板:

{
    "$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')))

模板中有几个小错误:

{
    "$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]"
                        }
                    }
                }
            }
        }
    ]
}
变量'-pip']中的逗号, 未定义的参数dnsLabelPrefix 嵌套输出中的一般错误。使用嵌套模板时,azure不会在主模板中找到它。因此,您必须使用具有标识符和API的引用函数:[ReferenceSourceId'Microsoft.Network/dnszones',参数'newZoneName','2016-04-01'。nameServers]

我修改了您的模板并在订阅中验证

    {
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "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."
            }
        },
        "dnsLabelPrefix": {
            "type": "string",
            "defaultValue": "[concat('dns',uniqueString(resourceGroup().name))]"
        },
        "nestedResourceGroup": {
            "type": "string",
            "defaultValue": "my-rg",
            "metadata": {
                "description": "my-rg"
            }
        }
    },
    "variables": {
        "publicIPAddressName": "[concat(resourceGroup().name, '-pip')]"
    },
    "resources": [
        {
            "apiVersion": "2015-06-15",
            "type": "Microsoft.Network/publicIPAddresses",
            "name": "[variables('publicIPAddressName')]",
            "location": "[resourceGroup().location]",
            "properties": {
                "publicIPAllocationMethod": "Dynamic",
                "dnsSettings": {
                    "domainNameLabel": "[parameters('dnsLabelPrefix')]"
                }
            }
        },
        {
            "apiVersion": "2017-05-10",
            "name": "nestedTemplate",
            "type": "Microsoft.Resources/deployments",
            "resourceGroup": "[parameters('nestedResourceGroup')]",
            "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": [
                                "[resourceId('Microsoft.Network/dnszones', parameters('newZoneName'))]"
                            ],
                            "properties": {
                                "TTL": 3600,
                                "ARecords": [
                                    {
                                        "ipv4Address": "1.2.3.4"
                                    },
                                    {
                                        "ipv4Address": "1.2.3.5"
                                    }
                                ]
                            }
                        }
                    ],
                    "outputs": {
                        "nameServers": {
                            "type": "array",
                            "value": "[reference(resourceId('Microsoft.Network/dnszones', parameters('newZoneName')), '2016-04-01').nameServers]"
                        }
                    }
                }
            }
        }
    ]
}

祝你今天愉快

谢谢你的反馈。你能告诉我一些关于嵌套内联部署不好的细节吗?如果我们与另一个资源组中的某个内容有链接,您建议使用什么来代替此链接?链接模板。如果您只需要引用另一个资源组或订阅中的某个内容,您可以直接引用它,而不需要另一个部署