【问题标题】:How can i specify the dns servers when terrafrorm uses aws_route53_zoneterraform 使用 aws_route53_zone 时如何指定 dns 服务器
【发布时间】:2017-06-17 21:00:39
【问题描述】:

当 terraform 运行以下命令时,它显然会选择随机 NS 服务器:

resource "aws_route53_zone" "example.com" {
  name = "example.com"
}

这个问题是我在 AWS 中的注册域已经指定了 NS 服务器。有没有办法指定此资源使用的 NS 服务器 - 或者可以将托管域的 NS 服务器更改为创建区域时选择的服务器?

【问题讨论】:

  • 您是说您的域已经有一个 Route53 区域吗?如果是这种情况,您只需使用 terraform import 将该区域带入您的状态,以便 Terraform 可以管理它。
  • 不,我是说我在 AWS 上注册了一个域,我正在使用 terraform 创建一个区域。
  • 在 aws 面板右侧的 Registered Domains > exmaple.com 下有一个地方可以添加您的 dns 服务器。当 terraform 创建新区域时,这些服务器不会更新......该区域会在托管区域中显示一堆随机 NS 服务器,这些服务器与注册域设置中的内容不匹配。我需要一种方法来确保这些同步。
  • 我可以选择将它们设置为 terraform 创建的区域所使用的内容,(手动)是的。我希望 terraform 进行编辑。
  • 搞乱可重用委托集似乎是解决这个问题的好方法......将集 id 传递给 aws_route53_zone 让我知道我需要什么。

标签: amazon-web-services dns terraform


【解决方案1】:

当您创建新区域时,AWS 会为您生成名称服务器列表。使用 Terraform 中的这个示例。

resource "aws_route53_zone" "dev" {
  name = "dev.example.com"

  tags {
    Environment = "dev"
  }
}

resource "aws_route53_record" "dev-ns" {
  zone_id = "${aws_route53_zone.main.zone_id}"
  name    = "dev.example.com"
  type    = "NS"
  ttl     = "30"

  records = [
    "${aws_route53_zone.dev.name_servers.0}",
    "${aws_route53_zone.dev.name_servers.1}",
    "${aws_route53_zone.dev.name_servers.2}",
    "${aws_route53_zone.dev.name_servers.3}",
  ]
}

https://www.terraform.io/docs/providers/aws/r/route53_zone.html

API 在调用创建区域后返回一个委托集。

http://docs.aws.amazon.com/Route53/latest/APIReference/API_CreateHostedZone.html#API_CreateHostedZone_ResponseSyntax

【讨论】:

    【解决方案2】:

    我已经能够指定 DNS 服务器,但我想 AWS 正在根据可用性、负载等分配服务器......所以您可能需要认真考虑将这些配置放入其中。

    resource "aws_route53_record" "primary-ns" {
      zone_id = "${aws_route53_zone.primary.zone_id}"
      name    = "www.bacon.rocks"
      type = "NS"
      ttl = "172800"
      records = ["ns-869.awsdns-44.net","ns-1237.awsdns-26.org","ns-1846.awsdns-38.co.uk","ns-325.awsdns-40.com"]
    }
    

    或者类似的东西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-05
      • 2016-09-09
      • 2012-04-29
      • 2021-10-10
      • 2017-06-29
      • 2023-03-12
      相关资源
      最近更新 更多