-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.tf
40 lines (29 loc) · 1.29 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
resource "aws_acm_certificate" "this" {
count = var.create_certificate ? 1 : 0
domain_name = var.domain_name
subject_alternative_names = var.subject_alternative_names
validation_method = "DNS"
options {
certificate_transparency_logging_preference = var.certificate_transparency_logging_preference ? "ENABLED" : "DISABLED"
}
tags = var.tags
lifecycle {
create_before_destroy = true
}
}
resource "cloudflare_record" "validation" {
count = var.create_certificate && var.validate_certificate ? length(local.distinct_domain_names) : 0
zone_id = data.cloudflare_zone.this[0].id
name = element(local.validation_domains, count.index)["resource_record_name"]
type = element(local.validation_domains, count.index)["resource_record_type"]
content = replace(element(local.validation_domains, count.index)["resource_record_value"], "/.$/", "")
ttl = var.dns_ttl
proxied = false
allow_overwrite = var.validation_allow_overwrite_records
depends_on = [aws_acm_certificate.this]
}
resource "aws_acm_certificate_validation" "this" {
count = var.create_certificate && var.validate_certificate && var.wait_for_validation ? 1 : 0
certificate_arn = aws_acm_certificate.this[0].arn
validation_record_fqdns = cloudflare_record.validation.*.hostname
}