cloudposse / terraform-aws-dynamic-subnets

Terraform module for public and private subnets provisioning in existing VPC
https://cloudposse.com/accelerate
Apache License 2.0
191 stars 165 forks source link

No NAT Gateway created if private subnets are not set #216

Open nnsense opened 5 hours ago

nnsense commented 5 hours ago

Describe the Bug

This module has features leaving to think it's able to deploy private and public subnets separately. It mostly works but, apparently, you must have both public and private enabled to get the NAT Gateways created, leaving the user to deal with it separately even if the resources to create them are already existing into the module.

This is due to: local.nat_gateway_enabled is true if nat_gateway_enabled = local.nat_gateway_useful && local.nat_gateway_setting

local.nat_gateway_useful is true if nat_gateway_useful = local.nat_instance_useful || local.public_dns64_enabled || local.private_dns64_enabled

About nat_gateway_setting, _if nat_instance_enabled is set to true, we set the default for nat_gateway_enabled to false_. This is the only place across the module where the var nat_gateway_enabled is actually used.

then local.nat_instance_useful is true if nat_instance_useful = local.private4_enabled

and local.private4_enabled is true if private4_enabled = local.private_enabled && local.ipv4_enabled

finally private_enabled = local.e && var.private_subnets_enabled

So, the NATGW won't be created if the private_subnets_enabled variable is set to false.

The change is obviosly trivial, I would just set

nat_instance_useful = local.private4_enabled || local.public4_enabled

or, in all honesty even

nat_instance_useful = local.public4_enabled

My question is:

Expected Behavior

If the variable nat_gateway_enabled is set to true with private_subnets_enabled set to false, I would expect the NAT gateways to be created, leaving the user able to use that instead of creating it separately.

Steps to Reproduce

Just try to deploy the module with

nat_gateway_enabled = true
private_subnets_enabled = false

No NAT gateways will be created

Screenshots

No response

Environment

No response

Additional Context

No response