1

似乎 azure 处理嵌套的模板依赖项,如果找不到资源则失败。

例如,我有 3 个嵌套模板:

  • 模板 #1:创建 VNet 和 Private-DNS-Zone。
  • 模板 #2:创建 Nic(可能带有 vm)
  • 模板 #3:为 DNS 区域中的 Nic 添加 A-Record。

模板 Json:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "resources": [
        {
            "apiVersion": "2017-05-10",
            "name": "VnetTemplate",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "resources": [
                       {
                         "properties":{
                            "subnets":[
                               {
                                  "properties":{
                                     "addressPrefix":"10.0.0.0/24"
                                  },
                                  "name":"default"
                               }
                            ],
                            "addressSpace":{
                               "addressPrefixes":[
                                  "10.0.0.0/24"
                               ]
                            }
                         },
                         "type":"Microsoft.Network/virtualNetworks",
                         "location":"[resourceGroup().location]",
                         "name":"my_vnet",
                         "apiVersion":"2017-10-01"
                      },
                     {
                         "properties":{
                            "resolutionVirtualNetworks":[
                               {
                                  "id":"[resourceId('Microsoft.Network/virtualNetworks/','my_vnet')]"
                               }
                            ],
                            "zoneType":"Private"
                         },
                         "type":"Microsoft.Network/dnsZones",
                         "location":"global",
                         "dependsOn":["my_vnet"],
                         "name":"my.dns",
                         "apiVersion":"2017-10-01"
                      }
                    ]
                }
            }
        },
        {
            "apiVersion": "2017-05-10",
            "name": "NicTemplate",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "resources": [
                        {
                            "properties":{
                                "ipConfigurations":[
                                   {
                                      "properties":{
                                         "privateIPAllocationMethod":"Dynamic",
                                         "subnet":{
                                            "id":"[resourceId('Microsoft.Network/virtualNetworks/subnets', 'my_vnet', 'default')]"
                                         }
                                      },
                                      "name":"app_vnic_IPConf"
                                   }
                                ]
                             },
                             "type":"Microsoft.Network/networkInterfaces",
                             "location":"[resourceGroup().location]",
                             "name":"app_vnic",
                             "apiVersion":"2017-10-01"
                        }
                    ]
                }
            },
            "dependsOn":[
                "VnetTemplate"
            ]
        },
        {
            "apiVersion": "2017-05-10",
            "name": "DnsRecordTemplate",
            "type": "Microsoft.Resources/deployments",
            "properties": {
                "mode": "Incremental",
                "template": {
                    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                    "contentVersion": "1.0.0.0",
                    "resources": [
                        {
                         "properties":{
                            "TTL":3600,
                            "ARecords":[
                               {
                                  "ipv4Address":"[reference(resourceId('Microsoft.Network/networkInterfaces/','app_vnic'), '2017-10-01').ipConfigurations[0].properties.privateIPAddress]"
                               }
                            ]
                         },
                         "type":"Microsoft.Network/dnsZones/A",
                         "name":"my.dns/my_app",
                         "apiVersion":"2017-10-01"
                      }
                    ]
                }
            },
            "dependsOn": [
                "NicTemplate"
            ]
        }
    ]
}

我希望在前两个完成之前不会处理最后一个嵌套模板,但事实并非如此。

屏幕截图 2

屏幕截图 1

(这个例子简化了我在多个资源组上部署的更大模板的问题)

知道如何处理吗?

4

1 回答 1

1

这是不正确的,如果您再部署一次模板,它将起作用,并且部署将相互等待。因此,模板中的 dependsOn 属性没有任何问题。但是,如果您查看该错误,您会注意到该错误是关于app_vnic未找到 NIC。此错误来自引用函数,而不是来自嵌套的 INLINE 模板(根据依赖项)。

要解决此问题,您需要将带有引用函数的模板转换为常规嵌套模板(不是内联模板)。将其上传到某个可公开访问的地方并像这样引用它:

{
    "name": "NestedDeployment1",
    "type": "Microsoft.Resources/deployments",
    "apiVersion": "2015-01-01",
    "dependsOn": [
      "NicTemplate"
    ],
    "properties": {
        "mode": "Incremental",
        "templateLink": {
            "uri": "url_goes_here",
            "contentVersion": "1.0.0.0"
        }
    }
}

这样它就可以工作了。

我不得不承认这是一个错误,但公平地说,嵌套的 INLINE 模板充满了奇怪的行为,我建议不要使用它们(除非你知道你在做什么)。

于 2018-11-11T14:48:12.567 回答