简体   繁体   中英

Multiple values for a property on resource in Azure ARM Template

According to https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-multiple#property-iteration it should be possible to create multiple values on a resource using copy but I can't make it work. Here is my code...

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": { 
    "appServiceName": {
      "type": "string",
      "metadata": {
        "description": "Name of app service to apply SSL to."
      }
    },
    "certificateName": {
      "type": "string",
      "metadata": {
        "description": "User friendly certificate resource name"
      }
    },
    "appServicePlan": {
      "type": "string",
      "metadata": {
        "description": "App Service Plan Name"
      }
    },
    "keyVaultId": {
      "type": "string",
      "metadata": {
        "description": "Existing Key Vault resource Id with an access     policy to allow Microsoft.Web RP to read Key Vault secrets (Checkout README.md for more information)"
      }
    },
    "hostname": {
      "type": "array",
      "metadata": {
        "description": "Custom hostname for creating SSL binding. This hostname should already be assigned to the Web App"
      }
    }
  },
  "resources": [
    {
      "apiVersion": "2017-03-30",
      "type": "Microsoft.Web/sites",
      "name": "[parameters('appServiceName')]",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[resourceId('Microsoft.Web/certificates', parameters('certificateName'))]"
      ],
      "properties": {
        "copy": [
          {
            "name": "hostnames",
            "count": "[length(parameters('hostname'))]",
            "input": {
              "name": "[copyIndex('hostnames')]",
              "properties": {
                "hostNameSslStates": [
                  {
                    "name": "[[copyIndex(hostname)]]",
                    "sslState": "SniEnabled",
                    "thumbprint": "[reference(resourceId('Microsoft.Web/certificates', parameters('certificateName'))).Thumbprint]",
                   "toUpdate": true
                  }
                ]
              }
            }
           } 
        ]
      }
    },
    {
      "type": "Microsoft.Web/certificates",
      "name": "[parameters('certificateName')]",
      "apiVersion": "2016-03-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "keyVaultId": "[parameters('keyVaultId')]",
        "keyVaultSecretName": "[parameters('certificateName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms',parameters('appServicePlan'))]"
      }
    }
  ]
}

And it returns Error: Code=InvalidTemplate; Message=Deployment template l anguage expression evaluation failed: 'Unable to parse language expression 'copyIndex(hostname)]': expecte d token 'LeftParenthesis' and actual 'RightParenthesis'.'. Please see https://aka.ms/arm-template-expressi ons for usage details.

Any ideas what am I doing wrong?

Thanks in advance!

the error gives is away:

change "[[copyIndex(hostname)]]", to "[copyIndex('hostname')]"

you even have it right in other places, why not here?

and you probably want to do this:

"[parameters('hostname')[copyIndex('hostname')]]"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM