-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
56 lines (45 loc) · 1.59 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
44
45
46
47
48
49
50
51
52
53
54
55
56
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate
resource "aws_acm_certificate" "main" {
provider = aws.certificate
domain_name = var.domain_name
subject_alternative_names = var.alternate_domain_names
validation_method = "DNS"
tags = var.tags
options {
certificate_transparency_logging_preference = var.enable_certificate_transparency_log ? "ENABLED" : "DISABLED"
}
# see https://developer.hashicorp.com/terraform/language/meta-arguments/lifecycle
lifecycle {
create_before_destroy = true
}
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/route53_record
resource "aws_route53_record" "main" {
for_each = {
for certificate in aws_acm_certificate.main.domain_validation_options : certificate.domain_name => {
name = certificate.resource_record_name
record = certificate.resource_record_value
type = certificate.resource_record_type
}
}
# this is required for Certificate Validation
allow_overwrite = true
name = each.value.name
records = [
each.value.record
]
ttl = 60
type = each.value.type
zone_id = var.route53_zone_id
}
# see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/acm_certificate_validation
resource "aws_acm_certificate_validation" "main" {
provider = aws.certificate
certificate_arn = aws_acm_certificate.main.arn
validation_record_fqdns = [
for record in aws_route53_record.main : record.fqdn
]
timeouts {
create = "60m"
}
}