Skip to content

Commit

Permalink
add is_shared_vpc
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Sep 20, 2024
1 parent d62c3ae commit e15defe
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
locals {
cluster_domain_description = format("%v EKS Cluster DNS Zone", var.cluster_name)
cluster_domain_name = format("%v.%v", var.cluster_name, local.vpc_domain_name)
is_shared_vpc = data.aws_vpc.eks_vpc.owner_id != data.aws_caller_identity.current.account_id
region = var.region
is_shared_vpc = data.aws_vpc.vpc_id.owner_id != data.aws_caller_identity.current.account_id
vpc_domain_name = var.vpc_domain_name
cluster_zone = aws_route53_zone.cluster_domain.zone_id
}

#-------------------------------------------------
Expand All @@ -25,14 +24,14 @@ resource "aws_route53_zone" "cluster_domain" {
force_destroy = false

vpc {
vpc_id = local.is_shared_vpc ? data.aws_vpc.dummy_vpc[0].id : data.aws_vpc.eks_vpc.id
vpc_id = local.is_shared_vpc ? try(data.aws_vpc.dummy_vpc[0].id, null) : data.aws_vpc.eks_vpc.id
vpc_region = local.region
}

lifecycle {
ignore_changes = [vpc]
precondition {
condition = (local.is_shared_vpc && !(var.vpc_domain_name == null || var.vpc_domain_name == ""))
condition = local.is_shared_vpc && !(var.vpc_domain_name == null || var.vpc_domain_name == "")
error_message = "var.vpc_domain_name must be provided when shared VPCs are in use."
}
}
Expand All @@ -48,7 +47,6 @@ resource "aws_route53_zone" "cluster_domain" {
# east region
#---
module "route53_cluster_domain_east" {
depends_on = [aws_route53_zone.cluster_domain]

count = local.region == "us-gov-east-1" && local.is_shared_vpc ? 1 : 0
providers = {
Expand All @@ -59,7 +57,7 @@ module "route53_cluster_domain_east" {
source = "git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//route53-zone-association/zone?ref=tf-upgrade"
region = "us-gov-east-1"
vpc_id = data.aws_vpc.eks_vpc.id
zone_ids = [local.cluster_zone]
zone_ids = [aws_route53_zone.cluster_domain.zone_id]

tags = var.tags
}
Expand All @@ -68,7 +66,6 @@ module "route53_cluster_domain_east" {
# west region
#-------------------------------------------------
module "route53_cluster_domain_west" {
depends_on = [aws_route53_zone.cluster_domain]

count = local.region == "us-gov-west-1" && local.is_shared_vpc ? 1 : 0
providers = {
Expand All @@ -79,7 +76,7 @@ module "route53_cluster_domain_west" {
source = "git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//route53-zone-association/zone?ref=tf-upgrade"
region = "us-gov-west-1"
vpc_id = data.aws_vpc.eks_vpc.id
zone_ids = [local.cluster_zone]
zone_ids = [aws_route53_zone.cluster_domain.zone_id]

tags = var.tags
}

0 comments on commit e15defe

Please sign in to comment.