使用 ARM 模板将自定义 DNS 服务器 IP 添加到 Azure VM NIC
Add custom DNS Server IP to an Azure VM NIC using ARM 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
处于同一级别:
所以只需尝试将 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'))]"
]
}
我尝试使用下面的 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'))]"
]
}