0

Please help me understand what is wrong with my Azure ARM template here, Which is very basic, takes some input arguments and prints out resourceId.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "virtualNetworkName": {
      "type": "string"
    },
    "virtualNetworkResourceGroupName": {
      "type": "string"
    },
    "subnetName": {
      "type": "string"
    },
    "location": {
      "type": "string",
      "metadata": {
        "description": "Location to Deploy Azure Resources"
      }
    }
  },
  "resources": [],
  "outputs": {
    "subnetRef": {
      "type": "string",
      "value": "[resourceId(parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"
    }
  }
}

Providing the required parameters, it fails with the following Error Message.

Parameter File

{  
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "virtualNetworkName": {
      "value": "core-services-vnet"
    },
    "virtualNetworkResourceGroupName": {
      "value": "core-networking-rg"
    },
    "subnetName": {
      "value": "private"
    },
    "location": {
      "value": "westus"
    }
  }
}
$ az deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus

Deployment failed. Correlation ID: b97a7544-2814-40c0-88c9-fbaaea2bf645. The template output 'subnetRef' is not valid: The provided value 'core-networking-rg' is not valid subscription identifier. Please see https://aka.ms/arm-template-expressions/#resourceid for usage details.

What Am I missing here ?

Thanks, Nag

  • I am not getting an error. Double check your parameter input. Edit your question and include more details on how you are getting this error. – John Hanley Dec 16 '19 at 01:19
  • Does the resource group `myResource-rg`? Sounds like the most likely problem – James Dec 16 '19 at 01:25
  • @johnHanley Updated with more details in the Question – Nag Matukumalli Dec 16 '19 at 01:42
  • @james It is irrespective of any resource group I try. – Nag Matukumalli Dec 16 '19 at 01:42
  • If the vnet is in the same resource group and providing the value as ```"value": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"``` works perfectly fine; but I need to refer to subnet in a different resource group – Nag Matukumalli Dec 16 '19 at 01:43
  • @NagMatukumalli does the target resource group reside in the same location? – James Dec 16 '19 at 02:04
  • @James, yes it does reside in the same location – Nag Matukumalli Dec 16 '19 at 02:43
  • @Nag please double check the resource group name for Virtual network – Muhammad Murad Haider Dec 16 '19 at 05:58
  • It give me impression that resourceId function is assuming the first argument as subscriptionId Instead of Resourcegroup, thus complaining provided value is not subscription identifier. – Nag Matukumalli Dec 16 '19 at 16:17
  • I had added subscriptionID in the value part as ```"value": "[resourceId(subscription().subscriptionId, parameters('virtualNetworkResourceGroupName'), 'Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnetName'))]"``` which ends up with following error – Nag Matukumalli Dec 16 '19 at 16:19
  • ```The template output 'subnetRef' is not valid: Unable to evaluate template language function 'resourceId': function requires fully qualified resource type 'Microsoft.Network/virtualNetworks/subnets' as one of first three arguments for resource at resource group scope, or first two arguments for resource at subscription scope. Please see https://aka.ms/arm-template-expressions/#resourceid for usage details..``` – Nag Matukumalli Dec 16 '19 at 16:19
  • @NagMatukumalli Try to use `az group deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus`? Let me know if this works. – Nancy Dec 17 '19 at 09:54
  • 1
    Thanks @NancyXiong, That worked. – Nag Matukumalli Dec 17 '19 at 17:58

1 Answers1

1

The problem is the deployment scope. You can target your deployment to either an Azure subscription or a resource group within a subscription.

In your template, the $schema https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json# is used for resource group deployments, while the commands az deployment create you use is for subscription-level deployments. The schema https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json# for subscription-level deployments is different than the schema for resource group deployments. You could get references from creating resource groups and resources at the subscription level.

In this case, you can use the commands az group deployment create -n core-deploy --template-file azuredeploy.json --parameters @params.json --location westus instead of az deployment create xxx to fix this issue.

Nancy
  • 26,865
  • 3
  • 18
  • 34