1

I am trying to deploy a storage account arm deployment using visual studio. Below is my template

{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "storageAccountType": {
        "type": "array",
        "defaultValue": [
          "Standard_LRS",
          "Standard_LRS",
          "Standard_GRS"
        ]
      },
      "storageAccountNamePrefix": {
        "type": "string",
        "defaultValue": "az",
        "minLength": 1
      }
    },
  "variables": {

  },
  "resources": [
    {
      "name": "[concat(parameters('storageAccountNamePrefix'),'strg', copyIndex(),uniqueString(resourceGroup().id))]",
      "type": "Microsoft.Storage/storageAccounts",
      "location": "[resourceGroup().location]",
      "apiVersion": "2015-06-15",
      "copy": {
        "count": "[length(parameters('storageAccountType'))]",
        "name": "storageCopy"
      },
      "sku": {
        "name": "[parameters('storageAccountType')[copyIndex()]]"
      },
      "tags": {
        "displayName": "[parameters('storageAccountNamePrefix')[copyIndex()]]"
      },
      "properties": {
        "accountType": "[parameters('storageAccountType')[copyIndex()]]"
      },
      "kind": "Storage"
    }
  ],
  "outputs": {
  }
}

The error is thrown is at the following line

 "name": "[concat(parameters('storageAccountNamePrefix'),'strg', copyIndex(),uniqueString(resourceGroup().id))]",

The error

Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template resource 'azstrg0u2pzkvcrv3eo4' at line '25' and column '10' is not valid: Template language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Templates.Expressions.TemplateFunctionExpression' can't be evaluated.  Please see https://aka.ms/arm-template-expressions for usage details..'.

I don't understand why is this failing because I was able to use concat function in other resource names. I know storage account names can have only characters and numbers no special characters. In the error the resolved name of the resource is accurately displayed. So from the error message it is difficult to know what is wrong with the expression.

Mitul
  • 9,734
  • 4
  • 43
  • 60

1 Answers1

2

I have tried your template, it seems something wrong with below code:

"tags": {
    "displayName": "[parameters('storageAccountNamePrefix')[copyIndex()]]"
  },

Since “'storageAccountNamePrefix'” is not an array. So it will give you error message, please try the following:

"tags": {
    "displayName": "[parameters('storageAccountNamePrefix')]"
  },

2.Please note that prior to version 2016-01-01, 'sku' was called 'accountType' and was found under the 'properties' envelope. We could find this information at this article. So I think we need to remove sku and kind when the api version is “2015-06-15”. I have test both of the following resource info template, it works successfully . Please have a try.

"resources": [
{
  "name": "[concat(parameters('storageAccountNamePrefix'),'strg', copyIndex(),uniqueString(resourceGroup().id))]",
  "type": "Microsoft.Storage/storageAccounts",
  "location": "[resourceGroup().location]",
  "apiVersion": "2015-06-15",
  "copy": {
    "count": "[length(parameters('storageAccountType'))]",
    "name": "storageCopy"
  },
  "tags": {
    "displayName": "[parameters('storageAccountNamePrefix')]"
  },
  "properties": {
    "accountType": "[parameters('storageAccountType')[copyIndex()]]"
  }
}],

or

"resources": [
{
  "name": "[concat(parameters('storageAccountNamePrefix'),'strg', copyIndex(),uniqueString(resourceGroup().id))]",
  "type": "Microsoft.Storage/storageAccounts",
  "location": "[resourceGroup().location]",
  "apiVersion": "2016-01-01",
  "copy": {
    "count": "[length(parameters('storageAccountType'))]",
    "name": "storageCopy"
  },
  "sku": {
    "name": "[parameters('storageAccountType')[copyIndex()]]"
  },
  "tags": {
    "displayName": "[parameters('storageAccountNamePrefix')]"
  },
  "kind": "Storage"
}],
Tom Sun - MSFT
  • 24,161
  • 3
  • 30
  • 47