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

Added fix for issue when no private subnets are defined #47

Merged
merged 2 commits into from
Dec 11, 2017
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Examples

* [Simple VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/simple-vpc)
* [Complete VPC](https://github.com/terraform-aws-modules/terraform-aws-vpc/tree/master/examples/complete-vpc)
* 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)

Authors
-------
Expand Down
25 changes: 0 additions & 25 deletions examples/complete-vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,3 @@ module "vpc" {
Name = "complete"
}
}

# This example creates resources which are not present in all AZs.
# This should be seldomly needed from architectural point of view,
# and it can also lead this module to some edge cases.
module "not_symmetrical_vpc" {
source = "../../"

name = "not-symmetrical-example"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
database_subnets = ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]

create_database_subnet_group = true
enable_nat_gateway = true

tags = {
Terraform = "true"
Environment = "dev"
Name = "not-symmetrical"
}
}
19 changes: 19 additions & 0 deletions examples/issue-44-asymmetric-private-subnets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Issue 44 - VPC
==============

Configuration in this directory creates set of VPC resources to cover issues reported on GitHub:

* https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/44

Usage
=====

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

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.
27 changes: 27 additions & 0 deletions examples/issue-44-asymmetric-private-subnets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# List of AZs and private subnets are not of equal length
#
# This example creates resources which are not present in all AZs.
# This should be seldomly needed from architectural point of view,
# and it can also lead this module to some edge cases.
#
# Github issue: https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/44
module "vpc" {
source = "../../"

name = "asymmetrical"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
private_subnets = ["10.0.1.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
database_subnets = ["10.0.21.0/24", "10.0.22.0/24", "10.0.23.0/24"]

create_database_subnet_group = true
enable_nat_gateway = true

tags = {
Issue = "44"
Name = "asymmetrical"
}
}
32 changes: 32 additions & 0 deletions examples/issue-44-asymmetric-private-subnets/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# VPC
output "vpc_id" {
description = "The ID of the VPC"
value = "${module.vpc.vpc_id}"
}

# Subnets
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.vpc.private_subnets}"]
}

output "public_subnets" {
description = "List of IDs of public subnets"
value = ["${module.vpc.public_subnets}"]
}

output "database_subnets" {
description = "List of IDs of database subnets"
value = ["${module.vpc.database_subnets}"]
}

output "elasticache_subnets" {
description = "List of IDs of elasticache subnets"
value = ["${module.vpc.elasticache_subnets}"]
}

# NAT gateways
output "nat_public_ips" {
description = "List of public Elastic IPs created for AWS NAT Gateway"
value = ["${module.vpc.nat_public_ips}"]
}
19 changes: 19 additions & 0 deletions examples/issue-46-no-private-subnets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Issue 46 - VPC
==============

Configuration in this directory creates set of VPC resources to cover issues reported on GitHub:

* https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/46

Usage
=====

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

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.
25 changes: 25 additions & 0 deletions examples/issue-46-no-private-subnets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# There are no private subnets in this VPC setup.
#
# Github issue: https://github.com/terraform-aws-modules/terraform-aws-vpc/issues/46
module "vpc" {
source = "../../"

name = "no-private-subnets"

cidr = "10.0.0.0/16"

azs = ["eu-west-1a", "eu-west-1b", "eu-west-1c"]
public_subnets = ["10.0.0.0/22", "10.0.4.0/22", "10.0.8.0/22"]
private_subnets = []
database_subnets = ["10.0.128.0/24", "10.0.129.0/24"]
elasticache_subnets = ["10.0.131.0/24", "10.0.132.0/24", "10.0.133.0/24"]

enable_dns_support = true
enable_dns_hostnames = true
enable_nat_gateway = false

tags = {
Issue = "46"
Name = "no-private-subnets"
}
}
32 changes: 32 additions & 0 deletions examples/issue-46-no-private-subnets/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# VPC
output "vpc_id" {
description = "The ID of the VPC"
value = "${module.vpc.vpc_id}"
}

# Subnets
output "private_subnets" {
description = "List of IDs of private subnets"
value = ["${module.vpc.private_subnets}"]
}

output "public_subnets" {
description = "List of IDs of public subnets"
value = ["${module.vpc.public_subnets}"]
}

output "database_subnets" {
description = "List of IDs of database subnets"
value = ["${module.vpc.database_subnets}"]
}

output "elasticache_subnets" {
description = "List of IDs of elasticache subnets"
value = ["${module.vpc.elasticache_subnets}"]
}

# NAT gateways
output "nat_public_ips" {
description = "List of public Elastic IPs created for AWS NAT Gateway"
value = ["${module.vpc.nat_public_ips}"]
}
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ resource "aws_route" "public_internet_gateway" {

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

vpc_id = "${aws_vpc.this.id}"
propagating_vgws = ["${var.private_propagating_vgws}"]
Expand Down