-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
73 lines (58 loc) · 2.13 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
resource "aws_acm_certificate" "certificate" {
domain_name = var.fqdn
validation_method = "DNS"
tags = var.tags
lifecycle {
create_before_destroy = true
}
}
data "aws_route53_zone" "zone_core_vpc" {
count = var.is-production ? 0 : 1
provider = aws.core-vpc
name = var.fqdn
private_zone = false
}
data "aws_route53_zone" "core_network_zone" {
count = var.is-production ? 1 : 0
provider = aws.core-network-services
name = var.fqdn
private_zone = false
}
locals {
domain_validation_records = {
for dvo in aws_acm_certificate.certificate.domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
}
}
}
resource "aws_route53_record" "dns_validation_record_core_vpc" {
provider = aws.core-vpc
depends_on = [aws_acm_certificate.certificate]
ttl = 300
type = "CNAME"
for_each = var.is-production ? {} : local.domain_validation_records
zone_id = var.is-production ? null : data.aws_route53_zone.zone_core_vpc[0].zone_id
name = each.value.name
records = [each.value.record]
}
resource "aws_route53_record" "dns_validation_record_core_network_services" {
provider = aws.core-network-services
depends_on = [aws_acm_certificate.certificate]
ttl = 300
type = "CNAME"
for_each = var.is-production ? local.domain_validation_records : {}
zone_id = var.is-production ? data.aws_route53_zone.core_network_zone[0].zone_id : null
name = each.value.name
records = [each.value.record]
}
resource "aws_acm_certificate_validation" "prod" {
count = var.is-production ? 1 : 0
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = [for record in aws_route53_record.dns_validation_record_core_network_services : record.fqdn]
}
resource "aws_acm_certificate_validation" "non_prod" {
count = var.is-production ? 0 : 1
certificate_arn = aws_acm_certificate.certificate.arn
validation_record_fqdns = [for record in aws_route53_record.dns_validation_record_core_vpc : record.fqdn]
}