diff --git a/locals.tf b/locals.tf index 852515e..2598d40 100644 --- a/locals.tf +++ b/locals.tf @@ -35,9 +35,9 @@ locals { # `peer_dest_cidrs` represent CIDR of this VPC, therefore a destination CIDR for peer_vpc # Destination cidrs for this are in peer and vice versa this_dest_ipv4_cidrs = toset(compact(length(var.peer_subnets_ids) == 0 ? [data.aws_vpc.peer_vpc.cidr_block] : data.aws_subnet.peer[*].cidr_block)) - this_dest_ipv6_cidrs = toset(compact(length(var.peer_subnets_ids) == 0 ? [data.aws_vpc.peer_vpc.ipv6_cidr_block] : data.aws_subnet.peer[*].ipv6_cidr_block)) + this_dest_ipv6_cidrs = toset(compact(length(var.peer_subnets_ids) == 0 && var.use_ipv6 ? [data.aws_vpc.peer_vpc.ipv6_cidr_block] : data.aws_subnet.peer[*].ipv6_cidr_block)) peer_dest_ipv4_cidrs = toset(compact(length(var.this_subnets_ids) == 0 ? [data.aws_vpc.this_vpc.cidr_block] : data.aws_subnet.this[*].cidr_block)) - peer_dest_ipv6_cidrs = toset(compact(length(var.this_subnets_ids) == 0 ? [data.aws_vpc.this_vpc.ipv6_cidr_block] : data.aws_subnet.this[*].ipv6_cidr_block)) + peer_dest_ipv6_cidrs = toset(compact(length(var.this_subnets_ids) == 0 && var.use_ipv6 ? [data.aws_vpc.this_vpc.ipv6_cidr_block] : data.aws_subnet.this[*].ipv6_cidr_block)) # Get associated CIDR blocks this_associated_dest_cidrs = toset(compact([for k, v in data.aws_vpc.peer_vpc.cidr_block_associations : v.cidr_block])) @@ -94,7 +94,9 @@ locals { create_associated_routes_this = var.from_this && var.from_this_associated create_associated_routes_peer = var.from_peer && var.from_peer_associated create_routes_this = var.from_this && !local.create_associated_routes_this + create_routes_this_ipv6 = var.from_this && !local.create_associated_routes_this && var.use_ipv6 create_routes_peer = var.from_peer && !local.create_associated_routes_peer + create_routes_peer_ipv6 = var.from_peer && !local.create_associated_routes_peer && var.use_ipv6 # Build tags requester_tags = var.name == "" ? merge( diff --git a/main.tf b/main.tf index 9bce2e1..6815807 100644 --- a/main.tf +++ b/main.tf @@ -61,7 +61,7 @@ resource "aws_route" "this_routes" { resource "aws_route" "this_ipv6_routes" { provider = aws.this # Only create routes for this route table if input dictates it, and in that case, for all combinations - count = local.create_routes_this ? length(local.this_ipv6_routes) : 0 + count = local.create_routes_this_ipv6 ? length(local.this_ipv6_routes) : 0 route_table_id = local.this_ipv6_routes[count.index].rts_id destination_ipv6_cidr_block = local.this_ipv6_routes[count.index].dest_ipv6_cidr vpc_peering_connection_id = aws_vpc_peering_connection.this.id @@ -94,7 +94,7 @@ resource "aws_route" "peer_routes" { resource "aws_route" "peer_ipv6_routes" { provider = aws.peer # Only create routes for peer route table if input dictates it, and in that case, for all combinations - count = local.create_routes_peer ? length(local.peer_ipv6_routes) : 0 + count = local.create_routes_peer_ipv6 ? length(local.peer_ipv6_routes) : 0 route_table_id = local.peer_ipv6_routes[count.index].rts_id destination_ipv6_cidr_block = local.peer_ipv6_routes[count.index].dest_ipv6_cidr vpc_peering_connection_id = aws_vpc_peering_connection.this.id diff --git a/variables.tf b/variables.tf index ce9a6d8..f28c17b 100644 --- a/variables.tf +++ b/variables.tf @@ -87,3 +87,9 @@ variable "peer_rts_ids" { type = list(string) default = [] } + +variable "use_ipv6" { + description = "If ipv6 should be used" + type = bool + default = true +}