简体   繁体   中英

Azure ARM Template different Resource Group Dependency Issue

I have a template that deploys a new template in a dedicated resource group for VNETs. I want to deploy a network interface in a subnet of the VNET, but put the network interface in its own separate resource group. When I run the template I receive the following error. I am sure it is a dependency issue, but the dependsOn parameter is not working for me... any ideas?

Recieved Error

  "error": {
    "code": "InvalidResourceReference",
    "message": "Resource /subscriptions/{removed-subscription-id}/resourceGroups/vnet-resource-group/providers/Microsoft.Network/virtualNetworks/my-vnet/subnets/subnet-1 referenced by resource /subscriptions/{removed-subscription-id}/resourceGroups/test-rg-1/providers/Microsoft.Network/networkInterfaces/my-first-nic was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.",
    "details": []
  }
}

Template

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "vnetName": {
      "type": "string",
      "defaultValue": "my-vnet"
    },
    "vnetResourceGroup": {
      "type": "string",
      "defaultValue": "vnet-resource-group"
    },
    "nicResourceGroup": {
      "type": "string",
      "defaultValue": "nic-resource-group"
    }
  },
  "variables": {
    "vnetID": "[resourceId(parameters('vnetResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('vnetName'))]",
    "subnetID": "[concat(variables('vnetID'),'/subnets/','subnet-1')]"
  },
  "resources": [
    {
      "apiVersion": "2017-05-10",
      "name": "vnetNestedTemplate",
      "type": "Microsoft.Resources/deployments",
      "resourceGroup": "[parameters('vnetResourceGroup')]",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "apiVersion": "2018-06-01",
              "name": "my-vnet",
              "type": "Microsoft.Network/virtualNetworks",
              "location": "[resourceGroup().location]",
              "properties": {
                "addressSpace": {
                  "addressPrefixes": [
                    "10.0.0.0/16"
                  ]
                },
                "subnets": [
                  {
                    "name": "subnet-1",
                    "properties": {
                      "addressPrefix": "10.0.0.0/24"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    },
    {
      "apiVersion": "2017-05-10",
      "name": "nestedNicTemplate",
      "type": "Microsoft.Resources/deployments",
      "resourceGroup": "[parameters('nicResourceGroup')]",
      "properties": {
        "mode": "Incremental",
        "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [
            {
              "apiVersion": "2015-06-15",
              "type": "Microsoft.Network/networkInterfaces",
              "name": "my-first-nic",
              "location": "[resourceGroup().location]",
              "dependsOn": [
                "[resourceId(parameters('vnetResourceGroup'), 'Microsoft.Network/virtualNetworks', parameters('vnetName'))]"
              ],
              "properties": {
                "ipConfigurations": [
                  {
                    "name": "ipconfig1",
                    "properties": {
                      "privateIPAllocationMethod": "Static",
                      "subnet": {
                        "id": "[variables('subnetID')]"
                      },
                      "privateIpAddress": "10.0.0.5"
                    }
                  }
                ]
              }
            }
          ]
        }
      }
    }
  ]
}

You need to add:

"dependsOn": [
    "vnetNestedTemplate"
]

to the second deployment. in the template you can only depend on sources that are in the same template. since you are invoking a nested deployment, its not in the same template (but in the nested template).

ps. maybe you are just showing an over simplified example, but there is no point in using nested deployment (ESPECIALLY INLINE) for this.
pps. i'd suggest against using INLINE nested deployments, they really have their weird mechanics

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM