Forum Discussion

vigneshkrcegmailcom's avatar
vigneshkrcegmailcom
Brass Contributor
Dec 01, 2020

ARM Template to create muntiple RG's with Tags

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
  • 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.

     
    • vigneshkrcegmailcom's avatar
      vigneshkrcegmailcom
      Brass Contributor

      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
      • vigneshkrcegmailcom's avatar
        vigneshkrcegmailcom
        Brass Contributor

        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]Task failed while creating or updating the template deployment.
        Finishing: ARM Template deployment: Resource Group
         
        Can you help me to fix this.
         
        Regards,
        Vignesh

Resources