certificate-hec.tf 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #Certificate
  2. resource "aws_acm_certificate" "cert_hec" {
  3. count = local.alsi_hec_alb ? 1 : 0
  4. domain_name = "${var.prefix}-alsi-hec.${var.dns_info["public"]["zone"]}"
  5. validation_method = "DNS"
  6. lifecycle {
  7. create_before_destroy = true
  8. }
  9. tags = merge(local.standard_tags, var.tags)
  10. }
  11. resource "aws_acm_certificate_validation" "cert_hec" {
  12. count = local.alsi_hec_alb ? 1 : 0
  13. certificate_arn = aws_acm_certificate.cert_hec[count.index].arn
  14. validation_record_fqdns = [for record in aws_route53_record.cert_hec_validation : record.fqdn]
  15. }
  16. resource "aws_route53_record" "cert_hec_validation" {
  17. provider = aws.mdr-common-services-commercial
  18. # This syntax is tricky. If the bool is true, then we create the for_each map, otherwise we do an empty map.
  19. for_each = local.alsi_hec_alb ? {
  20. for dvo in aws_acm_certificate.cert_hec[0].domain_validation_options : dvo.domain_name => {
  21. name = dvo.resource_record_name
  22. record = dvo.resource_record_value
  23. type = dvo.resource_record_type
  24. }
  25. } : {}
  26. allow_overwrite = true
  27. name = each.value.name
  28. records = [each.value.record]
  29. ttl = 60
  30. type = each.value.type
  31. zone_id = var.dns_info["public"]["zone_id"]
  32. }