Skip to content

Commit 3a32881

Browse files
authored
Added fix for issue when no private subnets are defined (terraform-aws-modules#47)
* Added fix for issue when no private subnets are defined * Minor readme
1 parent d19812d commit 3a32881

File tree

9 files changed

+157
-26
lines changed

9 files changed

+157
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Examples
9191

9292
* [Simple VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/simple-vpc)
9393
* [Complete VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete-vpc)
94+
* Few tests and edge cases examples: [#46](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/issue-46-no-private-subnets), [#44](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/issue-44-asymmetric-private-subnets)
9495

9596
Authors
9697
-------

examples/complete-vpc/main.tf

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,28 +29,3 @@ module "vpc" {
2929
Name = "complete"
3030
}
3131
}
32-
33-
# This example creates resources which are not present in all AZs.
34-
# This should be seldomly needed from architectural point of view,
35-
# and it can also lead this module to some edge cases.
36-
module "not_symmetrical_vpc" {
37-
source = "../../"
38-
39-
name = "not-symmetrical-example"
40-
41-
cidr = "10.0.0.0/16"
42-
43-
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
44-
private_subnets = ["10.0.1.0/24"]
45-
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
46-
database_subnets = ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]
47-
48-
create_database_subnet_group = true
49-
enable_nat_gateway = true
50-
51-
tags = {
52-
Terraform = "true"
53-
Environment = "dev"
54-
Name = "not-symmetrical"
55-
}
56-
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Issue 44 - VPC
2+
==============
3+
4+
Configuration in this directory creates set of VPC resources to cover issues reported on GitHub:
5+
6+
* https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/44
7+
8+
Usage
9+
=====
10+
11+
To run this example you need to execute:
12+
13+
```bash
14+
$ terraform init
15+
$ terraform plan
16+
$ terraform apply
17+
```
18+
19+
Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# List of AZs and private subnets are not of equal length
2+
#
3+
# This example creates resources which are not present in all AZs.
4+
# This should be seldomly needed from architectural point of view,
5+
# and it can also lead this module to some edge cases.
6+
#
7+
# Github issue: https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/44
8+
module "vpc" {
9+
source = "../../"
10+
11+
name = "asymmetrical"
12+
13+
cidr = "10.0.0.0/16"
14+
15+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
16+
private_subnets = ["10.0.1.0/24"]
17+
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
18+
database_subnets = ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]
19+
20+
create_database_subnet_group = true
21+
enable_nat_gateway = true
22+
23+
tags = {
24+
Issue = "44"
25+
Name = "asymmetrical"
26+
}
27+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# VPC
2+
output "vpc_id" {
3+
description = "The ID of the VPC"
4+
value = "${module.vpc.vpc_id}"
5+
}
6+
7+
# Subnets
8+
output "private_subnets" {
9+
description = "List of IDs of private subnets"
10+
value = ["${module.vpc.private_subnets}"]
11+
}
12+
13+
output "public_subnets" {
14+
description = "List of IDs of public subnets"
15+
value = ["${module.vpc.public_subnets}"]
16+
}
17+
18+
output "database_subnets" {
19+
description = "List of IDs of database subnets"
20+
value = ["${module.vpc.database_subnets}"]
21+
}
22+
23+
output "elasticache_subnets" {
24+
description = "List of IDs of elasticache subnets"
25+
value = ["${module.vpc.elasticache_subnets}"]
26+
}
27+
28+
# NAT gateways
29+
output "nat_public_ips" {
30+
description = "List of public Elastic IPs created for AWS NAT Gateway"
31+
value = ["${module.vpc.nat_public_ips}"]
32+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Issue 46 - VPC
2+
==============
3+
4+
Configuration in this directory creates set of VPC resources to cover issues reported on GitHub:
5+
6+
* https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/46
7+
8+
Usage
9+
=====
10+
11+
To run this example you need to execute:
12+
13+
```bash
14+
$ terraform init
15+
$ terraform plan
16+
$ terraform apply
17+
```
18+
19+
Note that this example may create resources which can cost money (AWS Elastic IP, for example). Run `terraform destroy` when you don't need these resources.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# There are no private subnets in this VPC setup.
2+
#
3+
# Github issue: https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/46
4+
module "vpc" {
5+
source = "../../"
6+
7+
name = "no-private-subnets"
8+
9+
cidr = "10.0.0.0/16"
10+
11+
azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
12+
public_subnets = ["10.0.0.0/22", "10.0.4.0/22", "10.0.8.0/22"]
13+
private_subnets = []
14+
database_subnets = ["10.0.128.0/24", "10.0.129.0/24"]
15+
elasticache_subnets = ["10.0.131.0/24", "10.0.132.0/24", "10.0.133.0/24"]
16+
17+
enable_dns_support = true
18+
enable_dns_hostnames = true
19+
enable_nat_gateway = false
20+
21+
tags = {
22+
Issue = "46"
23+
Name = "no-private-subnets"
24+
}
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# VPC
2+
output "vpc_id" {
3+
description = "The ID of the VPC"
4+
value = "${module.vpc.vpc_id}"
5+
}
6+
7+
# Subnets
8+
output "private_subnets" {
9+
description = "List of IDs of private subnets"
10+
value = ["${module.vpc.private_subnets}"]
11+
}
12+
13+
output "public_subnets" {
14+
description = "List of IDs of public subnets"
15+
value = ["${module.vpc.public_subnets}"]
16+
}
17+
18+
output "database_subnets" {
19+
description = "List of IDs of database subnets"
20+
value = ["${module.vpc.database_subnets}"]
21+
}
22+
23+
output "elasticache_subnets" {
24+
description = "List of IDs of elasticache subnets"
25+
value = ["${module.vpc.elasticache_subnets}"]
26+
}
27+
28+
# NAT gateways
29+
output "nat_public_ips" {
30+
description = "List of public Elastic IPs created for AWS NAT Gateway"
31+
value = ["${module.vpc.nat_public_ips}"]
32+
}

main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,10 @@ resource "aws_route" "public_internet_gateway" {
7272

7373
#################
7474
# Private routes
75+
# There are so many route-tables as the largest amount of subnets of each type (really?)
7576
#################
7677
resource "aws_route_table" "private" {
77-
count = "${length(var.private_subnets)}"
78+
count = "${max(length(var.private_subnets), length(var.elasticache_subnets), length(var.database_subnets))}"
7879

7980
vpc_id = "${aws_vpc.this.id}"
8081
propagating_vgws = ["${var.private_propagating_vgws}"]

0 commit comments

Comments
 (0)