我想创建一个新的 alb 和一个指向它的 route53 记录。
我看到我有 DNS 名称:${aws_lb.MYALB.dns_name}
是否可以使用 aws_route53_record 资源为公共 DNS 名称创建 cname?
我想创建一个新的 alb 和一个指向它的 route53 记录。
我看到我有 DNS 名称:${aws_lb.MYALB.dns_name}
是否可以使用 aws_route53_record 资源为公共 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]
}
或者,如果您使用的是“顶点”域(例如 example.com),请考虑使用别名(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
}
}
是的,如果您使用but not ,则可以创建CNAME
公共 DNS 名称${aws_lb.MYALB.dns_name}
或使用 aws_route53_record 资源。aws_lb.MYALB.dns_name
domain with a subdomain
apex domain(naked domain, root domain)
所以下面的代码Terraform(v0.15.0)
适用CNAME
于domain which has a subdomain
. * CNAME
withapex domain(naked domain, root domain)
导致错误。
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
apex domain(naked domain, root domain)
domain with a subdomain
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
}
}