-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
150 additions
and
29 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 |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../common/availabilty_zones.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 @@ | ||
| ../common/data.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 @@ | ||
| ../common/defaults.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,109 @@ | ||
| /* | ||
| * # About aws-vpc-setup :: subnets | ||
| * | ||
| * This submodule creates public and private subnets. | ||
| * | ||
| * # Usage | ||
| * | ||
| * ```hcl | ||
| * module "subnets" { | ||
| * source = "git@github.e.it.census.gov:terraform-modules/aws-vpc-setup.git//subnets" | ||
| * availability_zones = var.availability_zones | ||
| * public_subnets = [ { base_cidr = "10.188.16.0/24", label = "public", bits = 2, private = false } ] | ||
| * private_subnets = [ | ||
| * { base_cidr = "10.188.18.0/23", label = "private-lb", bits = 2, private = true }, | ||
| * { base_cidr = "10.188.20.0/23", label = "db", bits = 2, private = true }, | ||
| * { base_cidr = "10.188.22.0/23", label = "apps", bits = 2, private = true } ] | ||
| * | ||
| * vpc_name = var.vpc_name | ||
| * vpc_cidr_block = var.vpc_cidr_block | ||
| * vpc_index = var.vpc_index | ||
| * vpc_short_name = var.vpc_short_name | ||
| * vpc_full_name = var.vpc_full_name | ||
| * vpc_environment = var.vpc_environment | ||
| * | ||
| * tags = {} | ||
| * } | ||
| */ | ||
|
|
||
| locals { | ||
| account_id = var.account_id != "" ? var.account_id : data.aws_caller_identity.current.account_id | ||
| account_environment = data.aws_arn.current.partition == "aws-us-gov" ? "gov" : "ew" | ||
|
|
||
| base_tags = { | ||
| "boc:tf_module_version" = local._module_version | ||
| "boc:created_by" = "terraform" | ||
| } | ||
|
|
||
| availability_zones = length(var.availability_zones) != 0 ? var.availability_zones : data.aws_availability_zones.zones.names | ||
| az_count = length(local.availability_zones) | ||
| az_count_list = range(local.az_count) | ||
| az_list = toset(local.availability_zones) | ||
| empty = toset([]) | ||
| } | ||
|
|
||
| #--- | ||
| # public subnets | ||
| #--- | ||
| locals { | ||
| public_subnets = { for v in var.public_subnets : v.label => | ||
| { | ||
| base_cidr = v.base_cidr | ||
| label = v.label | ||
| bits = v.bits | ||
| private = v.private | ||
| subnets = [for i in local.az_count_list : cidrsubnet(v.base_cidr, v.bits, i)] | ||
| labels = [for az in local.availability_zones : format("%s-%s", v.label, az)] | ||
| availability_zones = local.availability_zones | ||
| } | ||
| } | ||
| public_map = flatten([for k, v in local.public_subnets : | ||
| [for i in local.az_count_list : tomap({ "subnet" = v.subnets[i], "label" = v.labels[i], "availability_zone" = v.availability_zones[i] })]]) | ||
| } | ||
|
|
||
|
|
||
| resource "aws_subnet" "public" { | ||
| for_each = { for subnet in local.public_map : subnet.label => subnet } | ||
| vpc_id = var.vpc_id | ||
| cidr_block = each.value.subnet | ||
| availability_zone = each.value.availability_zone | ||
|
|
||
| tags = merge( | ||
| local.base_tags, | ||
| var.tags, | ||
| map("Name", format("%v%v-%v", local._prefixes["subnet"], var.vpc_full_name, each.value.label)) | ||
| ) | ||
| } | ||
|
|
||
|
|
||
| #--- | ||
| # private subnets | ||
| #--- | ||
| locals { | ||
| private_subnets = { for v in var.private_subnets : v.label => | ||
| { | ||
| base_cidr = v.base_cidr | ||
| label = v.label | ||
| bits = v.bits | ||
| private = v.private | ||
| subnets = [for i in local.az_count_list : cidrsubnet(v.base_cidr, v.bits, i)] | ||
| labels = [for az in local.availability_zones : format("%s-%s", v.label, az)] | ||
| availability_zones = local.availability_zones | ||
| } | ||
| } | ||
| private_map = flatten([for k, v in local.private_subnets : | ||
| [for i in local.az_count_list : tomap({ "subnet" = v.subnets[i], "label" = v.labels[i], "availability_zone" = v.availability_zones[i] })]]) | ||
| } | ||
|
|
||
| resource "aws_subnet" "private" { | ||
| for_each = { for subnet in local.private_map : subnet.label => subnet } | ||
| vpc_id = var.vpc_id | ||
| cidr_block = each.value.subnet | ||
| availability_zone = each.value.availability_zone | ||
|
|
||
| tags = merge( | ||
| local.base_tags, | ||
| var.tags, | ||
| map("Name", format("%v%v-%v", local._prefixes["subnet"], var.vpc_full_name, each.value.label)) | ||
| ) | ||
| } |
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 @@ | ||
| ../common/prefixes.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 @@ | ||
| ../common/variables.common.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 @@ | ||
| ../common/variables.common.vpc.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,33 @@ | ||
| variable "availability_zones" { | ||
| description = "AWS Availability Zones to use (by default will use all available)" | ||
| type = list(string) | ||
| default = [] | ||
| } | ||
|
|
||
| variable "public_subnets" { | ||
| description = "List of objects with public subnet information to be created" | ||
| type = list(object({ | ||
| base_cidr = string | ||
| label = string | ||
| bits = number | ||
| private = bool | ||
| # subnets = list(string) | ||
| # labels = list(string) | ||
| # availability_zones = list(string) | ||
| })) | ||
| default = [] | ||
| } | ||
|
|
||
| variable "private_subnets" { | ||
| description = "List of objects with private subnet information to be created" | ||
| type = list(object({ | ||
| base_cidr = string | ||
| label = string | ||
| bits = number | ||
| private = bool | ||
| # subnets = list(string) | ||
| # labels = list(string) | ||
| # availability_zones = 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../common/version.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 |
|---|---|---|
| @@ -1,31 +1,3 @@ | ||
| locals { | ||
| az_list = data.aws_availability_zones.zones.names | ||
| az_count = length(local.az_list) | ||
| az_count_list = range(local.az_count) | ||
| region = data.aws_region.current.name | ||
| } | ||
|
|
||
| data "aws_availability_zones" "zones" { | ||
| state = "available" | ||
| } | ||
|
|
||
| data "aws_availability_zone" "zone" { | ||
| count = length(data.aws_availability_zones.zones.names) | ||
| state = "available" | ||
| name = data.aws_availability_zones.zones.names[count.index] | ||
| } | ||
|
|
||
| output "availability_zone_names" { | ||
| description = "VPC Availability zone name list (3)" | ||
| value = data.aws_availability_zones.zones.names | ||
| } | ||
|
|
||
| output "availability_zone_ids" { | ||
| description = "VPC Availability zone id list (3)" | ||
| value = data.aws_availability_zones.zones.zone_ids | ||
| } | ||
|
|
||
| output "availability_zone_suffixes" { | ||
| description = "VPC Availability zone suffix list (3)" | ||
| value = data.aws_availability_zone.zone[*].name_suffix | ||
| region = data.aws_region.current.name | ||
| } |