certificate.tf 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #Certificate
  2. resource "aws_acm_certificate" "cert" {
  3. domain_name = "${var.dns_name}${var.suffix}.${var.dns_info["public"]["zone"]}"
  4. validation_method = "DNS"
  5. lifecycle {
  6. create_before_destroy = true
  7. }
  8. provisioner "local-exec" {
  9. # For this purpose, the certificate is frequently not ready by the time
  10. # we attempt to use it. This buys a little time, but is a hack.
  11. command = "sleep 10"
  12. }
  13. tags = merge(local.standard_tags, var.tags)
  14. }
  15. resource "aws_acm_certificate_validation" "cert" {
  16. certificate_arn = aws_acm_certificate.cert.arn
  17. validation_record_fqdns = [for record in aws_route53_record.cert_validation : record.fqdn]
  18. }
  19. resource "aws_route53_record" "cert_validation" {
  20. provider = aws.mdr-common-services-commercial
  21. for_each = {
  22. for dvo in aws_acm_certificate.cert.domain_validation_options : dvo.domain_name => {
  23. name = dvo.resource_record_name
  24. record = dvo.resource_record_value
  25. type = dvo.resource_record_type
  26. }
  27. }
  28. allow_overwrite = true
  29. name = each.value.name
  30. records = [each.value.record]
  31. ttl = 60
  32. type = each.value.type
  33. zone_id = var.dns_info["public"]["zone_id"]
  34. }