具有API网关,Route53和SSL认证相互依赖性问题的Terraform

问题描述 投票:2回答:1

我似乎无法从使用terraform的API-Gateway,Route53获得ACM的SSL证书。似乎存在一个相互依赖的问题。

data "aws_route53_zone" "root_domain" {
  name         = "${var.route53_root_domain_name}"
  private_zone = false
}

# The domain name to use with api-gateway
resource "aws_api_gateway_domain_name" "domain_name" {
  domain_name = "${var.route53_sub_domain_name}"

  certificate_arn = "${aws_acm_certificate.cert.arn}"
}

resource "aws_route53_record" "sub_domain" {
  name    = "${var.route53_sub_domain_name}"
  type    = "A"
  zone_id = "${data.aws_route53_zone.root_domain.zone_id}"

  alias {
    name                   = "${aws_api_gateway_domain_name.domain_name.cloudfront_domain_name}"
    zone_id                = "${aws_api_gateway_domain_name.domain_name.cloudfront_zone_id}"
    evaluate_target_health = false
  }
}

resource "aws_acm_certificate" "cert" {
  # api-gateway / cloudfront certificates need to use the us-east-1 region
  provider          = "aws.cloudfront-acm-certs"
  domain_name       = "${var.route53_sub_domain_name}"
  validation_method = "DNS"

  lifecycle {
    create_before_destroy = true
  }
}

resource "aws_route53_record" "cert_validation" {
  name    = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_name}"
  type    = "${aws_acm_certificate.cert.domain_validation_options.0.resource_record_type}"
  zone_id = "${aws_route53_record.sub_domain.zone_id}"
  records = ["${aws_acm_certificate.cert.domain_validation_options.0.resource_record_value}"]
  ttl     = 60
}

resource "aws_acm_certificate_validation" "cert" {
  # api-gateway / cloudfront certificates need to use the us-east-1 region
  provider          = "aws.cloudfront-acm-certs"

  certificate_arn         = "${aws_acm_certificate.cert.arn}"
  validation_record_fqdns = ["${aws_route53_record.cert_validation.fqdn}"]
}

问题似乎是:

  1. aws_api_gateway_domain_name需要aws_acm_certificate
  2. 必须验证aws_acm_certificate,因此步骤3
  3. aws_route53_record.cert_validation需要aws_route53_record.sub_domain
  4. aws_route53_record.subdomain需要aws_api_gateway_domain_name
  5. 转到1

每次我尝试使用给定的配置时,我都会收到以下错误:

aws_api_gateway_domain_name.domain_name:创建API网关域名时出错:BadRequestException:无法将证书arn:aws:acm:us-east-1:yyyy:certificate / zzzz与CloudFront关联。此错误可能会阻止域名audit-log.taspli.com在API网关中使用长达40分钟。请确保证书域名与请求的域名匹配,并且该用户有权在“*”资源上调用cloudfront:UpdateDistribution。状态码:400,请求ID:xxxx

amazon-web-services aws-api-gateway terraform amazon-route53 terraform-provider-aws
1个回答
© www.soinside.com 2019 - 2024. All rights reserved.