问题描述
我尝试使用下面的 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')]","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
的成员,它与ipConfigurations
下的properties
处于同一级别:
因此,请尝试将 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'))]"
]
}