【问题标题】:Cannot create azure private dns A record with its ip by using ARM template无法使用 ARM 模板创建带有 ip 的 azure private dns A 记录
【发布时间】:2021-10-28 20:10:02
【问题描述】:

我正在尝试使用 ARM template 在 Azure 私有 DNS 区域中创建 A 记录。记录创建成功,但没有IP,也没有TTL。 我的模板如下:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "DNSZoneName": {
      "type": "string",
      "defaultValue": "privatelink.database.windows.net",
      "metadata": {
        "description": "The name of the DNS zone. Must have at least 2 segements, e.g. hostname.org"
      }
    },
    "newRecordName": {
      "type": "string",
      "defaultValue": "pe-sql3",
      "metadata": {
        "description": "The name of the DNS record to be created. The name is relative to the zone, not the FQDN."
      }
    }
  },

  "resources": [
    {

      "type": "Microsoft.Network/privateDnsZones/A",
      "apiVersion": "2018-09-01",
      "name": "[concat(parameters('DNSZoneName'), '/', parameters('newRecordName'))]",
      "location": "global",
      "properties": {
        "TTL": 3600,
        "ARecords": [
          {
            "ipv4Address": "10.0.0.1"
          }
        ]
      }
    }

  ]
}

我的命令是New-AzResourceGroupDeployment -ResourceGroupName myRg -TemplateFile deploy.json

这是来自门户的 A 记录的屏幕截图:

有什么想法吗?

【问题讨论】:

    标签: azure azure-resource-manager azure-dns


    【解决方案1】:

    我认为你有一个竞争条件。添加一个dpendsOn

      "dependsOn": [
        "[parameters('DNSZoneName')]"
      ],
    

    像这样: [编辑:同时指定 DNS 区域资源]

    "resources": [
    {
      "type": "Microsoft.Network/privateDnsZones",
      "apiVersion": "2018-05-01",
      "name": "[parameters('DNSZoneName')]",
      "location": "global"
    },
    {
        "type": "Microsoft.Network/privateDnsZones/A",
        "apiVersion": "2018-09-01",
        "name": "[concat(parameters('DNSZoneName'), '/', parameters('newRecordName'))]",
        "location": "global",
        "dependsOn": [
            "[parameters('DNSZoneName')]"
        ],
        "properties": {
            "TTL": 3600,
            "ARecords": [
              {
                "ipv4Address": "10.0.0.1"
              }
            ]
        }
      }
    ]
    

    【讨论】:

    • 添加时出现此错误:New-AzResourceGroupDeployment: 7:06:24 AM - Error: Code=InvalidTemplate;消息=部署模板验证失败:'模板引用'privatelink.database.windows.net'无效:找不到具有此名称的模板资源或资源副本。请参阅aka.ms/arm-template-expressions/#reference 了解使用详情。'.
    • @MoonHorse 错误消息意味着没有DNSZoneName的资源定义。我更新了我的答案以包括一个。
    • 我已经试过了。结果相同。它创建一个没有 IP 和 TLS 配置的记录
    【解决方案2】:

    我正在用大写字母写 TTL 和 ARecords。 ttlaRecords 应该是这样的:

        "properties": {
            "ttl": 3600,
            "aRecords": [
                {
                    "ipv4Address": "1.2.3.4"
                }
            ]
        }
    }
    

    但问题是,当它用大写字母编写时,REST API 不会抛出错误并接受请求。通常,它应该返回 http 400 错误。

    不管怎样,我的问题解决了。

    【讨论】:

      猜你喜欢
      • 2021-07-05
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2021-04-24
      相关资源
      最近更新 更多