使用 Terraform 创建具有 DNS 验证的 ACM 证书
·
这就是我创建 HTTPS AWS 证书 (ACM) 并使用 DNS 验证在 AWSRoute53 中使用我的域对其进行验证的方式,所有这些都使用基础设施作为代码工具 Terraform。
这就是我创建 HTTPS AWS 证书 (ACM) 并使用 DNS 验证在 AWSRoute53 中使用我的域对其进行验证的方式,所有这些都使用基础设施作为代码工具 Terraform。
先决条件
-
AWS CLI 配置
-
地形
-
R53 域
-
AWS Terraform 提供商
为您的域添加变量
variable "root_domain_name" {
type = string
default = "helloworld.info"
}
进入全屏模式 退出全屏模式
- 将上面的
helloworld.info
替换为你的域
Route53
我已经有一条进口的 53 号公路。有关更多信息,请参阅 terraform 文档
resource "aws_route53_zone" "hello_world_zone" {
name = var.root_domain_name
}
Create an ACM Certificate
resource "aws_acm_certificate" "hello_certificate" {
domain_name = var.root_domain_name
validation_method = "DNS"
lifecycle {
create_before_destroy = true
}
}
进入全屏模式 退出全屏模式
-
这将为您设置为变量的域名创建 AWS ACM 证书
-
设置验证模式为 DNS
添加 DNS 记录
resource "aws_route53_record" "hello_cert_dns" {
allow_overwrite = true
name = tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_name
records = [tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_value]
type = tolist(aws_acm_certificate.hello_certificate.domain_validation_options)[0].resource_record_type
zone_id = aws_route53_zone.hello_world_zone.zone_id
ttl = 60
}
进入全屏模式 退出全屏模式
- 这会从上面的资源中添加 DNS 记录,并将它们输入到您的 Route53 主机区域。与您手动执行此操作的方式类似
验证证书
resource "aws_acm_certificate_validation" "hello_cert_validate" {
certificate_arn = aws_acm_certificate.hello_certificate.arn
validation_record_fqdns = [aws_route53_record.hello_cert_dns.fqdn]
}
进入全屏模式 退出全屏模式
- 这将使用您的域名验证您的 ACM 证书
运行 Terraform
terraform fmt
terraform validate
terraform plan
terraform apply
进入全屏模式 退出全屏模式
检查ACM
-
在 AWS 控制台 > 证书管理器中
-
你应该有已发出的状态
希望这有帮助😁
随时提出问题或反馈意见✌️
快乐编码,
👨🏾u200d💻
积分
- https://www.oss-group.co.nz/blog/automated-certificates-aws-https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53 _record
зоз100053https://гифы.ком/гийс/сутпаркгийс-26ueZwfsRvivkoHvO
-
https://app.diagrams.net/
-
https://www.terraform.io/
-
https://aws.amazon.com/
更多推荐
所有评论(0)