certificate-elastic.tf 1.3 KB

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