/
base.tf
115 lines (87 loc) · 2.99 KB
/
base.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
locals {
// Because of the issue https://github.com/hashicorp/terraform/issues/12570, the consumers cannot count 0/1
// based on if api_external_lb_dns_name for example, which will be null when there is no external lb for API.
// So publish_strategy serves an coordinated proxy for that decision.
public_endpoints = var.publish_strategy == "External" ? true : false
use_cname = contains(["us-gov-west-1", "us-gov-east-1", "us-iso-east-1"], var.region)
use_alias = ! local.use_cname
}
data "aws_route53_zone" "public" {
count = local.public_endpoints ? 1 : 0
name = var.base_domain
depends_on = [aws_route53_record.api_external_internal_zone_alias, aws_route53_record.api_external_internal_zone_cname]
}
data "aws_route53_zone" "int" {
zone_id = var.internal_zone == null ? aws_route53_zone.new_int[0].id : var.internal_zone
}
resource "aws_route53_zone" "new_int" {
count = var.internal_zone == null ? 1 : 0
name = var.cluster_domain
force_destroy = true
vpc {
vpc_id = var.vpc_id
}
tags = merge(
{
"Name" = "${var.cluster_id}-int"
},
var.tags,
)
}
resource "aws_route53_record" "api_external_alias" {
count = local.use_alias && local.public_endpoints ? 1 : 0
zone_id = data.aws_route53_zone.public[0].zone_id
name = "api.${var.cluster_domain}"
type = "A"
alias {
name = var.api_external_lb_dns_name
zone_id = var.api_external_lb_zone_id
evaluate_target_health = false
}
}
resource "aws_route53_record" "api_internal_alias" {
count = local.use_alias ? 1 : 0
zone_id = data.aws_route53_zone.int.zone_id
name = "api-int.${var.cluster_domain}"
type = "A"
alias {
name = var.api_internal_lb_dns_name
zone_id = var.api_internal_lb_zone_id
evaluate_target_health = false
}
}
resource "aws_route53_record" "api_external_internal_zone_alias" {
count = local.use_alias ? 1 : 0
zone_id = data.aws_route53_zone.int.zone_id
name = "api.${var.cluster_domain}"
type = "A"
alias {
name = var.api_internal_lb_dns_name
zone_id = var.api_internal_lb_zone_id
evaluate_target_health = false
}
}
resource "aws_route53_record" "api_external_cname" {
count = local.use_cname && local.public_endpoints ? 1 : 0
zone_id = data.aws_route53_zone.public[0].zone_id
name = "api.${var.cluster_domain}"
type = "CNAME"
ttl = 10
records = [var.api_external_lb_dns_name]
}
resource "aws_route53_record" "api_internal_cname" {
count = local.use_cname ? 1 : 0
zone_id = data.aws_route53_zone.int.zone_id
name = "api-int.${var.cluster_domain}"
type = "CNAME"
ttl = 10
records = [var.api_internal_lb_dns_name]
}
resource "aws_route53_record" "api_external_internal_zone_cname" {
count = local.use_cname ? 1 : 0
zone_id = data.aws_route53_zone.int.zone_id
name = "api.${var.cluster_domain}"
type = "CNAME"
ttl = 10
records = [var.api_internal_lb_dns_name]
}