0
votes

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

1
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
Does the resource group myResource-rg? Sounds like the most likely problemJames
@johnHanley Updated with more details in the QuestionNag Matukumalli
@james It is irrespective of any resource group I try.Nag Matukumalli
Thanks @NancyXiong, That worked.Nag Matukumalli

1 Answers

1
votes

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.