-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Test fixture for partial-subnets * Update gitignore * Fix unable to find route table bug
- Loading branch information
Showing
13 changed files
with
526 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
/ To make it unit testable, get required parameters from vpcs. | ||
*/ | ||
|
||
# peer vpc main route table | ||
data "aws_route_table" "peer_main_route_table" { | ||
provider = aws.peer | ||
vpc_id = var.peer_vpc_id | ||
filter { | ||
name = "association.main" | ||
values = ["true"] | ||
} | ||
} | ||
|
||
# peer subnets | ||
data "aws_subnets" "peer" { | ||
provider = aws.peer | ||
filter { | ||
name = "vpc-id" | ||
values = [var.peer_vpc_id] | ||
} | ||
} | ||
|
||
# get route tables associated with subnets | ||
data "aws_route_tables" "peer_associated_route_tables" { | ||
for_each = { for subnet in data.aws_subnets.peer.ids: subnet => subnet } | ||
provider = aws.peer | ||
vpc_id = var.peer_vpc_id | ||
filter { | ||
name = "association.subnet-id" | ||
values = [each.key] | ||
} | ||
} | ||
|
||
locals { | ||
peer_subnet_route_table_map = { | ||
for subnet in data.aws_subnets.peer.ids: | ||
subnet => concat( | ||
data.aws_route_tables.peer_associated_route_tables[subnet].ids, | ||
[data.aws_route_table.peer_main_route_table.id] | ||
)[0] | ||
} | ||
peer_subnets_associated_map = { | ||
for subnet, route_table in local.peer_subnet_route_table_map: | ||
subnet => route_table | ||
if route_table != data.aws_route_table.peer_main_route_table.id | ||
} | ||
|
||
peer_subnets_unassociated_map = { | ||
for subnet, route_table in local.peer_subnet_route_table_map: | ||
subnet => route_table | ||
if route_table == data.aws_route_table.peer_main_route_table.id | ||
} | ||
peer_subnet_ids = distinct(concat( | ||
try(slice(keys(local.peer_subnets_associated_map), 0, 1), []), | ||
try(slice(keys(local.peer_subnets_unassociated_map),0, 1), []), | ||
)) | ||
# actually, peer route tables should be detected from peer subnets if specified | ||
peer_route_tables = distinct([ for subnet in local.peer_subnet_ids: local.peer_subnet_route_table_map[subnet] ]) | ||
} | ||
|
||
|
||
|
||
|
||
module "partial_subnets" { | ||
|
||
source = "../../" | ||
#version = "6.0.0" | ||
|
||
providers = { | ||
aws.this = aws.this | ||
aws.peer = aws.peer | ||
} | ||
|
||
this_vpc_id = var.this_vpc_id | ||
peer_vpc_id = var.peer_vpc_id | ||
|
||
auto_accept_peering = true | ||
peer_dns_resolution = true | ||
this_dns_resolution = true | ||
peer_subnets_ids = length(var.peer_subnets_ids) > 0 ? var.peer_subnets_ids : local.peer_subnet_ids | ||
this_subnets_ids = var.this_subnets_ids | ||
this_rts_ids = var.this_rts_ids | ||
peer_rts_ids = length(var.peer_rts_ids)>0 ? var.peer_rts_ids : local.peer_route_tables | ||
|
||
tags = { | ||
Name = "tf-partial-subnets" | ||
Environment = "Test" | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Required for tests | ||
|
||
output "vpc_peering_accept_status" { | ||
value = module.partial_subnets.vpc_peering_accept_status | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
provider "aws" { | ||
alias = "this" | ||
region = var.this_region != "" ? var.this_region : "eu-west-2" | ||
assume_role { | ||
role_arn = var.this_assume_role_arn != "" ? var.this_assume_role_arn : null | ||
} | ||
access_key = var.aws_this_access_key != "" ? var.aws_this_access_key : null | ||
secret_key = var.aws_this_secret_key != "" ? var.aws_this_secret_key : null | ||
} | ||
|
||
provider "aws" { | ||
alias = "peer" | ||
region = var.peer_region != "" ? var.peer_region : "eu-central-1" | ||
assume_role { | ||
role_arn = var.peer_assume_role_arn != "" ? var.peer_assume_role_arn : null | ||
} | ||
access_key = var.aws_peer_access_key != "" ? var.aws_peer_access_key : null | ||
secret_key = var.aws_peer_secret_key != "" ? var.aws_peer_secret_key : null | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
variable this_assume_role_arn { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable peer_assume_role_arn { | ||
type = string | ||
default = "" | ||
} | ||
|
||
variable "aws_this_access_key" { | ||
description = "AWS Access Key for requester account" | ||
default = "" | ||
} | ||
|
||
variable "aws_this_secret_key" { | ||
description = "AWS Secret Key for requester account" | ||
default = "" | ||
} | ||
|
||
variable "aws_peer_access_key" { | ||
description = "AWS Access Key for accepter account" | ||
default = "" | ||
} | ||
|
||
variable "aws_peer_secret_key" { | ||
description = "AWS Secret Key for accepter account" | ||
default = "" | ||
} | ||
|
||
|
||
variable this_region { | ||
type = string | ||
default = "eu-central-1" | ||
} | ||
|
||
variable peer_region { | ||
type = string | ||
default = "eu-central-1" | ||
} | ||
|
||
variable this_vpc_id { | ||
type = string | ||
} | ||
|
||
variable peer_vpc_id { | ||
type = string | ||
} | ||
|
||
variable "auto_accept_peering" { | ||
description = "Auto accept peering connection: bool" | ||
type = bool | ||
default = false | ||
} | ||
|
||
variable "tags" { | ||
description = "Tags: map" | ||
type = map(string) | ||
default = {} | ||
} | ||
|
||
variable "peer_subnets_ids" { | ||
description = "If communication can only go to some specific subnets of peer vpc. If empty whole vpc cidr is allowed" | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "this_subnets_ids" { | ||
description = "If communication can only go to some specific subnets of this vpc. If empty whole vpc cidr is allowed" | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "this_rts_ids" { | ||
description = "Allows to explicitly specify route tables for this VPC" | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
variable "peer_rts_ids" { | ||
description = "Allows to explicitly specify route tables for peer VPC" | ||
type = list(string) | ||
default = [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
data "aws_route_table" "peer_main_route_table" { | ||
provider = aws.peer | ||
vpc_id = aws_vpc.peer.id | ||
filter { | ||
name = "association.main" | ||
values = ["true"] | ||
} | ||
} | ||
|
||
data "aws_route_table" "this_main_route_table" { | ||
provider = aws.this | ||
vpc_id = aws_vpc.this.id | ||
filter { | ||
name = "association.main" | ||
values = ["true"] | ||
} | ||
} |
Oops, something went wrong.