-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from vivgoyal-aws/main
Fix: support private only subnets (nat_gateway_configuration == "none" / null)
- Loading branch information
Showing
7 changed files
with
203 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
) | ||
|
||
|
||
func TestExamplesNATGWRoutesNoNATGWNoRoute(t *testing.T) { | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/nat_gw_routes", | ||
Vars: map[string]interface{}{ | ||
"nat_gateway_configuration" : "none", | ||
"route_to_nw" : false, | ||
}, | ||
} | ||
|
||
defer terraform.Destroy(t, terraformOptions) | ||
terraform.InitAndApply(t, terraformOptions) | ||
terraform.ApplyAndIdempotent(t, terraformOptions) | ||
} | ||
|
||
func TestExamplesNATGWRoutesSingleAZNATGWNoRoute(t *testing.T) { | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/nat_gw_routes", | ||
Vars: map[string]interface{}{ | ||
"nat_gateway_configuration" : "single_az", | ||
"route_to_nw" : false, | ||
}, | ||
} | ||
|
||
defer terraform.Destroy(t, terraformOptions) | ||
terraform.InitAndApply(t, terraformOptions) | ||
terraform.ApplyAndIdempotent(t, terraformOptions) | ||
} | ||
|
||
func TestExamplesNATGWRoutesAllAZsNATGWNoRoute(t *testing.T) { | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/nat_gw_routes", | ||
Vars: map[string]interface{}{ | ||
"nat_gateway_configuration" : "all_azs", | ||
"route_to_nw" : false, | ||
}, | ||
} | ||
|
||
defer terraform.Destroy(t, terraformOptions) | ||
terraform.InitAndApply(t, terraformOptions) | ||
terraform.ApplyAndIdempotent(t, terraformOptions) | ||
} | ||
|
||
func TestExamplesNATGWRoutesSingleAZNATGWWithRoute(t *testing.T) { | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/nat_gw_routes", | ||
Vars: map[string]interface{}{ | ||
"nat_gateway_configuration" : "single_az", | ||
"route_to_nw" : true, | ||
}, | ||
} | ||
|
||
defer terraform.Destroy(t, terraformOptions) | ||
terraform.InitAndApply(t, terraformOptions) | ||
terraform.ApplyAndIdempotent(t, terraformOptions) | ||
} | ||
|
||
func TestExamplesNATGWRoutesAllAZsNATGWWithRoute(t *testing.T) { | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/nat_gw_routes", | ||
Vars: map[string]interface{}{ | ||
"nat_gateway_configuration" : "all_azs", | ||
"route_to_nw" : true, | ||
}, | ||
} | ||
|
||
defer terraform.Destroy(t, terraformOptions) | ||
terraform.InitAndApply(t, terraformOptions) | ||
terraform.ApplyAndIdempotent(t, terraformOptions) | ||
} |
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 @@ | ||
# NAT Gateway Options | ||
|
||
This example builds a VPC with public and private subnets in 2 availability zones. | ||
It creates NAT GW in public subnet with either "none", "single_az" or "all_azs" option. | ||
It creates routes from private subnets to NAT GW if `connect_to_public_natgw` is true otherwise no route is created. | ||
It creates an internet gateway and appropriately routes subnet traffic from "0.0.0.0/0" to the IGW. |
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,35 @@ | ||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
No requirements. | ||
|
||
## Providers | ||
|
||
No providers. | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_nat_gw_vpc"></a> [nat\_gw\_vpc](#module\_nat\_gw\_vpc) | ../.. | n/a | | ||
|
||
## Resources | ||
|
||
No resources. | ||
|
||
## Inputs | ||
|
||
| Name | Description | Type | Default | Required | | ||
|------|-------------|------|---------|:--------:| | ||
| <a name="input_nat_gateway_configuration"></a> [nat\_gateway\_configuration](#input\_nat\_gateway\_configuration) | all\_azs, single\_az, or none | `string` | n/a | yes | | ||
| <a name="input_route_to_nw"></a> [route\_to\_nw](#input\_route\_to\_nw) | Should route to NATGW be created? | `bool` | n/a | yes | | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_nat_gateway_attributes_by_az"></a> [nat\_gateway\_attributes\_by\_az](#output\_nat\_gateway\_attributes\_by\_az) | Map of nat gateway resource attributes by AZ. | | ||
| <a name="output_private_subnet_attributes_by_az"></a> [private\_subnet\_attributes\_by\_az](#output\_private\_subnet\_attributes\_by\_az) | Map of all private subnets containing their attributes. | | ||
| <a name="output_public_subnet_attributes_by_az"></a> [public\_subnet\_attributes\_by\_az](#output\_public\_subnet\_attributes\_by\_az) | Map of all public subnets containing their attributes. | | ||
| <a name="output_rt_attributes_by_type_by_az"></a> [rt\_attributes\_by\_type\_by\_az](#output\_rt\_attributes\_by\_type\_by\_az) | Map of route tables by type => az => route table attributes. | | ||
<!-- END_TF_DOCS --> |
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,42 @@ | ||
module "nat_gw_vpc" { | ||
source = "../../.." | ||
|
||
name = "nat-gw-options-vpc" | ||
cidr_block = "10.51.0.0/16" | ||
az_count = 2 | ||
|
||
subnets = { | ||
|
||
public = { | ||
name_prefix = "public" # omit to prefix with "public" | ||
netmask = 24 | ||
nat_gateway_configuration = var.nat_gateway_configuration | ||
tags = { | ||
"tier" = "web" | ||
} | ||
} | ||
|
||
app = { | ||
name_prefix = "app" | ||
netmask = 24 | ||
connect_to_public_natgw = var.route_to_nw | ||
tags = { | ||
"tier" = "app" | ||
} | ||
} | ||
|
||
db = { | ||
name_prefix = "db" | ||
netmask = 24 | ||
connect_to_public_natgw = var.route_to_nw | ||
tags = { | ||
"tier" = "database" | ||
} | ||
} | ||
|
||
} | ||
|
||
tags = { | ||
"app" = "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,21 @@ | ||
output "private_subnet_attributes_by_az" { | ||
description = "Map of all private subnets containing their attributes." | ||
value = module.nat_gw_vpc.private_subnet_attributes_by_az | ||
|
||
} | ||
|
||
output "public_subnet_attributes_by_az" { | ||
description = "Map of all public subnets containing their attributes." | ||
value = module.nat_gw_vpc.public_subnet_attributes_by_az | ||
|
||
} | ||
|
||
output "rt_attributes_by_type_by_az" { | ||
description = "Map of route tables by type => az => route table attributes." | ||
value = module.nat_gw_vpc.rt_attributes_by_type_by_az | ||
} | ||
|
||
output "nat_gateway_attributes_by_az" { | ||
description = "Map of nat gateway resource attributes by AZ." | ||
value = module.nat_gw_vpc.nat_gateway_attributes_by_az | ||
} |
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 @@ | ||
variable "nat_gateway_configuration" { | ||
description = "all_azs, single_az, or none" | ||
type = string | ||
} | ||
|
||
variable "route_to_nw" { | ||
description = "Should route to NATGW be created?" | ||
type = bool | ||
} |