ARM Template to create muntiple RG's with Tags

%3CLINGO-SUB%20id%3D%22lingo-sub-1945196%22%20slang%3D%22en-US%22%3EARM%20Template%20to%20create%20muntiple%20RG's%20with%20Tags%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1945196%22%20slang%3D%22en-US%22%3EHi%20All%2C%3CBR%20%2F%3E%3CBR%20%2F%3EI%20am%20trying%20to%20create%20Multiple%20Resource%20groups%20with%20Tag's%20for%20each%20RG.%20Can%20any%20one%20help%20me%20with%20the%20ARM%20template.%20I%20need%20Tempalate%20and%20paramater%20file%20to%20do%20this.%3CBR%20%2F%3E%3CBR%20%2F%3EThis%20is%20the%20template%20file%20am%20trying%20but%20this%20is%20not%20working%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22%24schema%22%3A%20%22%3CA%20href%3D%22https%3A%2F%2Fschema.management.azure.com%2Fschemas%2F2019-04-01%2FdeploymentTemplate.json%23%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fschema.management.azure.com%2Fschemas%2F2019-04-01%2FdeploymentTemplate.json%23%3C%2FA%3E%22%2C%3CBR%20%2F%3E%22contentVersion%22%3A%20%221.0.0.0%22%2C%3CBR%20%2F%3E%22parameters%22%3A%20%7B%3CBR%20%2F%3E%22rgName%22%3A%20%7B%3CBR%20%2F%3E%22type%22%3A%20%22array%22%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%22tags%22%3A%20%7B%3CBR%20%2F%3E%22type%22%3A%20%22object%22%2C%3CBR%20%2F%3E%22defaultValue%22%3A%20%7B%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%22variables%22%3A%20%7B%7D%2C%3CBR%20%2F%3E%22resources%22%3A%20%5B%3CBR%20%2F%3E%7B%3CBR%20%2F%3E%22copy%22%3A%20%7B%3CBR%20%2F%3E%22name%22%3A%20%22RGLoop%22%2C%3CBR%20%2F%3E%22count%22%3A%20%22%5Blength(parameters('rgName'))%5D%22%3CBR%20%2F%3E%7D%2C%3CBR%20%2F%3E%22type%22%3A%20%22Microsoft.Resources%2FresourceGroups%22%2C%3CBR%20%2F%3E%22apiVersion%22%3A%20%222018-05-01%22%2C%3CBR%20%2F%3E%22name%22%3A%20%22%5Bparameters('rgName')%5BcopyIndex('RGLoop')%5D.Name%5D%22%2C%3CBR%20%2F%3E%22location%22%3A%20%22eastus%22%2C%3CBR%20%2F%3E%22tags%22%3A%20%22%5Bparameters('tags')%5BcopyIndex('RGLoop')%5D.tags%5D%22%2C%3CBR%20%2F%3E%22properties%22%3A%20%7B%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%5D%2C%3CBR%20%2F%3E%22outputs%22%3A%20%7B%7D%3CBR%20%2F%3E%7D%3CBR%20%2F%3E%3CBR%20%2F%3EHelp%20me%20to%20complete%20this.%3CBR%20%2F%3E%3CBR%20%2F%3ERegards%2C%3CBR%20%2F%3EVignesh%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1945351%22%20slang%3D%22en-US%22%3ERe%3A%20ARM%20Template%20to%20create%20muntiple%20RG's%20with%20Tags%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1945351%22%20slang%3D%22en-US%22%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F300973%22%20target%3D%22_blank%22%3E%40StefanIvemo%3C%2FA%3E%3CBR%20%2F%3E%3CBR%20%2F%3ECan%20you%20help%20me%20on%20this..%3CBR%20%2F%3E%3CBR%20%2F%3EVignesh%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1945596%22%20slang%3D%22en-US%22%3ERe%3A%20ARM%20Template%20to%20create%20muntiple%20RG's%20with%20Tags%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1945596%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F865597%22%20target%3D%22_blank%22%3E%40vigneshkrcegmailcom%3C%2FA%3E%26nbsp%3BI%20was%20wondering%2C%20what%20errors%20are%20you%20getting%20when%20you%20try%20to%20provision%20the%20resource%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20took%20your%20template%20and%20pasted%20it%20into%20my%20Visual%20Studio%20Code.%20The%20type%20that%20you%20provided%3A%20%22Microsoft.Resources%2FresourceGroups%20isn't%20recognized.%20I%20reviewed%20the%20documentation%20on%20docs.microsoft.com%20and%20see%3A%26nbsp%3B%3C%2FP%3E%3CUL%3E%3CLI%3Emicrosoft.resources%2Fsubscriptions%2Fresourcegroups%3C%2FLI%3E%3C%2FUL%3E%3CP%3EYou%20might%20try%20to%20change%20that.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOtherwise%20please%20update%20what%20errors%20you%20are%20receiving%2C%20please.%3C%2FP%3E%3CDIV%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1946202%22%20slang%3D%22en-US%22%3ERe%3A%20ARM%20Template%20to%20create%20muntiple%20RG's%20with%20Tags%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1946202%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F887614%22%20target%3D%22_blank%22%3E%40ITChristos%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Contributor
Hi All,

I am trying to create Multiple Resource groups with Tag's for each RG. Can any one help me with the ARM template. I need Tempalate and paramater file to do this.

This is the template file am trying but this is not working
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"rgName": {
"type": "array"
},
"tags": {
"type": "object",
"defaultValue": {}
}
},
"variables": {},
"resources": [
{
"copy": {
"name": "RGLoop",
"count": "[length(parameters('rgName'))]"
},
"type": "Microsoft.Resources/resourceGroups",
"apiVersion": "2018-05-01",
"name": "[parameters('rgName')[copyIndex('RGLoop')].Name]",
"location": "eastus",
"tags": "[parameters('tags')[copyIndex('RGLoop')].tags]",
"properties": {}
}
],
"outputs": {}
}

Help me to complete this.

Regards,
Vignesh
5 Replies
@StefanIvemo

Can you help me on this..

Vignesh

@vigneshkrcegmailcom I was wondering, what errors are you getting when you try to provision the resource?

 

I took your template and pasted it into my Visual Studio Code. The type that you provided: "Microsoft.Resources/resourceGroups isn't recognized. I reviewed the documentation on docs.microsoft.com and see: 

  • microsoft.resources/subscriptions/resourcegroups

You might try to change that.

 

Otherwise please update what errors you are receiving, please.

 

@StefanIvemo

 

Hi Stephan,

 

Can you please help me to create Multiple RG with TAG's for each RG.

The script i am trying is given below but it is throwing error.

Ultimate aim is to create Multiple RG's with TAG's

 

Template File i am using is :

{

  "contentVersion": "1.0.0.0",

  "parameters": {

    "rgName": {

      "type": "array"

    },

    "tags": {

      "type": "object",

      "defaultValue": {}

    }

  },

  "variables": {},

  "resources": [

    {

      "copy": {

        "name": "RGLoop",

        "count": "[length(parameters('rgName'))]"

      },

      "type": "Microsoft.Resources/resourceGroups",

      "apiVersion": "2019-10-01",

      "name": "[parameters('rgName')[copyIndex('RGLoop')].Name]",

      "location": "eastus",

      "tags": "[parameters('tags')[copyIndex('RGLoop')].tags]",

      "properties": {}

    }

  ],

  "outputs": {}

}

 

==============================

 

Paramater is given below:

 

{

  "contentVersion": "1.0.0.0",

  "parameters": {

    "rgname": {

      "value": [

        {

          "name": "TestRG"

        }

      ]

    },

    "tags": {

      "value": [

        {

          "Environment": "Test",

          "Team": "skg",

          "Application": "SKG",

          "Business Unit": "non-production",

          "POC": "Vignesh",

          "ManagedBy": "Own"

        }

      ]

    }

  }

}

 

=========================================

 

 

Error I am Getting is:

There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Object'. Actual 'Array'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
##[warning]Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. Task failed while creating or updating the template deployment.. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax
Starting Deployment.
Deployment name is Deploy-RG
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Object'. Actual 'Array'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
##[error]Check out the troubleshooting guide to see if your issue is addressed: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-resource-group-deployment...
##[error]Task failed while creating or updating the template deployment.
Finishing: ARM Template deployment: Resource Group
 
Can you help me to fix this.
 
Regards,
Vignesh

The Error message i am getting is

 

There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Object'. Actual 'Array'. Please see https://aka.ms/resource-manager-parameter-files for usage details.'.
##[warning]Validation errors were found in the Azure Resource Manager template. This can potentially cause template deployment to fail. Task failed while creating or updating the template deployment.. Please follow https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/template-syntax
Starting Deployment.
Deployment name is Deploy-RG
There were errors in your deployment. Error code: InvalidTemplate.
##[error]Deployment template validation failed: 'Template parameter JToken type is not valid. Expected 'Object'. Actual 'Array'.
##[error]Task failed while creating or updating the template deployment.
Finishing: ARM Template deployment: Resource Group