Cloud/Terraform/AwsAcmCertificateAndValidation

resource "aws_acm_certificate" "cert" {
  domain_name       = "mycert.dev.m.com"
  validation_method = "DNS"

  tags = {
    Environment = "test"
  }

  lifecycle {
    create_before_destroy = true
  }
}

data "aws_route53_zone" "dns" {
  name         = "dev.m.com"  #base domain
  private_zone = false
}

resource "aws_route53_record" "dns" {
  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             = 300
  type            = each.value.type
  zone_id         = data.aws_route53_zone.dns.zone_id
}

resource "aws_acm_certificate_validation" "example" {
  certificate_arn         = aws_acm_certificate.cert.arn
  validation_record_fqdns = [for record in aws_route53_record.dns : record.fqdn]
}


CategoryTerraform

Cloud/Terraform/AwsAcmCertificateAndValidation (last edited 2021-06-17 05:06:40 by PieterSmit)