-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
43 lines (34 loc) · 1.32 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
resource "aws_acm_certificate" "certificate" {
domain_name = local.common_name
subject_alternative_names = [for name in local.names : name if name != local.common_name]
validation_method = "DNS"
lifecycle {
create_before_destroy = true
}
tags = var.tags
}
locals {
names = keys(var.names)
common_name = var.common_name != "" ? var.common_name : local.names[0]
}
resource "aws_route53_record" "validation" {
for_each = {
for record in aws_acm_certificate.certificate.domain_validation_options : record.domain_name => {
name = record.resource_record_name
record = record.resource_record_value
type = record.resource_record_type
zone_id = var.names[record.domain_name]
} if var.names[record.domain_name] != null
}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = each.value.zone_id
}
resource "aws_acm_certificate_validation" "validation" {
count = var.wait_for_validation ? 1 : 0
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = length(var.names) == length([for hosted_zone in var.names : hosted_zone if hosted_zone != null]) ? [for record in aws_route53_record.validation : record.fqdn] : null
}