0
votes

Thanks in advance, I'm new to ARM templates and still learning how it works. I've a VNET with resources in it, VNET address space is 10.0.0.0/16 and it contains one single subnet with address space 10.0.0.0/16 I'm trying to update the DNS using ARM template and it throws me an error

"New-AzureRmResourceGroupDeployment : 11.50.14 PM - Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The provided value for the template parameter 'virtualNetworkSubnetaddress' at line 
'26' and column '40' is not valid.'."

This is my deployment file

  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",

  "contentVersion": "1.0.0.0",

  "parameters": {

    "location": {

      "type": "string",

      "metadata": {

        "Description": "The region to deploy the resources into"

      }

    },

    "virtualNetworkName": {

      "type": "string",

      "metadata": {

        "Description": "The name of the Virtual Network"

      }

    },

    "virtualNetworkAddressRange": {

      "type": "string",

      "metadata": {

        "Description": "The address range of the virtual network in CIDR format"

      },

      "defaultValue": "10.0.0.0/16"

    },


    "virtualNetworkSubnetaddress": {

      "type": "array",

      "metadata": {

        "Description": "The subnet definition for the virtual network"

      }

    },

    "dnsAddress": {

      "type": "array",

      "metadata": {

        "Description": "The DNS address(es) of the DNS Server(s) used by the virtual network"

      }

    },
  },

  "resources": [

    {

      "name": "[parameters('virtualNetworkName')]",

      "type": "Microsoft.Network/virtualNetworks",

      "location": "[parameters('location')]",

      "apiVersion": "2018-02-01",

      "properties": {

        "addressSpace": {

          "addressPrefixes": [

            "[parameters('virtualNetworkAddressRange')]"

          ]

        },

        "dhcpOptions": {

          "dnsServers": "[parameters('dnsAddress')]"

        },

        "subnets": "[parameters('virtualNetworkSubnetaddress')]"

      }

    }

  ],

  "outputs": {}

}

Below is my parameter file

{

  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",

  "contentVersion": "1.0.0.0",

  "parameters": {
    "dnsaddress": {

      "value": ["10.0.0.4"]

    },
    "location": {

      "value": "East US"

    },
    "virtualNetworkAddressRange": {

      "value": "10.0.0.0/16"

    },
    "virtualNetworkName": {

      "value": "vnettest"

    },
    "virtualNetworkSubnetaddress": {

      "value": ["10.0.0.0/16"]

    }
  }
}

I'm not sure what I'm doing wrong.

I tried using [] bracket for parameter and Getting error

"{"code":"DeploymentFailed","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details.","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\": \"InvalidRequestFormat\",\r\n \"message\": \"Cannot parse the request.\",\r\n \"details\": [\r\n {\r\n \"code\": \"InvalidJson\",\r\n \"message\": \"Error converting value \"10.0.0.0/16\" to type 'Microsoft.WindowsAzure.Networking.Nrp.Frontend.Contract.Csm.Public.Subnet'. Path 'properties.subnets[0]', line 1, position 153.\"\r\n }\r\n ]\r\n }\r\n}"}]}"

1

1 Answers

1
votes

your subnet definition is just an array, but it should be an array of objects, like this:

        "subnets": [
          {
            "name": "[variables('subnet1Name')]",
            "properties": {
              "addressPrefix": "10.0.0.0/24"
            }
          },
          {
            "name": "[variables('subnet2Name')]",
            "properties": {
              "addressPrefix": "10.0.1.0/24"
            }
          }
        ]

Example: https://github.com/Azure/azure-quickstart-templates/blob/master/101-1vm-2nics-2subnets-1vnet/azuredeploy.json#L139

Reference: https://docs.microsoft.com/en-us/azure/templates/microsoft.network/2018-11-01/virtualnetworks

ps. in your case if you only want to update DNS for the vnet your subnet definition has to match actual vnet subnet definition, else it will overwrite it with your input