Skip to content

Commit

Permalink
Add a test for when only 1 side has ipv6 addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
Unverified committed May 16, 2024
1 parent 34f13ba commit cf25278
Show file tree
Hide file tree
Showing 10 changed files with 104 additions and 5 deletions.
8 changes: 4 additions & 4 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ 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
route_table_id = local.peer_ipv6_routes[count.index].rts_id
destination_cidr_block = local.peer_ipv6_routes[count.index].dest_ipv6_cidr
vpc_peering_connection_id = aws_vpc_peering_connection.this.id
count = local.create_routes_peer ? 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
73 changes: 73 additions & 0 deletions test/fixtures/single-account-single-region-one-dualstack/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Fixtures
// VPC
resource "aws_vpc" "this" {
cidr_block = "172.20.0.0/16"
assign_generated_ipv6_cidr_block = true

tags = {
Name = "this_vpc"
Environment = "Test"
}
}

resource "aws_vpc" "peer" {
cidr_block = "172.21.0.0/16"
assign_generated_ipv6_cidr_block = false

tags = {
Name = "peer_vpc"
Environment = "Test"
}
}

// Route Tables
resource "aws_route_table" "this" {
count = length(var.azs)

vpc_id = aws_vpc.this.id

tags = {
Name = "This VPC RT"
Environment = "Test"
}
}

resource "aws_route_table" "peer" {
count = length(var.azs)

vpc_id = aws_vpc.peer.id

tags = {
Name = "Peer VPC RT"
Environment = "Test"
}
}

// Subnets
resource "aws_subnet" "this" {
for_each = toset(var.azs)

vpc_id = aws_vpc.this.id
cidr_block = cidrsubnet(aws_vpc.this.cidr_block, 5, index(var.azs, each.value))
// IPV6 Subnet cidr needs to align to /64, aws provides a /56 CIDR automatically
ipv6_cidr_block = cidrsubnet(aws_vpc.this.ipv6_cidr_block, 8, index(var.azs, each.value))
availability_zone = each.value

tags = {
Name = "This VPC Subnet"
Environment = "Test"
}
}

resource "aws_subnet" "peer" {
for_each = toset(var.azs)

vpc_id = aws_vpc.peer.id
cidr_block = cidrsubnet(aws_vpc.peer.cidr_block, 5, index(var.azs, each.value))
availability_zone = each.value

tags = {
Name = "This VPC Subnet"
Environment = "Test"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "this_vpc_id" {
value = aws_vpc.this.id
}

output "peer_vpc_id" {
value = aws_vpc.peer.id
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
provider "aws" {
endpoints {
ec2 = "http://localhost:4566"
s3 = "http://localhost:4566"
sts = "http://localhost:4566"
}
region = "eu-west-1"
access_key = "null"
secret_key = "null"
skip_credentials_validation = true
skip_metadata_api_check = true
skip_requesting_account_id = true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
variable "azs" {
description = "Availability Zones"
type = list(string)
default = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
}
3 changes: 2 additions & 1 deletion test/peering-active_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ func TestPeeringActive(t *testing.T) {
testCases := []TestCase{
{"SingleAccountSingleRegion", "./fixtures/single-account-single-region", "../examples/single-account-single-region"},
{"SingleAccountSingleRegionWithOptions", "./fixtures/single-account-single-region-with-options", "../examples/single-account-single-region-with-options"},
{"SingleAccountSingleRegionOneDualstack", "./fixtures/single-account-single-region-one-dualstack", "../examples/single-account-single-region"},
{"SingleAccountMultiRegion", "./fixtures/single-account-multi-region", "../examples/single-account-multi-region"},
{"MultiAccountSingleRegion", "./fixtures/multi-account-single-region", "../examples/multi-account-single-region"},
{"MultiAccountSingleRegionDualstack", "./fixtures/multi-account-single-region-dualstack", "../examples/multi-account-single-region"},
{"MultiAccountSingleRegionBothDualstack", "./fixtures/multi-account-single-region-both-dualstack", "../examples/multi-account-single-region"},
{"MultiAccountMultiRegion", "./fixtures/multi-account-multi-region", "../examples/multi-account-multi-region"},
// There is a bug with `depends_on` functionality.
//{"ModuleDependsOn", "", "../examples/module-depends-on"},
Expand Down

0 comments on commit cf25278

Please sign in to comment.