gpt4 book ai didi

amazon-web-services - 创建 LB 监听器时出现 CertificateNotfound 错误

转载 作者:行者123 更新时间:2023-12-03 18:45:40 28 4
gpt4 key购买 nike

我在向 LB 监听器添加证书时遇到问题。这是用于执行此操作的代码(注意这些是代码片段):

全局/main.tf

  resource "aws_acm_certificate" "demo_cert_east" {
provider = "aws.east"
domain_name = "*.mydomain.com"
validation_method = "DNS"

tags {
Name = "demo certificate"
Environment = "demo"
}

lifecycle {
create_before_destroy = true
}
}

阶段/主要.tf
data "aws_acm_certificate" "demo_cert" {
domain = "*.mydomain.com"
statuses = ["ISSUED", "PENDING_VALIDATION"]
}

resource "aws_lb_listener" "wfe_demo_ssl" {
load_balancer_arn = "${aws_lb.wfe_demo.arn}"
port = "443"
protocol = "HTTPS"
ssl_policy = "ELBSecurityPolicy-2016-08"
certificate_arn = "${data.aws_acm_certificate.demo_cert.arn}"

default_action {
target_group_arn = "${aws_lb_target_group.wfe_demo.arn}"
type = "forward"
}
}

我已经确保这两个资源都在 aws-east 区域。我收到错误:

Error creating LB Listener: CertificateNotFound: Certificate 'arn:aws:acm:us-east-1:078395932517:certificate/b83ba534-ef9d-4a07-ae13-832695dc8b5a' not found.



因此,数据源正确检索了证书,但监听器似乎无法找到它。

最佳答案

为了能够将 ACM 证书附加到负载均衡器或其他 AWS 资源(例如 Cloudfront),必须先对其进行验证。
更改数据源以仅查找 ISSUED如果没有与您的模式匹配的经过验证的证书,则证书应将错误推送到数据源中:

data "aws_acm_certificate" "demo_cert" {
domain = "*.mydomain.com"
statuses = ["ISSUED"]
}
要验证证书,您可以在请求时手动处理带外,使用其他工具为您自动验证它,或者您可以使用 Terraform 的 aws_acm_certificate_validation resource创建 ACM 证书请求时:
resource "aws_acm_certificate" "cert" {
domain_name = "example.com"
validation_method = "DNS"
}

data "aws_route53_zone" "zone" {
name = "example.com."
private_zone = false
}

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 = data.aws_route53_zone.zone.id
records = [aws_acm_certificate.cert.domain_validation_options.0.resource_record_value]
ttl = 60
}

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

关于amazon-web-services - 创建 LB 监听器时出现 CertificateNotfound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51270878/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com