Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple subnets per AZ. Named subnets #174

Merged
merged 9 commits into from
Jan 27, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2017-2020 Cloud Posse, LLC
Copyright 2017-2023 Cloud Posse, LLC

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
22 changes: 17 additions & 5 deletions README.md

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions docs/terraform.md

Large diffs are not rendered by default.

32 changes: 17 additions & 15 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ provider "aws" {

module "vpc" {
source = "cloudposse/vpc/aws"
version = "1.1.0"

cidr_block = "172.16.0.0/16"
version = "2.0.0"

ipv4_primary_cidr_block = "172.16.0.0/16"
assign_generated_ipv6_cidr_block = true
ipv6_egress_only_internet_gateway_enabled = true

Expand All @@ -17,20 +16,23 @@ module "vpc" {
module "subnets" {
source = "../../"

availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_enabled = true
ipv6_enabled = true
ipv6_egress_only_igw_id = [module.vpc.ipv6_egress_only_igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
ipv6_cidr_block = [module.vpc.vpc_ipv6_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false
aws_route_create_timeout = "5m"
aws_route_delete_timeout = "10m"
availability_zones = var.availability_zones
vpc_id = module.vpc.vpc_id
igw_id = [module.vpc.igw_id]
ipv4_enabled = true
ipv6_enabled = true
ipv6_egress_only_igw_id = [module.vpc.ipv6_egress_only_igw_id]
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
ipv6_cidr_block = [module.vpc.vpc_ipv6_cidr_block]
nat_gateway_enabled = false
nat_instance_enabled = false
route_create_timeout = "5m"
route_delete_timeout = "10m"

subnet_type_tag_key = "cpco.io/subnet/type"

subnets_per_az_count = var.subnets_per_az_count
subnets_per_az_names = var.subnets_per_az_names

context = module.this.context
}
50 changes: 50 additions & 0 deletions examples/complete/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,53 @@ output "private_route_table_ids" {
description = "IDs of the created private route tables"
value = module.subnets.private_route_table_ids
}

output "az_private_subnets_map" {
description = "Map of AZ names to list of private subnet IDs in the AZs"
value = module.subnets.az_private_subnets_map
}

output "az_public_subnets_map" {
description = "Map of AZ names to list of public subnet IDs in the AZs"
value = module.subnets.az_public_subnets_map
}

output "az_private_route_table_ids_map" {
description = "Map of AZ names to list of private route table IDs in the AZs"
value = module.subnets.az_private_route_table_ids_map
}

output "az_public_route_table_ids_map" {
description = "Map of AZ names to list of public route table IDs in the AZs"
value = module.subnets.az_public_route_table_ids_map
}

output "named_private_subnets_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of private subnet IDs"
value = module.subnets.named_private_subnets_map
}

output "named_public_subnets_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of public subnet IDs"
value = module.subnets.named_public_subnets_map
}

output "named_private_route_table_ids_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of private route table IDs"
value = module.subnets.named_private_route_table_ids_map
}

output "named_public_route_table_ids_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of public route table IDs"
value = module.subnets.named_public_route_table_ids_map
}

output "named_private_subnets_stats_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of objects with each object having three items: AZ, private subnet ID, private route table ID"
value = module.subnets.named_private_subnets_stats_map
}

output "named_public_subnets_stats_map" {
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of objects with each object having three items: AZ, public subnet ID, public route table ID"
value = module.subnets.named_public_subnets_stats_map
}
27 changes: 27 additions & 0 deletions examples/complete/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,30 @@ variable "availability_zones" {
type = list(string)
description = "List of Availability Zones where subnets will be created"
}

variable "subnets_per_az_count" {
type = number
description = <<-EOT
The number of subnet of each type (public or private) to provision per Availability Zone.
EOT
default = 1

validation {
condition = var.subnets_per_az_count > 0
# Validation error messages must be on a single line, among other restrictions.
# See https://github.com/hashicorp/terraform/issues/24123
error_message = "The `subnets_per_az` value must be greater than 0."
}
}

variable "subnets_per_az_names" {
type = list(string)

description = <<-EOT
The subnet names of each type (public or private) to provision per Availability Zone.
This variable is optional.
If a list of names is provided, the list items will be used as keys in the outputs `named_private_subnets_map`, `named_public_subnets_map`,
`named_private_route_table_ids_map` and `named_public_route_table_ids_map`
EOT
default = ["common"]
}
Loading