Azure ARM- Passing array parameters values to Vari

2019-08-20 17:37发布

问题:

I am here trying to pass array of email values and reference it to variables, so that it can iterate over each value and deploy.My requirement is to keep parameter file separately so that i can touch parameter file only incase of any updation(more email details). Im ending up with errors trying this way. Please help me how can i pass.

Errors: 1.'The provided value for the template parameter 'emailReceiverName' at line '1' and column '487' is not valid.'. 2. "message": "At least one resource deployment operation failed. Please list deployment operations for details.

#####TemplateDeployment.json######

{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
    "actionGroupName": {
      "type": "array",
      "metadata": {
        "description": "Unique name (within the Resource Group) for the Action group."
      }
    },
    "actionGroupShortName": {
      "type": "string",
      "defaultValue": "newActionGroup",
      "metadata": {
        "description": "Short name (maximum 12 characters) for the Action group."
      }
    },
    "emailReceiverName": {
      "type": "array",
      "metadata": {
        "description": "email receiver service Name."
      }
    },
    "emailReceiverAddress": {
      "type": "array",
      "metadata": {
        "description": "email receiver address."
      }
    }
  },
  "variables": {
          "actionGroups": [
        {
            "EmailName": "[array(parameters('emailReceiverName'))]",
            "EmailAddress": "[array(parameters('emailReceiverAddress'))]"
        }
          ]
  } ,
"resources": [
    {
    "type": "Microsoft.Insights/actionGroups",
    "apiVersion": "2018-03-01",
    "name": "actionname",
    "location": "Global",
    "properties": {
        "groupShortName": "short",
        "enabled": true,
        "copy": [
            {
                "name": "emailReceivers",
                "count": "[length(variables('actionGroups'))]",
                "input": {
                    "name": "[variables('actionGroups')[copyIndex('emailReceivers')].EmailName]",
                    "emailAddress": "[variables('actionGroups')[copyIndex('emailReceivers')].EmailAddress]"

                }

                }

        ]
    }
}
    ]
}

**#####TemplateDeployment.json ends here ######

##parameter.json########**
{
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "actionGroupName": {
            "value": "actiongroupslb"
        },
        "actionGroupShortName": {
            "value": "agSLB"
        },
        "emailReceiverName": {
            "value": ["siva1","siva2",........]
        },
        "emailReceiverAddress": {
            "value": ["sa@ga.com","s@g.com",........]
        }

    }
}

回答1:

ok, I'm not sure I understand you correctly (sorry). But i think you just need this bit:

{
    "name": "emailReceivers",
    "count": "[length(parameters('emailReceiverName'))]",
    "input": {
        "name": "[(parameters('emailReceiverName')[copyIndex('emailReceivers')]]",
        "emailAddress": "[(parameters('emailReceiverAddress')[copyIndex('emailReceivers')]]"
    }
}

and just drop this variable actionGroups