ARM模板错误错误代码invalidTemplate“检测到循环依赖性

时间:2018-03-15 00:34:54

标签: azure-resource-manager

我是部署ARM模板的新手。在创建ARM模板之前,我创建了一个简单的基础架构,包括1个VM,1个VNet和1个存储帐户。完成基础架构配置后,我决定制作一个模板供将来使用。我使用自动化脚本,然后将其保存到库中,然后我也下载了它。所以,我想将模板中的SSD磁盘层从标准D2S_V1更改为E2S_V3。所以我做到了。我保存了更改,然后决定通过部署模板来测试它。在此之后,我收到了一个错误代码,其中包含以下内容:

部署模板验证失败:'在资源上检测到循环依赖关系:'/ subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleRev2/providers/Microsoft.Network/networkInterfaces/simplevm18'。有关使用详情,请参阅https://aka.ms/arm-template/#resources。 (代码:InvalidTemplate)

所以,我试着通过查看这些链接进行自己的研究:

https://social.msdn.microsoft.com/Forums/en-US/c5782362-3a04-47fe-b5ec-87e5f488e844/deployment-failed-with-arm-template?forum=WAVirtualMachinesforWindows

https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-define-dependencies

据我所知,循环依赖性错误意味着dependOn属性可能存在问题。所以我进入模板并查看它们,因为它主要与模板中指定的vnet资源有关。我不确定的是,我是否需要更改vnet,pub ip,nsg和nic的名称?或者是别的什么。在这里,我将在JSON中附加模板:

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "virtualMachines_SimpleVM_name": {
            "defaultValue": "SimpleVM",
            "type": "String"
        },
        "virtualNetworks_SimpleVNet_name": {
            "defaultValue": "SimpleVNet",
            "type": "String"
        },
        "networkInterfaces_simplevm18_name": {
            "defaultValue": "simplevm18",
            "type": "String"
        },
        "publicIPAddresses_SimpleVM_ip_name": {
            "defaultValue": "SimpleVM-ip",
            "type": "String"
        },
        "storageAccounts_simplestorage1_name": {
            "defaultValue": "simplestorage1",
            "type": "String"
        },
        "networkSecurityGroups_SimpleVM_nsg_name": {
            "defaultValue": "SimpleVM-nsg",
            "type": "String"
        },
        "subnets_default_name": {
            "defaultValue": "default",
            "type": "String"
        },
        "securityRules_default_allow_rdp_name": {
            "defaultValue": "default-allow-rdp",
            "type": "String"
        },
        "virtualMachines_SimpleVM_id": {
            "defaultValue": "/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Compute/disks/SimpleVM_OsDisk_1_e66aaeca090f4ff5a3021460b8255a30",
            "type": "String"
        }
    },
    "variables": {},
    "resources": [
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Compute/virtualMachines/SimpleVM'.",
            "type": "Microsoft.Compute/virtualMachines",
            "name": "[parameters('virtualMachines_SimpleVM_name')]",
            "apiVersion": "2017-03-30",
            "location": "centralus",
            "scale": null,
            "properties": {
                "hardwareProfile": {
                    "vmSize": "Standard_E2S_v3"
                },
                "storageProfile": {
                    "imageReference": {
                        "publisher": "MicrosoftWindowsServer",
                        "offer": "WindowsServer",
                        "sku": "2016-Datacenter",
                        "version": "latest"
                    },
                    "osDisk": {
                        "osType": "Windows",
                        "name": "[concat(parameters('virtualMachines_SimpleVM_name'),'_OsDisk_1_e66aaeca090f4ff5a3021460b8255a30')]",
                        "createOption": "FromImage",
                        "caching": "ReadWrite",
                        "managedDisk": {
                            "storageAccountType": "Premium_LRS",
                            "id": "[parameters('virtualMachines_SimpleVM_id')]"
                        },
                        "diskSizeGB": 128
                    },
                    "dataDisks": []
                },
                "osProfile": {
                    "computerName": "[parameters('virtualMachines_SimpleVM_name')]",
                    "adminUsername": "susan",
                    "windowsConfiguration": {
                        "provisionVMAgent": true,
                        "enableAutomaticUpdates": true
                    },
                    "secrets": []
                },
                "networkProfile": {
                    "networkInterfaces": [
                        {
                            "id": "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_simplevm18_name'))]"
                        }
                    ]
                },
                "diagnosticsProfile": {
                    "bootDiagnostics": {
                        "enabled": true,
                        "storageUri": "https://loadbaldiag639.blob.core.windows.net/"
                    }
                }
            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkInterfaces', parameters('networkInterfaces_simplevm18_name'))]"
            ]
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/networkInterfaces/simplevm18'.",
            "type": "Microsoft.Network/networkInterfaces",
            "name": "[parameters('networkInterfaces_simplevm18_name')]",
            "apiVersion": "2017-10-01",
            "location": "centralus",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "resourceGuid": "5cced9eb-2dee-4f5a-9768-7098c140bfba",
                "ipConfigurations": [
                    {
                        "name": "ipconfig1",
                        "etag": "W/\"a2959053-241e-49fc-9ee6-ae6dd8f9a2ac\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "privateIPAddress": "10.5.0.4",
                            "privateIPAllocationMethod": "Dynamic",
                            "publicIPAddress": {
                                "id": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_SimpleVM_ip_name'))]"
                            },
                            "subnet": {
                                "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworks_SimpleVNet_name'), parameters('subnets_default_name'))]"
                            },
                            "primary": true,
                            "privateIPAddressVersion": "IPv4"
                        }
                    }
                ],
                "dnsSettings": {
                    "dnsServers": [],
                    "appliedDnsServers": [],
                    "internalDomainNameSuffix": "4k34gmmtgvzetdldyabe4m2uwh.gx.internal.cloudapp.net"
                },
                "macAddress": "00-0D-3A-94-FA-26",
                "enableAcceleratedNetworking": false,
                "enableIPForwarding": false,
                "networkSecurityGroup": {
                    "id": "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroups_SimpleVM_nsg_name'))]"
                },
                "primary": true,
                "virtualMachine": {
                    "id": "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_SimpleVM_name'))]"
                }
            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_SimpleVM_ip_name'))]",
                "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworks_SimpleVNet_name'), parameters('subnets_default_name'))]",
                "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroups_SimpleVM_nsg_name'))]",
                "[resourceId('Microsoft.Compute/virtualMachines', parameters('virtualMachines_SimpleVM_name'))]"
            ]
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/networkSecurityGroups/SimpleVM-nsg'.",
            "type": "Microsoft.Network/networkSecurityGroups",
            "name": "[parameters('networkSecurityGroups_SimpleVM_nsg_name')]",
            "apiVersion": "2017-10-01",
            "location": "centralus",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "resourceGuid": "0af138ab-8f42-4b94-b440-46525541955e",
                "securityRules": [
                    {
                        "name": "default-allow-rdp",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "protocol": "TCP",
                            "sourcePortRange": "*",
                            "destinationPortRange": "3389",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 1000,
                            "direction": "Inbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    }
                ],
                "defaultSecurityRules": [
                    {
                        "name": "AllowVnetInBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Allow inbound traffic from all VMs in VNET",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "VirtualNetwork",
                            "destinationAddressPrefix": "VirtualNetwork",
                            "access": "Allow",
                            "priority": 65000,
                            "direction": "Inbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    },
                    {
                        "name": "AllowAzureLoadBalancerInBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Allow inbound traffic from azure load balancer",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "AzureLoadBalancer",
                            "destinationAddressPrefix": "*",
                            "access": "Allow",
                            "priority": 65001,
                            "direction": "Inbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    },
                    {
                        "name": "DenyAllInBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Deny all inbound traffic",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Deny",
                            "priority": 65500,
                            "direction": "Inbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    },
                    {
                        "name": "AllowVnetOutBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Allow outbound traffic from all VMs to all VMs in VNET",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "VirtualNetwork",
                            "destinationAddressPrefix": "VirtualNetwork",
                            "access": "Allow",
                            "priority": 65000,
                            "direction": "Outbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    },
                    {
                        "name": "AllowInternetOutBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Allow outbound traffic from all VMs to Internet",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "Internet",
                            "access": "Allow",
                            "priority": 65001,
                            "direction": "Outbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    },
                    {
                        "name": "DenyAllOutBound",
                        "etag": "W/\"ece2fb9b-8e13-4434-ac2a-c5800b3b3c56\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "description": "Deny all outbound traffic",
                            "protocol": "*",
                            "sourcePortRange": "*",
                            "destinationPortRange": "*",
                            "sourceAddressPrefix": "*",
                            "destinationAddressPrefix": "*",
                            "access": "Deny",
                            "priority": 65500,
                            "direction": "Outbound",
                            "sourcePortRanges": [],
                            "destinationPortRanges": [],
                            "sourceAddressPrefixes": [],
                            "destinationAddressPrefixes": []
                        }
                    }
                ]
            },
            "dependsOn": []
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/publicIPAddresses/SimpleVM-ip'.",
            "type": "Microsoft.Network/publicIPAddresses",
            "sku": {
                "name": "Basic"
            },
            "name": "[parameters('publicIPAddresses_SimpleVM_ip_name')]",
            "apiVersion": "2017-10-01",
            "location": "centralus",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "resourceGuid": "6ebcb25d-2340-4438-bfa5-8301ba372db9",
                "ipAddress": "52.173.136.16",
                "publicIPAddressVersion": "IPv4",
                "publicIPAllocationMethod": "Dynamic",
                "idleTimeoutInMinutes": 4
            },
            "dependsOn": []
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/virtualNetworks/SimpleVNet'.",
            "type": "Microsoft.Network/virtualNetworks",
            "name": "[parameters('virtualNetworks_SimpleVNet_name')]",
            "apiVersion": "2017-10-01",
            "location": "centralus",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "resourceGuid": "31e3bbf2-3593-4972-8d63-c0024f3394b7",
                "addressSpace": {
                    "addressPrefixes": [
                        "10.5.0.0/16"
                    ]
                },
                "subnets": [
                    {
                        "name": "default",
                        "etag": "W/\"add0de6e-d14d-4511-b107-739686a5dd70\"",
                        "properties": {
                            "provisioningState": "Succeeded",
                            "addressPrefix": "10.5.0.0/24"
                        }
                    }
                ],
                "virtualNetworkPeerings": [],
                "enableDdosProtection": false,
                "enableVmProtection": false
            },
            "dependsOn": []
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Storage/storageAccounts/simplestorage1'.",
            "type": "Microsoft.Storage/storageAccounts",
            "sku": {
                "name": "Standard_LRS",
                "tier": "Standard"
            },
            "kind": "Storage",
            "name": "[parameters('storageAccounts_simplestorage1_name')]",
            "apiVersion": "2017-10-01",
            "location": "centralus",
            "identity": {
                "principalId": "ba12dbb9-d280-4037-ae54-8ce938863a41",
                "tenantId": "f3c4e7bf-60d1-40db-aa86-fcf229eb6d77",
                "type": "SystemAssigned"
            },
            "tags": {},
            "scale": null,
            "properties": {
                "networkAcls": {
                    "bypass": "AzureServices",
                    "virtualNetworkRules": [],
                    "ipRules": [],
                    "defaultAction": "Allow"
                },
                "supportsHttpsTrafficOnly": false,
                "encryption": {
                    "services": {
                        "file": {
                            "enabled": true
                        },
                        "blob": {
                            "enabled": true
                        }
                    },
                    "keySource": "Microsoft.Storage"
                }
            },
            "dependsOn": []
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/networkSecurityGroups/SimpleVM-nsg/securityRules/default-allow-rdp'.",
            "type": "Microsoft.Network/networkSecurityGroups/securityRules",
            "name": "[concat(parameters('networkSecurityGroups_SimpleVM_nsg_name'), '/', parameters('securityRules_default_allow_rdp_name'))]",
            "apiVersion": "2017-10-01",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "protocol": "TCP",
                "sourcePortRange": "*",
                "destinationPortRange": "3389",
                "sourceAddressPrefix": "*",
                "destinationAddressPrefix": "*",
                "access": "Allow",
                "priority": 1000,
                "direction": "Inbound",
                "sourcePortRanges": [],
                "destinationPortRanges": [],
                "sourceAddressPrefixes": [],
                "destinationAddressPrefixes": []
            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/networkSecurityGroups', parameters('networkSecurityGroups_SimpleVM_nsg_name'))]"
            ]
        },
        {
            "comments": "Generalized from resource: '/subscriptions/7b790d29-944d-4f0f-861b-928e4774cde9/resourceGroups/SimpleVM/providers/Microsoft.Network/virtualNetworks/SimpleVNet/subnets/default'.",
            "type": "Microsoft.Network/virtualNetworks/subnets",
            "name": "[concat(parameters('virtualNetworks_SimpleVNet_name'), '/', parameters('subnets_default_name'))]",
            "apiVersion": "2017-10-01",
            "scale": null,
            "properties": {
                "provisioningState": "Succeeded",
                "addressPrefix": "10.5.0.0/24"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworks_SimpleVNet_name'))]"
            ]
        }
    ]
}

1 个答案:

答案 0 :(得分:0)

模板非常大,我无法看到它。但错误意味着您的模板中有一个依赖循环。您需要分析模板中的dependsOnreference()来检测它。

因为这两者都充当依赖“标记”