0
votes

I am trying to deploy a number of Private DNS resources in Azure using the following code:

"variables": {
"blobDNSName": "privatelink.blob.core.windows.net",
"databaseDNSName": "privatelink.database.core.windows.net",
"datafactoryDNSName": "privatelink.datafactory.core.windows.net",
"dfsDNSName": "privatelink.dfs.core.windows.net",
"keyvaultDNSName": "privatelink.vaultcore.core.windows.net",
"blobTags": {
  "value": {
    "Application": "Monitor",
    "CostCentre": "[parameters('costCentre')]",
    "Criticality": "[parameters('criticality')]",
    "Owner": "[parameters('owner')]",
    "Project": "[parameters('project')]",
    "Enviroment": "[parameters('environment')]"
  }
},
"databaseTags": {
  "value": {
    "Application": "SQL",
    "CostCentre": "[parameters('costCentre')]",
    "Criticality": "[parameters('criticality')]",
    "Owner": "[parameters('owner')]",
    "Project": "[parameters('project')]",
    "Enviroment": "[parameters('environment')]"
  }
},
"datafactoryTags": {
  "value": {
    "Application": "Data Factory",
    "CostCentre": "[parameters('costCentre')]",
    "Criticality": "[parameters('criticality')]",
    "Owner": "[parameters('owner')]",
    "Project": "[parameters('project')]",
    "Enviroment": "[parameters('environment')]"
  }
},
"dfsTags": {
  "value": {
    "Application": "Data Lake",
    "CostCentre": "[parameters('costCentre')]",
    "Criticality": "[parameters('criticality')]",
    "Owner": "[parameters('owner')]",
    "Project": "[parameters('project')]",
    "Enviroment": "[parameters('environment')]"
  }
},
"keyvaultTags": {
  "value": {
    "Application": "Key Vault",
    "CostCentre": "[parameters('costCentre')]",
    "Criticality": "[parameters('criticality')]",
    "Owner": "[parameters('owner')]",
    "Project": "[parameters('project')]",
    "Enviroment": "[parameters('environment')]"
  }
},
"dnsArray": {
  "value": [
    {
      "dns": "[variables('blobDNSName')]",
      "tags": "[variables('blobTags')]"
    },
    {
      "dns": "[variables('databaseDNSName')]",
      "tags": "[variables('databaseTags')]"
    },
    {
      "dns": "[variables('datafactoryDNSName')]",
      "tags": "[variables('datafactoryTags')]"
    },
    {
      "dns": "[variables('dfsDNSName')]",
      "tags": "[variables('dfsTags')]"
    },
    {
      "dns": "[variables('keyvaultDNSName')]",
      "tags": "[variables('keyvaultTags')]"
    }
  ]
}

and:

"resources": [
{
  "type": "Microsoft.Network/privateDnsZones",
  "apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
  "name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",
  //"tags": "[[copyIndex('dnsCopy')].tags]",
  "copy": {
    "name": "dnsCopy",
    "count": "[length(variables('dnsArray'))]"
  },
  "location": "global",
  "properties": {
    "maxNumberOfRecordSets": 25000,
    "maxNumberOfVirtualNetworkLinks": 1000,
    "maxNumberOfVirtualNetworkLinksWithRegistration": 100,
    "numberOfRecordSets": 1,
    "numberOfVirtualNetworkLinks": 0,
    "numberOfVirtualNetworkLinksWithRegistration": 0,
    "provisioningState": "Succeeded"
  }
}]

The error I get is: Deployment template validation failed: 'The template resource '[variables('dnsArray')[copyIndex('dnsCopy')].value.dns]' at line '150' and column '9' is not valid: The language expression property '0' can't be evaluated, property name must be a string.. Please see https://aka.ms/arm-template-expressions for usage details.'. (Code: InvalidTemplate)

Which is occurring on this line:

"name": "[variables('dnsArray')[copyIndex('dnsCopy')].dns]",

Is what I am trying to attempt possible?

1

1 Answers

0
votes

I've managed to solve the issue after much head scratching and in case anyone encounters such an issue:

    {
  "type": "Microsoft.Network/privateDnsZones",
  "apiVersion": "[utils.apiVersion('Microsoft.Network', 'privateDnsZones')]",
  "name": "[variables('dnsArray').value[copyIndex('dnsCopy')].dns]",
  "tags": "[variables('dnsArray').value[copyIndex('dnsCopy')].tags.value]",
  "copy": {
    "name": "dnsCopy",
    "count": "[length(variables('dnsArray').value)]"
  },
  "location": "global",
  "properties": {
    "maxNumberOfRecordSets": 25000,        "maxNumberOfVirtualNetworkLinks": 1000,
    "maxNumberOfVirtualNetworkLinksWithRegistration": 100,
    "numberOfRecordSets": 1,
    "numberOfVirtualNetworkLinks": 0,
    "numberOfVirtualNetworkLinksWithRegistration": 0,
    "provisioningState": "Succeeded"
  }
}

Note the use of value after dnsArray