generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
route53-infrastructure.tf
116 lines (94 loc) · 4.57 KB
/
route53-infrastructure.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
resource "aws_route53_zone" "infrastructure" {
count = local.enable_infrastructure_route53_hosted_zone ? 1 : 0
name = local.infrastructure_route53_domain
}
resource "aws_route53_record" "infrastructure_ns" {
count = local.create_infrastructure_route53_delegations ? 1 : 0
provider = aws.awsroute53root
name = local.infrastructure_route53_domain
ttl = 172800
type = "NS"
zone_id = data.aws_route53_zone.root[0].zone_id
records = [
aws_route53_zone.infrastructure[0].name_servers[0],
aws_route53_zone.infrastructure[0].name_servers[1],
aws_route53_zone.infrastructure[0].name_servers[2],
aws_route53_zone.infrastructure[0].name_servers[3],
]
}
resource "aws_route53_record" "infrastructure_wildcard_ssl_verification" {
for_each = local.enable_infrastructure_wildcard_certificate ? {
for dvo in aws_acm_certificate.infrastructure_wildcard[0].domain_validation_options : dvo.domain_name => {
name = dvo.resource_record_name
record = dvo.resource_record_value
type = dvo.resource_record_type
}
} : {}
allow_overwrite = true
name = each.value.name
records = [each.value.record]
ttl = 60
type = each.value.type
zone_id = aws_route53_zone.infrastructure[0].zone_id
}
resource "aws_route53_record" "service_loadbalancer_record_alb" {
count = length(local.infrastructure_ecs_cluster_services) > 0 && local.enable_infrastructure_route53_hosted_zone ? 1 : 0
zone_id = aws_route53_zone.infrastructure[0].zone_id
name = "alb.${local.infrastructure_route53_domain}."
type = "A"
alias {
name = aws_alb.infrastructure_ecs_cluster_service[0].dns_name
zone_id = aws_alb.infrastructure_ecs_cluster_service[0].zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "service_loadbalancer_record_alb_global_accelerator_a" {
count = local.infrastructure_ecs_cluster_services_alb_enable_global_accelerator && local.enable_infrastructure_route53_hosted_zone ? 1 : 0
zone_id = aws_route53_zone.infrastructure[0].zone_id
name = "ga.${local.infrastructure_route53_domain}."
type = "A"
alias {
name = aws_globalaccelerator_accelerator.infrastructure_ecs_cluster_service_alb[0].dns_name
zone_id = aws_globalaccelerator_accelerator.infrastructure_ecs_cluster_service_alb[0].hosted_zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "service_record" {
for_each = local.enable_infrastructure_route53_hosted_zone ? {
for k, v in local.infrastructure_ecs_cluster_services : k => v if v["container_port"] != 0
} : {}
zone_id = aws_route53_zone.infrastructure[0].zone_id
name = "${each.key}.${local.infrastructure_route53_domain}."
type = "A"
alias {
name = each.value["enable_cloudfront"] == true ? aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].domain_name : aws_alb.infrastructure_ecs_cluster_service[0].dns_name
zone_id = each.value["enable_cloudfront"] == true ? aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].hosted_zone_id : aws_alb.infrastructure_ecs_cluster_service[0].zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "service_record_ipv6" {
for_each = local.enable_infrastructure_route53_hosted_zone ? {
for k, v in local.infrastructure_ecs_cluster_services : k => v if v["container_port"] != 0 && v["enable_cloudfront"] == true
} : {}
zone_id = aws_route53_zone.infrastructure[0].zone_id
name = "${each.key}.${local.infrastructure_route53_domain}."
type = "AAAA"
alias {
name = aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].domain_name
zone_id = aws_cloudfront_distribution.infrastructure_ecs_cluster_service_cloudfront[each.key].hosted_zone_id
evaluate_target_health = true
}
}
resource "aws_route53_record" "custom_s3_cloudfront_record" {
for_each = local.enable_infrastructure_route53_hosted_zone ? {
for k, v in local.custom_s3_buckets : k => v if v["cloudfront_dedicated_distribution"] == true
} : {}
zone_id = aws_route53_zone.infrastructure[0].zone_id
name = "${each.key}-bucket.${local.infrastructure_route53_domain}."
type = "A"
alias {
name = aws_cloudfront_distribution.custom_s3_buckets[each.key].domain_name
zone_id = aws_cloudfront_distribution.custom_s3_buckets[each.key].hosted_zone_id
evaluate_target_health = true
}
}