Aws vpc deployment with controllable number of nat gateways despite of subnets number

Hello terraform community! I’d appreciate any help or tip on how i can modify the following module to deploy any number of nat gateways despite of number of public and private subnets i deploy, this is the module created by someone else, i tried to understand the module, this is the reason why it has two locals.tf, one of the locals.tf with terraform console output commented out - in case it can be helpful in understanding generated data types, it needs just one locals.tf for the deployment.

terraform {
  required_version = ">= 0.12"

  required_providers {
    aws = {
      source = "hashicorp/aws"
    }
    time = {
      source = "hashicorp/time"
    }
  }
}

  pri_subnets_only = {
    for subnet in local.subnets_list : subnet.name => subnet
    if subnet.type == "private" ############
  }

  pub_subnets_only = {
    for subnet in local.subnets_list : subnet.name => subnet
    if subnet.type == "public" ############
  }

  decrease_pub_subnets = {
    for idx, subnet in slice((values(local.pub_subnets_only)), 0, local.count) : subnet.name => subnet
  }

  merged_subnets_minut_nat = merge(local.pri_subnets_only, local.decrease_pub_subnets)

i tried to sort public and private subnets only and then merge all together and use that local called merged_subnets_minut_nat and reference it everywhere instead of local.subnets, but going this way i reduce number of public subnets + getting an error on route table level, i’d like this module to deploy let’s say 3 public 3 private subnets and 1 nat gateways or 2 nat gateways or any number of nat gateways, so it could be deployed independently

the part in locals.tf related to nat_gateway_map is not working properly, specifically key called single , please help!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.