【问题标题】:updating DNS of existing VNET using ARM template使用 ARM 模板更新现有 VNET 的 DNS
【发布时间】:2019-04-06 20:12:58
【问题描述】:

提前致谢,我是 ARM 模板的新手,仍在学习它的工作原理。我有一个包含资源的 VNET,VNET 地址空间为 10.0.0.0/16,它包含一个地址空间为 10.0.0.0/16 的子网我正在尝试使用 ARM 模板更新 DNS,但它给我一个错误

"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.'."

这是我的部署文件

  "$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": {}

}

下面是我的参数文件

{

  "$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"]

    }
  }
}

我不确定自己做错了什么。

我尝试使用 [] 括号作为参数并出现错误

"{"code":"DeploymentFailed","message":"至少一项资源部署操作失败。请列出部署操作以了解详细信息。使用详情请查看https://aka.ms/arm-debug。","details":[{"code":"BadRequest","message":"{\r\n \"error\": {\r\n \"code\ ": \"InvalidRequestFormat\",\r\n \"message\": \"无法解析请求。\",\r\n \"详细信息\": [\r\n {\r\n \" code\": \"InvalidJson\",\r\n \"message\": \"Error conversion value \"10.0.0.0/16\" to type 'Microsoft.WindowsAzure.Networking.Nrp.Frontend.Contract.Csm .Public.Subnet'。路径 'properties.subnets[0]',第 1 行,位置 153。\"\r\n }\r\n ]\r\n }\r\n}"}]}"

【问题讨论】:

    标签: azure arm-template


    【解决方案1】:

    您的子网定义只是一个数组,但它应该是一个对象数组,如下所示:

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

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

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

    ps。在您的情况下,如果您只想更新 vnet 的 DNS,您的子网定义必须与实际的 vnet 子网定义匹配,否则它将用您的输入覆盖它

    【讨论】:

    • 感谢 Gleb,很高兴您分享了一些有用的模板链接。再次感谢所有帮助。
    猜你喜欢
    • 1970-01-01
    • 2019-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多