Terraform 如何创建到ALB的Route 53记录?(美国焊接学会)
我想创建一个新的alb和一个指向它的route53记录 我知道我有DNS名称:Terraform 如何创建到ALB的Route 53记录?(美国焊接学会),terraform,Terraform,我想创建一个新的alb和一个指向它的route53记录 我知道我有DNS名称:${aws_lb.MYALB.DNS_name} 是否可以使用aws_route53_记录资源为公共DNS名称创建cname 参见 您可以添加具有以下内容的基本CNAME条目: resource "aws_route53_record" "cname_route53_record" { zone_id = "${aws_route53_zone.primary.zone_id}" # Replace with yo
${aws_lb.MYALB.DNS_name}
是否可以使用aws_route53_记录资源为公共DNS名称创建cname 参见
您可以添加具有以下内容的基本CNAME条目:
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}"]
}
或者如果您使用的是“顶点”域(例如,示例.com),请考虑使用别名():
是的,如果将
域与子域一起使用而不是顶点域(裸域、根域)
,则可以使用aws_route53_记录资源创建公共DNS名称CNAME
因此Terraform(v0.15.0)
中下面的代码对于CNAME
具有子域的域正常工作*<代码>CNAME
与顶点域(裸域、根域)
一起导致错误
resource "aws_route53_zone" "myZone" {
name = "example.com"
}
resource "aws_route53_record" "myRecord" {
zone_id = aws_route53_zone.myZone.zone_id
name = "www.example.com"
type = "CNAME"
ttl = 60
records = [aws_lb.MYALB.dns_name]
}
此外,Terraform(v0.15.0)
中的以下代码适用于A
或AAAA
具有顶点域(裸域、根域)
的域,甚至适用于具有子域的域
resource "aws_route53_zone" "myZone" {
name = "example.com"
}
resource "aws_route53_record" "myRecord" {
zone_id = aws_route53_zone.myZone.zone_id
name = "example.com" # OR "www.example.com"
type = "A" # OR "AAAA"
alias {
name = aws_lb.MYALB.dns_name
zone_id = aws_lb.MYALB.zone_id
evaluate_target_health = true
}
}
也许值得指出的是,别名A记录比CNAME更好,因为它可以节省更多的DNS查找,而且也是免费的。非常好的解释,谢谢。你的顶点方案是我的赢家。
resource "aws_route53_zone" "myZone" {
name = "example.com"
}
resource "aws_route53_record" "myRecord" {
zone_id = aws_route53_zone.myZone.zone_id
name = "example.com" # OR "www.example.com"
type = "A" # OR "AAAA"
alias {
name = aws_lb.MYALB.dns_name
zone_id = aws_lb.MYALB.zone_id
evaluate_target_health = true
}
}