Skip to content

Commit

Permalink
Fix terraform init
Browse files Browse the repository at this point in the history
  • Loading branch information
mgledi committed Nov 29, 2023
1 parent 0d16298 commit be9bfca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 4 additions & 2 deletions modules/tgw/spoke/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

locals {
spoke_account = module.this.tenant != null ? format("%s-%s-%s", module.this.tenant, module.this.environment, module.this.stage) : format("%s-%s", module.this.environment, module.this.stage)
// "When default routing via transit gateway is enabled, both nat gateway and nat instance must be disabled"
enabled = local.enabled ? (length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 ? true : false) : true
}

module "tgw_hub_routes" {
Expand Down Expand Up @@ -53,7 +55,7 @@ module "tgw_spoke_vpc_attachment" {
}

resource "aws_route" "default_route" {
count = length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 && var.default_route_enabled ? length(module.vpc.outputs.private_route_table_ids) : 0
count = length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 && local.enabled ? length(module.vpc.outputs.private_route_table_ids) : 0

route_table_id = module.vpc.outputs.private_route_table_ids[count.index]
destination_cidr_block = "0.0.0.0/0"
Expand All @@ -68,7 +70,7 @@ locals {
resource "aws_route" "back_route" {
provider = aws.tgw-hub

count = length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 && var.default_route_enabled ? length(local.default_route_vpc_public_route_table_ids) : 0
count = length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 && local.enabled ? length(local.default_route_vpc_public_route_table_ids) : 0

route_table_id = local.default_route_vpc_public_route_table_ids[count.index]
destination_cidr_block = module.vpc.outputs.vpc_cidr
Expand Down
4 changes: 0 additions & 4 deletions modules/tgw/spoke/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ variable "default_route_enabled" {
type = bool
description = "Enable default routing via transit gateway, requires also nat gateway and instance to be disabled in vpc component. Default is disabled."
default = false
validation {
condition = var.default_route_enabled ? (length(module.vpc.outputs.nat_gateway_ids) == 0 && length(module.vpc.outputs.nat_instance_ids) == 0 ? true : false) : true
error_message = "When default routing via transit gateway is enabled, both nat gateway and nat instance must be disabled"
}
}

variable "default_route_outgoing_account_name" {
Expand Down

0 comments on commit be9bfca

Please sign in to comment.