azure - 使用 ARM 模板将自定义 DNS 服务器 IP 添加到 Azure VM NIC

标签 azure azure-resource-manager azure-rm-template

我尝试使用下面的 ARM 模板代码来创建 Azure VM NIC 并自定义其 DNS 服务器 IP 地址。然而,ARM 模板似乎不起作用。请问可能出了什么问题。 部署模板时,此行 "dnsServers": "[[parameters('dnsAddress')]]"似乎不起作用,并且我收到了错误

"message": "Could not find member 'dnsSettings' on object of type 'NetworkInterfaceIpConfigurationProperties'. Path 'properties.ipConfigurations[0].properties.dnsSettings?

还有其他人遇到过这个问题吗?

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
   
     "dnsAddress": {

      "type": "array",

      "metadata": {

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

      },
      "defaultValue":["10.0.0.4"]

    },
     
   
  },
  "variables": {
    "nicName": "[concat(uniquestring(resourceGroup().id), 'myVMNic')]",
    "addressPrefix": "10.0.0.0/16",
    "subnetName": "Subnet",
    "subnetPrefix": "10.0.0.0/24",
    "virtualNetworkName": "MyVNET",
    "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), variables('subnetName'))]"
   
  },
  "resources": [
    
    {
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[variables('virtualNetworkName')]",
      "apiVersion": "2020-05-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('addressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('subnetName')]",
            "properties": {
              "addressPrefix": "[variables('subnetPrefix')]"
            
            }
          }
        ]
      }
    },
    {
      "type": "Microsoft.Network/networkInterfaces",
      "name": "[variables('nicName')]",
      "apiVersion": "2020-05-01",
      "location": "[resourceGroup().location]",
      "properties": {
        "ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Dynamic",
              "subnet": {
                "id": "[variables('subnetRef')]"
              },
              "dnsSettings": {
                  "dnsServers": "[[parameters('dnsAddress')]]"
                    
                }
              
            }
          }
        ]
      },
       "dependsOn": [
         "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
      ]
    }
    
    
  ]
 
}

最佳答案

基于official ARM template reference of network interfaces , dnsSettings 不是 ipConfigurations 的成员,它与 properties 下的 ipConfigurations 处于同一级别:

enter image description here

因此,只需尝试将 dnsSettings 移动到与 ipConfigurations 相同的级别,如下所示:

{
    "type": "Microsoft.Network/networkInterfaces",
    "name": "[variables('nicName')]",
    "apiVersion": "2020-05-01",
    "location": "[resourceGroup().location]",
    "properties": {
        "ipConfigurations": [{
                "name": "ipconfig1",
                "properties": {
                    "privateIPAllocationMethod": "Dynamic",
                    "subnet": {
                        "id": "[variables('subnetRef')]"
                    }
                }
            }
        ],
        "dnsSettings": {
            "dnsServers": "[[parameters('dnsAddress')]]"
        }
    },
    "dependsOn": [
        "[resourceId('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]"
    ]
}

关于azure - 使用 ARM 模板将自定义 DNS 服务器 IP 添加到 Azure VM NIC,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66599398/

相关文章:

azure - ARM 模板中有什么方法可以使用类似 Case 的语句吗?

Azure 流分析作业 - 转换查询 - ARM 模板中的正确格式

azure - 如何使用 Azure ARM 模板将 VM 部署到资源组 "A"并引用资源组 "B"中的现有 key 保管库?

json - ARM 模板 - 如何删除参数字符串中的空格?

azure - 模板部署后输出 Azure SQL 数据库连接字符串

azure - 如何根据Azure中的部署名称删除所有已部署的资源

list - 容器的 Azure SAS token 引发 'invalid Signature Size' 错误

python - 如何通过Python SDK创建Azure网络安全组

c# - 使用 cron 或逻辑应用程序的 Azure webjob 哪一个是成本有效的?Azure webjob 是否免费?

azure - Azure Functions 应用服务中的最大突发和最大扩展限制之间有什么区别