-
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.
Few enhancements & tests for peering w/ options (#25)
* Few enhancements & tests for peering w/ options * Use test matrix
- Loading branch information
Showing
16 changed files
with
258 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ vendor/ | |
|
||
# Tests directory | ||
.test-data/ | ||
|
||
# Workaround for go test | ||
main.go |
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
30 changes: 30 additions & 0 deletions
30
examples/single-account-single-region-with-options/README.md
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,30 @@ | ||
# Single Account Single Region Peering Connection with Peering Options | ||
|
||
Configuration in this directory creates a peering connection between VPCs in a single region within the same AWS account. It also creates connection options: | ||
|
||
* Cross-VPC DNS resolution option | ||
* Allow classic link access between VPCs | ||
|
||
## Usage | ||
|
||
Modify the variables to suite your purposes. Then 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. | ||
|
||
### Testing notes | ||
|
||
I'm unable to properly test VPC peering options because I need to create public subnets (which contain AWS Internet Gateway) and some resources in Classic. These costs money and I don't want to add it to thr CI. Therefore, tests for this module inplementation simply test that module is able to run and peering is created. | ||
|
||
## 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. |
31 changes: 31 additions & 0 deletions
31
examples/single-account-single-region-with-options/main.tf
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,31 @@ | ||
// Single Account single region example | ||
// Additional options are created | ||
module "single_account_single_region_options" { | ||
source = "../../" | ||
|
||
providers = { | ||
aws.this = "aws" | ||
aws.peer = "aws" | ||
} | ||
|
||
this_vpc_id = "${var.this_vpc_id}" | ||
peer_vpc_id = "${var.peer_vpc_id}" | ||
|
||
create_peering = true | ||
auto_accept_peering = true | ||
|
||
// Peering options for requester | ||
this_dns_resolution = true | ||
this_link_to_peer_classic = true | ||
this_link_to_local_classic = true | ||
|
||
// Peering options for accepter | ||
peer_dns_resolution = true | ||
peer_link_to_peer_classic = true | ||
peer_link_to_local_classic = true | ||
|
||
tags = { | ||
Name = "tf-single-account-single-region-with-options" | ||
Environment = "Test" | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
examples/single-account-single-region-with-options/outputs.tf
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,12 @@ | ||
// Required for tests | ||
output "vpc_peering_accept_status" { | ||
value = "${module.single_account_single_region_options.vpc_peering_accept_status}" | ||
} | ||
|
||
output "accepter_options" { | ||
value = "${module.single_account_single_region_options.accepter_options}" | ||
} | ||
|
||
output "requester_options" { | ||
value = "${module.single_account_single_region_options.requester_options}" | ||
} |
3 changes: 3 additions & 0 deletions
3
examples/single-account-single-region-with-options/provider.tf
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,3 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} |
5 changes: 5 additions & 0 deletions
5
examples/single-account-single-region-with-options/variables.tf
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
# Simple Peering | ||
# Single Account Single Region VPC Peering | ||
|
||
Configuration in this directory creates a simple peering connection between VPCs in a single region within the same AWS account. | ||
This is a basic configuration example, which creates a peering connection between VPCs in a single region within the same AWS account. | ||
|
||
## Usage | ||
|
||
To run this example you need to execute | ||
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. | ||
|
||
## TODO: | ||
* Create VPCs and route tables using this example. For now you can use for example [this module](https://github.com/terraform-aws-modules/terraform-aws-vpc/) to seyup prerequisites. |
71 changes: 71 additions & 0 deletions
71
test/fixtures/single-account-single-region-with-options/main.tf
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 | ||
// VPCs | ||
resource "aws_vpc" "this" { | ||
cidr_block = "172.20.0.0/16" | ||
enable_classiclink = true | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
|
||
tags = { | ||
Name = "this_vpc_options" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_vpc" "peer" { | ||
cidr_block = "172.21.0.0/16" | ||
enable_classiclink = true | ||
enable_dns_support = true | ||
enable_dns_hostnames = true | ||
|
||
tags = { | ||
Name = "peer_vpc_options" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
// Route Tables | ||
resource "aws_route_table" "this" { | ||
count = "${length(var.this_subnets)}" | ||
vpc_id = "${aws_vpc.this.id}" | ||
|
||
tags = { | ||
Name = "This VPC RT" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_route_table" "peer" { | ||
count = "${length(var.peer_subnets)}" | ||
vpc_id = "${aws_vpc.peer.id}" | ||
|
||
tags = { | ||
Name = "Peer VPC RT" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
// Subnets | ||
resource "aws_subnet" "this" { | ||
count = "${length(var.this_subnets)}" | ||
vpc_id = "${aws_vpc.this.id}" | ||
cidr_block = "${var.this_subnets[count.index]}" | ||
availability_zone = "${element(var.azs, count.index)}" | ||
|
||
tags = { | ||
Name = "This VPC Subnet" | ||
Environment = "Test" | ||
} | ||
} | ||
|
||
resource "aws_subnet" "peer" { | ||
count = "${length(var.peer_subnets)}" | ||
vpc_id = "${aws_vpc.peer.id}" | ||
cidr_block = "${var.peer_subnets[count.index]}" | ||
availability_zone = "${element(var.azs, count.index)}" | ||
|
||
tags = { | ||
Name = "This VPC Subnet" | ||
Environment = "Test" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
test/fixtures/single-account-single-region-with-options/outputs.tf
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}" | ||
} |
3 changes: 3 additions & 0 deletions
3
test/fixtures/single-account-single-region-with-options/provider.tf
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,3 @@ | ||
provider "aws" { | ||
region = "us-east-1" | ||
} |
1 change: 1 addition & 0 deletions
1
test/fixtures/single-account-single-region-with-options/terraform.tfvars
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 @@ | ||
azs = ["us-east-1a", "us-east-1b", "us-east-1c"] |
17 changes: 17 additions & 0 deletions
17
test/fixtures/single-account-single-region-with-options/variables.tf
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 @@ | ||
// 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" { | ||
description = "Availability Zones" | ||
type = "list" | ||
} |
18 changes: 0 additions & 18 deletions
18
.../single-account-single-region/fixtures.tf → ...ures/single-account-single-region/main.tf
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 @@ | ||
// 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" { | ||
description = "Availability Zones" | ||
type = "list" | ||
} |
Oops, something went wrong.