-
Notifications
You must be signed in to change notification settings - Fork 106
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 #81 from aws-ia/f-secondarycidr-nat
Feature allow `connect_to_natgw` for secondary invocations
- Loading branch information
Showing
13 changed files
with
155 additions
and
45 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
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,35 +1,31 @@ | ||
# To test this example, uncomment the module blocks for "vpc" and "ipam_base_for_example_only" | ||
data "aws_region" "current" {} | ||
|
||
module "secondary" { | ||
source = "aws-ia/vpc/aws" | ||
version = ">= 2.0.0" | ||
|
||
name = "secondary-cidr" | ||
|
||
vpc_secondary_cidr = true | ||
vpc_id = module.vpc.vpc.id | ||
vpc_ipv4_ipam_pool_id = module.ipam_base_for_example_only.pool_id | ||
vpc_ipv4_netmask_length = 20 | ||
az_count = 2 | ||
|
||
name = "secondary-cidr" | ||
az_count = 2 | ||
cidr_block = "10.2.0.0/16" | ||
|
||
vpc_secondary_cidr = true | ||
vpc_id = var.vpc_id | ||
|
||
# If referencing another instantiation of this module, you can use the output nat_gateway_attributes_by_az, example: | ||
# vpc_secondary_cidr_natgw = module.vpc.nat_gateway_attributes_by_az | ||
vpc_secondary_cidr_natgw = { | ||
"${data.aws_region.current.name}a" : { | ||
id : var.natgw_id_1 | ||
} | ||
"${data.aws_region.current.name}b" : { | ||
id : var.natgw_id_2 | ||
} | ||
} | ||
subnets = { | ||
private = { netmask = 24 } | ||
private = { | ||
name_prefix = "secondary-private-natgw-connected" | ||
netmask = 18 | ||
connect_to_public_natgw = true | ||
} | ||
} | ||
} | ||
|
||
# module "ipam_base_for_example_only" { | ||
# source = "../../test/hcl_fixtures/ipam_base" | ||
# } | ||
|
||
# module "vpc" { | ||
# source = "aws-ia/vpc/aws" | ||
# version = ">= 1.0.0" | ||
|
||
# name = "multi-az-vpc" | ||
# cidr_block = "10.0.0.0/16" | ||
# az_count = 3 | ||
|
||
# subnets = { | ||
# private = { netmask = 24 } | ||
# } | ||
# } |
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,9 +0,0 @@ | ||
output "public_subnets" { | ||
description = "Map of public subnet attributes grouped by az." | ||
value = module.secondary.public_subnet_cidrs_by_az | ||
} | ||
|
||
output "private_subnets" { | ||
description = "Map of private subnet attributes grouped by az." | ||
value = module.secondary.private_subnet_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,14 @@ | ||
variable "vpc_id" { | ||
description = "vpc id to create secondary cidr on" | ||
type = string | ||
} | ||
|
||
variable "natgw_id_1" { | ||
description = "nat gw id for az 2" | ||
type = string | ||
} | ||
|
||
variable "natgw_id_2" { | ||
description = "nat gw id for az 2" | ||
type = string | ||
} |
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,39 @@ | ||
package test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gruntwork-io/terratest/modules/terraform" | ||
) | ||
|
||
func TestExamplesSecondaryCidr(t *testing.T) { | ||
|
||
primary := &terraform.Options{ | ||
TerraformDir: "./hcl_fixtures/secondary_cidr_base", | ||
} | ||
defer terraform.Destroy(t, primary) | ||
terraform.InitAndApply(t, primary) | ||
|
||
// region := terraform.Output(t, primary, "region") | ||
vpcId := terraform.Output(t, primary, "vpc_id") | ||
natgwId1 := terraform.Output(t, primary, "natgw_id_1") | ||
natgwId2 := terraform.Output(t, primary, "natgw_id_2") | ||
|
||
terraformOptions := &terraform.Options{ | ||
TerraformDir: "../examples/secondary_cidr", | ||
Vars: map[string]interface{}{ | ||
"vpc_id": vpcId, | ||
"natgw_id_1": natgwId1, | ||
"natgw_id_2": natgwId2, | ||
// "natgw_attrs": map[string]interface{}{ | ||
// fmt.Sprintf("%v%v", region, "a"): natgwId1, | ||
// fmt.Sprintf("%v%v", region, "b"): natgwId2, | ||
// }, | ||
}, | ||
} | ||
|
||
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,22 @@ | ||
data "aws_availability_zones" "current" {} | ||
|
||
module "vpc" { | ||
source = "aws-ia/vpc/aws" | ||
version = ">= 2.0.0" | ||
|
||
name = "primary-az-vpc" | ||
cidr_block = "10.0.0.0/16" | ||
az_count = 2 | ||
|
||
subnets = { | ||
public = { | ||
name_prefix = "primary-vpc-public" # omit to prefix with "public" | ||
netmask = 24 | ||
nat_gateway_configuration = "all_azs" # options: "single_az", "none" | ||
} | ||
private = { | ||
netmask = 24 | ||
connect_to_public_natgw = true | ||
} | ||
} | ||
} |
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,15 @@ | ||
output "vpc_id" { | ||
description = "vpc id" | ||
value = module.vpc.vpc_attributes.id | ||
|
||
} | ||
|
||
output "natgw_id_1" { | ||
value = module.vpc.nat_gateway_attributes_by_az[data.aws_availability_zones.current.names[0]].id | ||
description = "nat gateway attributes" | ||
} | ||
|
||
output "natgw_id_2" { | ||
value = module.vpc.nat_gateway_attributes_by_az[data.aws_availability_zones.current.names[1]].id | ||
description = "nat gateway attributes" | ||
} |
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,11 @@ | ||
terraform { | ||
required_version = ">= 1.0.7" | ||
experiments = [module_variable_optional_attrs] | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = ">= 3.72.0" | ||
} | ||
} | ||
} | ||
|
Empty file.
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