Skip to content

Commit 029080a

Browse files
authored
Multiple subnets per AZ. Named subnets (#174)
* Update versions * Updates * Updates * Updates * Updates * Updates * Multiple subnets per AZ * Multiple subnets per AZ * Multiple subnets per AZ
1 parent b132e47 commit 029080a

28 files changed

+1104
-104
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2017-2020 Cloud Posse, LLC
189+
Copyright 2017-2023 Cloud Posse, LLC
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 17 additions & 5 deletions
Large diffs are not rendered by default.

docs/terraform.md

Lines changed: 16 additions & 4 deletions
Large diffs are not rendered by default.

examples/complete/main.tf

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,9 @@ provider "aws" {
44

55
module "vpc" {
66
source = "cloudposse/vpc/aws"
7-
version = "1.1.0"
8-
9-
cidr_block = "172.16.0.0/16"
7+
version = "2.0.0"
108

9+
ipv4_primary_cidr_block = "172.16.0.0/16"
1110
assign_generated_ipv6_cidr_block = true
1211
ipv6_egress_only_internet_gateway_enabled = true
1312

@@ -17,20 +16,23 @@ module "vpc" {
1716
module "subnets" {
1817
source = "../../"
1918

20-
availability_zones = var.availability_zones
21-
vpc_id = module.vpc.vpc_id
22-
igw_id = [module.vpc.igw_id]
23-
ipv4_enabled = true
24-
ipv6_enabled = true
25-
ipv6_egress_only_igw_id = [module.vpc.ipv6_egress_only_igw_id]
26-
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
27-
ipv6_cidr_block = [module.vpc.vpc_ipv6_cidr_block]
28-
nat_gateway_enabled = false
29-
nat_instance_enabled = false
30-
aws_route_create_timeout = "5m"
31-
aws_route_delete_timeout = "10m"
19+
availability_zones = var.availability_zones
20+
vpc_id = module.vpc.vpc_id
21+
igw_id = [module.vpc.igw_id]
22+
ipv4_enabled = true
23+
ipv6_enabled = true
24+
ipv6_egress_only_igw_id = [module.vpc.ipv6_egress_only_igw_id]
25+
ipv4_cidr_block = [module.vpc.vpc_cidr_block]
26+
ipv6_cidr_block = [module.vpc.vpc_ipv6_cidr_block]
27+
nat_gateway_enabled = false
28+
nat_instance_enabled = false
29+
route_create_timeout = "5m"
30+
route_delete_timeout = "10m"
3231

3332
subnet_type_tag_key = "cpco.io/subnet/type"
3433

34+
subnets_per_az_count = var.subnets_per_az_count
35+
subnets_per_az_names = var.subnets_per_az_names
36+
3537
context = module.this.context
3638
}

examples/complete/outputs.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,53 @@ output "private_route_table_ids" {
3232
description = "IDs of the created private route tables"
3333
value = module.subnets.private_route_table_ids
3434
}
35+
36+
output "az_private_subnets_map" {
37+
description = "Map of AZ names to list of private subnet IDs in the AZs"
38+
value = module.subnets.az_private_subnets_map
39+
}
40+
41+
output "az_public_subnets_map" {
42+
description = "Map of AZ names to list of public subnet IDs in the AZs"
43+
value = module.subnets.az_public_subnets_map
44+
}
45+
46+
output "az_private_route_table_ids_map" {
47+
description = "Map of AZ names to list of private route table IDs in the AZs"
48+
value = module.subnets.az_private_route_table_ids_map
49+
}
50+
51+
output "az_public_route_table_ids_map" {
52+
description = "Map of AZ names to list of public route table IDs in the AZs"
53+
value = module.subnets.az_public_route_table_ids_map
54+
}
55+
56+
output "named_private_subnets_map" {
57+
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of private subnet IDs"
58+
value = module.subnets.named_private_subnets_map
59+
}
60+
61+
output "named_public_subnets_map" {
62+
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of public subnet IDs"
63+
value = module.subnets.named_public_subnets_map
64+
}
65+
66+
output "named_private_route_table_ids_map" {
67+
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of private route table IDs"
68+
value = module.subnets.named_private_route_table_ids_map
69+
}
70+
71+
output "named_public_route_table_ids_map" {
72+
description = "Map of subnet names (specified in `subnets_per_az_names` variable) to lists of public route table IDs"
73+
value = module.subnets.named_public_route_table_ids_map
74+
}
75+
76+
output "named_private_subnets_stats_map" {
77+
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"
78+
value = module.subnets.named_private_subnets_stats_map
79+
}
80+
81+
output "named_public_subnets_stats_map" {
82+
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"
83+
value = module.subnets.named_public_subnets_stats_map
84+
}

examples/complete/variables.tf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,30 @@ variable "availability_zones" {
77
type = list(string)
88
description = "List of Availability Zones where subnets will be created"
99
}
10+
11+
variable "subnets_per_az_count" {
12+
type = number
13+
description = <<-EOT
14+
The number of subnet of each type (public or private) to provision per Availability Zone.
15+
EOT
16+
default = 1
17+
18+
validation {
19+
condition = var.subnets_per_az_count > 0
20+
# Validation error messages must be on a single line, among other restrictions.
21+
# See https://github.com/hashicorp/terraform/issues/24123
22+
error_message = "The `subnets_per_az` value must be greater than 0."
23+
}
24+
}
25+
26+
variable "subnets_per_az_names" {
27+
type = list(string)
28+
29+
description = <<-EOT
30+
The subnet names of each type (public or private) to provision per Availability Zone.
31+
This variable is optional.
32+
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`,
33+
`named_private_route_table_ids_map` and `named_public_route_table_ids_map`
34+
EOT
35+
default = ["common"]
36+
}

0 commit comments

Comments
 (0)