Skip to content

Commit

Permalink
easier conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
morga471 committed Sep 20, 2024
1 parent b5220b5 commit dfc16a0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
2 changes: 1 addition & 1 deletion aws_data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data "aws_arn" "current" {
# dummy vpc, so we can associate the zone to this account
#---
data "aws_vpc" "dummy_vpc" {
count = !(var.shared_vpc_label == null || var.shared_vpc_label == "") ? 1 : 0
count = local.is_shared_vpc ? 1 : 0
filter {
name = "tag:Name"
values = ["vpc0-dummy"]
Expand Down
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
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.vpc_id.owner_id != data.aws_caller_identity.current.account_id
region = var.region
vpc_domain_name = var.vpc_domain_name
}
Expand All @@ -23,14 +24,14 @@ resource "aws_route53_zone" "cluster_domain" {
force_destroy = false

vpc {
vpc_id = !(var.shared_vpc_label == null || var.shared_vpc_label == "") ? try(data.aws_vpc.dummy_vpc[0].id, null) : 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 = (var.shared_vpc_label == null || var.shared_vpc_label == "") || (!(var.shared_vpc_label == null || var.shared_vpc_label == "") && !(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 Down

0 comments on commit dfc16a0

Please sign in to comment.