本文介绍了使用Terraform在route53上获取托管域的zone_id的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用Terraform创建route53记录,我已经有一个托管域(公共),可以说 example.com 如何获取其zone_id并附加到记录中.如何获取现有route53托管区域的zone_id.我已经写了一个文件,但它的作用是创建另一个托管区域 example.com ,而不是获取现有的 example.com

Hi I am creating route53 record with terraform, I already have a hosted domain (public) lets say example.com how to fetch its zone_id and attach to record. How can I fetch the zone_id of existing route53 hosted zone. I have written a file but what it does it creates another hosted zone example.com rather then fetching existing example.com

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

resource "aws_route53_record" "www" {
  zone_id = data.aws_route53_zone.selected.zone_id
  name    = "dev.${data.aws_route53_zone.selected.name}"
  type    = "A"
  alias {
    name                   = var.alb_dns
    zone_id                = var.zone_id
    evaluate_target_health = false
  }
}

推荐答案

您还需要添加 private_zone = false

data "aws_route53_zone" "selected" {
  name         = "test.com."
private_zone = false
}

resource "aws_route53_record" "www" {
  zone_id = data.aws_route53_zone.selected.zone_id
  name    = "dev.${data.aws_route53_zone.selected.name}"
  type    = "A"
  alias {
    name                   = var.alb_dns
    zone_id                = var.zone_id
    evaluate_target_health = false
  }
}

这篇关于使用Terraform在route53上获取托管域的zone_id的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 14:44