forked from cloudposse/terraform-aws-acm-request-certificate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
47 lines (42 loc) · 1.79 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
resource "aws_acm_certificate" "default" {
count = local.enabled ? 1 : 0
domain_name = var.domain_name
validation_method = var.validation_method
subject_alternative_names = var.subject_alternative_names
tags = module.this.tags
lifecycle {
create_before_destroy = true
}
}
locals {
enabled = module.this.enabled
zone_name = var.zone_name == "" && var.zone_id == "" ? "${var.domain_name}." : var.zone_name
process_domain_validation_options = local.enabled && var.process_domain_validation_options && var.validation_method == "DNS"
domain_validation_options_set = local.process_domain_validation_options ? aws_acm_certificate.default.0.domain_validation_options : toset([])
}
data "aws_route53_zone" "default" {
count = local.process_domain_validation_options ? 1 : 0
zone_id = var.zone_id
name = local.zone_name
private_zone = false
}
resource "aws_route53_record" "default" {
for_each = {
for dvo in local.domain_validation_options_set : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
}
zone_id = join("", data.aws_route53_zone.default.*.zone_id)
ttl = var.ttl
allow_overwrite = true
name = each.value.name
type = each.value.type
records = [each.value.record]
}
resource "aws_acm_certificate_validation" "default" {
count = local.process_domain_validation_options && var.wait_for_certificate_issued ? 1 : 0
certificate_arn = join("", aws_acm_certificate.default.*.arn)
validation_record_fqdns = [for record in aws_route53_record.default : record.fqdn]
}