我从 Route 53 得到了一个域(skhole.club)并自动生成了一个主机区域 skhole.club。
我创建了一个新的主机区 alb.skhole.club。
记录是由我的地形代码添加的。
当我在 skhole.club 中运行 dig 命令时,dig 返回记录。
另一方面,alb.skhole.club 不返回任何记录。
这是第一次使用自定义域,所以我可能会犯一个低级错误。 任何解决方案或提示?
版本
required_providers {
aws = {
source = "hashicorp/aws"
version = "4.59.0"
}
}
data "aws_route53_zone" "host_domain" {
name = local.host_domain
}
data "aws_route53_zone" "alb" {
name = "alb.${local.host_domain}"
}
resource "aws_route53_record" "cert_validation" {
for_each = {
for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = data.aws_route53_zone.host_domain.zone_id
}
resource "aws_route53_record" "cert_alb" {
for_each = {
for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
} if length(regexall("^\\*\\.", dvo.domain_name)) == 0
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = data.aws_route53_zone.alb.zone_id
}
resource "aws_acm_certificate" "cert" {
domain_name = local.host_domain
subject_alternative_names = ["alb.${local.host_domain}"]
validation_method = "DNS"
tags = {
Environment = var.app_environment
}
lifecycle {
create_before_destroy = true
}
}
resource "aws_acm_certificate_validation" "cert" {
certificate_arn = aws_acm_certificate.cert.arn
validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn]
}
resource "aws_acm_certificate_validation" "alb" {
certificate_arn = aws_acm_certificate.cert.arn
validation_record_fqdns = [for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.resource_record_name]
}
resource "aws_route53_record" "site" {
zone_id = data.aws_route53_zone.host_domain.zone_id
name = local.host_domain
type = "A"
alias {
name = aws_cloudfront_distribution.static-skhole.domain_name
zone_id = aws_cloudfront_distribution.static-skhole.hosted_zone_id
evaluate_target_health = false
}
}
resource "aws_route53_record" "alb" {
zone_id = data.aws_route53_zone.alb.zone_id
name = "alb.${local.host_domain}"
type = "A"
alias {
name = aws_lb.application_load_balancer.dns_name
zone_id = aws_lb.application_load_balancer.zone_id
evaluate_target_health = false
}
}
dig skhole.club
> dig skhole.club ns +short
ns-306.awsdns-38.com.
ns-1898.awsdns-45.co.uk.
ns-1111.awsdns-10.org.
ns-526.awsdns-01.net.
dig alb.skhole.club(无回应)
> dig alb.skhole.club ns +short
不要为子域创建单独的托管区域。
相反,只需在原始托管区中创建
Alias=Yes
A 记录,记录名称为 alb.skhole.club
。