Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add use ipv6 as options #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Loading