-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRoute53.tf
More file actions
69 lines (64 loc) · 2.34 KB
/
Copy pathRoute53.tf
File metadata and controls
69 lines (64 loc) · 2.34 KB
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
locals {
internal_domain_name = var.domain_name != "" ? "internal.hyperspace.${var.environment}.${var.domain_name}" : ""
public_domain_name = var.domain_name != "" ? "hyperspace.${var.environment}.${var.domain_name}" : ""
create_records = var.domain_name != "" ? 1 : 0
# Combine main VPC with additional VPCs for private hosted zone
private_zone_vpc_configs = concat(
# Main VPC (always included, same region as the zone)
[{ vpc_id = local.vpc_id }],
# Additional VPCs from user input (can be cross-region)
[for vpc_config in var.additional_private_zone_vpc_ids : {
vpc_id = vpc_config.vpc_id
vpc_region = vpc_config.vpc_region
}]
)
}
module "external_zone" {
count = local.create_public_zone ? 1 : 0
source = "terraform-aws-modules/route53/aws//modules/zones"
version = "~> 4.1.0"
zones = {
external = {
domain_name = local.public_domain_name
comment = "Public hosted zone for ${local.public_domain_name}"
tags = merge(local.tags, {
Name = local.public_domain_name
Type = "public"
})
}
}
}
module "internal_zone" {
count = local.create_private_zone ? 1 : 0
source = "terraform-aws-modules/route53/aws//modules/zones"
version = "~> 4.1.0"
zones = {
internal = {
domain_name = local.internal_domain_name
comment = "Private hosted zone for ${local.internal_domain_name}"
vpc = local.private_zone_vpc_configs
tags = merge(local.tags, {
Name = local.internal_domain_name
Type = "private"
})
}
}
}
resource "aws_route53_record" "external_wildcard" {
count = var.create_eks && (var.create_public_zone || var.existing_public_zone_id != null) ? 1 : 0
zone_id = local.public_zone_id
name = "*"
type = "CNAME"
ttl = "300"
records = [data.aws_lb.external_ingress[0].dns_name]
depends_on = [helm_release.nginx-ingress, time_sleep.wait_for_external_ingress]
}
resource "aws_route53_record" "internal_wildcard" {
count = var.create_eks && (local.create_private_zone || var.existing_private_zone_id != null) ? 1 : 0
zone_id = local.private_zone_id
name = "*"
type = "CNAME"
ttl = "300"
records = [data.aws_lb.internal_ingress[0].dns_name]
depends_on = [helm_release.nginx-ingress, time_sleep.wait_for_internal_ingress]
}