我尝试使用下面的 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
处于同一级别:
因此,只需尝试将 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/