-
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.
Single account multi region peering (#26)
* Create fixtures for cross-region * Rename the test * Fix few fixtures issues * Fix cross-region peering * Update CHANGELOG * Update CHANGELOG * Rename the test
- Loading branch information
Showing
16 changed files
with
287 additions
and
7 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,49 @@ | ||
# Single Account Multi Region VPC Peering | ||
|
||
This example creates a peering connection between VPCs in different regions, which are located in the same AWS account. | ||
|
||
## Sample Code | ||
|
||
``` | ||
module "single_account_multi_region" { | ||
source = "../../" | ||
providers = { | ||
aws.this = "aws.us-east-1" | ||
aws.peer = "aws.us-west-1" | ||
} | ||
this_vpc_id = "${var.this_vpc_id}" | ||
peer_vpc_id = "${var.peer_vpc_id}" | ||
peer_region = "us-west-1" | ||
create_peering = true | ||
auto_accept_peering = true | ||
tags = { | ||
Name = "tf-single-account-multi-region" | ||
Environment = "Test" | ||
} | ||
} | ||
``` | ||
|
||
## Usage | ||
|
||
Change the variables to fit your purposes and run: | ||
|
||
```bash | ||
terraform init | ||
terraform plan | ||
terraform apply | ||
``` | ||
|
||
## Testing | ||
|
||
This configuration is tested with [Terratest](https://github.com/gruntwork-io/terratest). | ||
|
||
You can find tests in [`test/`](../../test) directory. | ||
|
||
## Note | ||
|
||
Running the resources in AWS may cost money! Make sure to clean up afterwards. You can use `terraform destroy` to delete the resources spawned by this example. |
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,22 @@ | ||
// Creates a peering between VPCs in the same account, but different regions | ||
module "single_account_multi_region" { | ||
source = "../../" | ||
|
||
providers = { | ||
aws.this = "aws.us-east-1" | ||
aws.peer = "aws.us-west-1" | ||
} | ||
|
||
this_vpc_id = "${var.this_vpc_id}" | ||
peer_vpc_id = "${var.peer_vpc_id}" | ||
|
||
peer_region = "us-west-1" | ||
|
||
create_peering = true | ||
auto_accept_peering = true | ||
|
||
tags = { | ||
Name = "tf-single-account-multi-region" | ||
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,4 @@ | ||
// Required for tests | ||
output "vpc_peering_accept_status" { | ||
value = "${module.single_account_multi_region.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,9 @@ | ||
provider "aws" { | ||
alias = "us-east-1" | ||
region = "us-east-1" | ||
} | ||
|
||
provider "aws" { | ||
alias = "us-west-1" | ||
region = "us-west-1" | ||
} |
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,5 @@ | ||
// Variables are required to pass them via Terratest | ||
// on fixtures creation | ||
variable "this_vpc_id" {} | ||
|
||
variable "peer_vpc_id" {} |
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
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,71 @@ | ||
// Fixtures | ||
// VPC | ||
resource "aws_vpc" "this" { | ||
provider = "aws.us-east-1" | ||
cidr_block = "172.20.0.0/16" | ||
|
||
tags = { | ||
Name = "this_vpc" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_vpc" "peer" { | ||
provider = "aws.us-west-1" | ||
cidr_block = "172.21.0.0/16" | ||
|
||
tags = { | ||
Name = "peer_vpc" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
// Route Tables | ||
resource "aws_route_table" "this" { | ||
provider = "aws.us-east-1" | ||
count = "${length(var.this_subnets)}" | ||
vpc_id = "${aws_vpc.this.id}" | ||
|
||
tags = { | ||
Name = "This VPC RT" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "peer" { | ||
provider = "aws.us-west-1" | ||
count = "${length(var.peer_subnets)}" | ||
vpc_id = "${aws_vpc.peer.id}" | ||
|
||
tags = { | ||
Name = "Peer VPC RT" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
// Subnets | ||
resource "aws_subnet" "this" { | ||
provider = "aws.us-east-1" | ||
count = "${length(var.azs_this)}" | ||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.this_subnets[count.index]}" | ||
availability_zone = "${element(var.azs_this, count.index)}" | ||
|
||
tags = { | ||
Name = "This VPC Subnet" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "peer" { | ||
provider = "aws.us-west-1" | ||
count = "${length(var.azs_peer)}" | ||
vpc_id = "${aws_vpc.peer.id}" | ||
cidr_block = "${var.peer_subnets[count.index]}" | ||
availability_zone = "${element(var.azs_peer, count.index)}" | ||
|
||
tags = { | ||
Name = "This VPC Subnet" | ||
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,7 @@ | ||
output "this_vpc_id" { | ||
value = "${aws_vpc.this.id}" | ||
} | ||
|
||
output "peer_vpc_id" { | ||
value = "${aws_vpc.peer.id}" | ||
} |
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,9 @@ | ||
provider "aws" { | ||
alias = "us-east-1" | ||
region = "us-east-1" | ||
} | ||
|
||
provider "aws" { | ||
alias = "us-west-1" | ||
region = "us-west-1" | ||
} |
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,24 @@ | ||
// Variables | ||
variable "this_subnets" { | ||
description = "Subnet list for _this_ VPC" | ||
type = "list" | ||
default = ["172.20.0.0/24", "172.20.1.0/24", "172.20.2.0/24"] | ||
} | ||
|
||
variable "peer_subnets" { | ||
description = "Subnet list for _peer_ VPC" | ||
type = "list" | ||
default = ["172.21.0.0/24", "172.21.1.0/24", "172.21.2.0/24"] | ||
} | ||
|
||
variable "azs_this" { | ||
description = "Availability Zones for requester VPC" | ||
type = "list" | ||
default = ["us-east-1a", "us-east-1b", "us-east-1c"] | ||
} | ||
|
||
variable "azs_peer" { | ||
description = "Availability Zones for accepter VPC" | ||
type = "list" | ||
default = ["us-west-1a", "us-west-1c"] | ||
} |
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