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

Error when creating VPC without any private subnets and has NAT gateways #1068

Closed
aiell0 opened this issue Apr 16, 2024 · 8 comments
Closed
Labels

Comments

@aiell0
Copy link
Contributor

aiell0 commented Apr 16, 2024

Description

When creating a VPC with only public subnets and with one_nat_gateway_per_az configured, module fails with an error.

Versions

  • Module version [Required]: 5.7.1

  • Terraform version: 1.7.5

  • Provider version(s): 5.45.0

Reproduction Code [Required]

module "outbound_vpc" {
  source  = "terraform-aws-modules/vpc/aws"
  version = "~>5.0"

  name = "outbound"
  cidr = "192.168.16.0/21"

  azs            = ["us-east-1a", "us-east-1b", "us-east-1c", "us-east-1d", "us-east-1e", "us-east-1f"]
  public_subnets = ["192.168.16.0/23", "192.168.18.0/23", "192.168.20.0/24", "192.168.21.0/24", "192.168.22.0/24", "192.168.23.0/24"]

  enable_nat_gateway     = true
  single_nat_gateway     = false
  one_nat_gateway_per_az = true
}

Steps to reproduce the behavior:

Run a terraform plan or terraform apply.

Expected behavior

VPC creates without issues.

Actual behavior

Module errors out.

Terminal Output Screenshot(s)

│ Error: Error in function call
│ 
│   on .terraform/modules/outbound_vpc/main.tf line 1088, in resource "aws_route" "private_nat_gateway":
│ 1088:   route_table_id         = element(aws_route_table.private[*].id, count.index)
│     ├────────────────
│     │ while calling element(list, index)
│     │ aws_route_table.private is empty tuple
│     │ count.index is 0
│ 
│ Call to function "element" failed: cannot use element function with an empty list.

Additional context

This use case comes from AWS Prescriptive Guidance around setting up network architecture. In this case, an outbound VPC would only have NAT gateways. This VPC would then have routes to it via Transit Gateway connections to other VPCs which emulates the same functionality as private subnets. This module does not support that setup in the current form.

@laserpedro
Copy link

From my understanding you have to define private subnets in the egress vpc cf here ...

@aiell0
Copy link
Contributor Author

aiell0 commented Apr 20, 2024

@laserpedro not quite....the egress VPC can live in another account and has just public subnets with NAT gateways living in them. You can then use a Transit Gateway to link those subnets with private subnets in separate VPCs that live in separate accounts. By creating a VPC with just public subnets for the egress VPC, you can keep the IP space small (which is desirable because this will be an internet-facing VPC after all).

@laserpedro
Copy link

What about using non routable IPs for the private subnets in your egress VPC ?

Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label May 22, 2024
@glyve99
Copy link

glyve99 commented May 23, 2024

I really think this is a valid use case and it's something I already witnessed on a past project. Also, AWS documents this pattern on some architectures, like here. I also made some local changes to the module so that the reproduction code (shared by @aiell0) works as expected. Can I open a PR for this? :)

Copy link

This issue has been automatically marked as stale because it has been open 30 days
with no activity. Remove stale label or comment or this issue will be closed in 10 days

@github-actions github-actions bot added the stale label Jun 24, 2024
Copy link

github-actions bot commented Jul 5, 2024

This issue was automatically closed because of stale in 10 days

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2024
Copy link

github-actions bot commented Aug 4, 2024

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants