How can I create a route53 record to an alb?

强颜欢笑 提交于 2020-12-29 05:39:48

问题


I want to create a new alb and a route53 record that points to it.

I see I have the DNS name: ${aws_lb.MYALB.dns_name}

Is it possible to create a cname to the public DNS name with aws_route53_record resource?


回答1:


See the Terraform Route53 Record docs

You can add a basic CNAME entry with the following:

resource "aws_route53_record" "cname_route53_record" {
  zone_id = "${aws_route53_zone.primary.zone_id}" # Replace with your zone ID
  name    = "www.example.com" # Replace with your subdomain, Note: not valid with "apex" domains, e.g. example.com
  type    = "CNAME"
  ttl     = "60"
  records = ["${aws_lb.MYALB.dns_name}"]
}

Or if you're are using an "apex" domain (e.g. example.com) consider using an Alias (AWS Alias Docs):

resource "aws_route53_record" "alias_route53_record" {
  zone_id = "${aws_route53_zone.primary.zone_id}" # Replace with your zone ID
  name    = "example.com" # Replace with your name/domain/subdomain
  type    = "A"

  alias {
    name                   = "${aws_lb.MYALB.dns_name}"
    zone_id                = "${aws_lb.MYALB.zone_id}"
    evaluate_target_health = true
  }
}


来源:https://stackoverflow.com/questions/48919317/how-can-i-create-a-route53-record-to-an-alb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!