terraform-aws-modules / terraform-aws-vpc

Terraform module to create AWS VPC resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/vpc/aws
Apache License 2.0
2.98k stars 4.44k forks source link

Unable to create multiple private subnets from [private_subnets], with different names #964

Closed Mysilver-cloud closed 1 year ago

Mysilver-cloud commented 1 year ago

Description

Hi,

I want to create private subnets without using additional keywords such as database_subnets or elasticache_subnets, but for some reason terraform gives me this error: Error: creating EC2 VPC: InvalidParameterValue: The allocation size is too big for the pool. status code: 400, request id: 4b211e71-05f7-474c-90f3-ef3f43e4a3ba

Versions

Reproduction Code [Required]

module "vpc" {
  source            = "terraform-aws-modules/vpc/aws"
  ipv4_ipam_pool_id = data.aws_vpc_ipam_pool.ipv4_prod.id
  cidr              = data.aws_vpc_ipam_preview_next_cidr.previewed_cidr.cidr
  private_subnets   = local.cidrsubnet_private
  public_subnets    = local.cidrsubnet_public
  name              = local.vpc_name

  azs = local.azs
  public_subnet_names  = [for value in local.azs : join("-", [value, local.public_subnet_name])]
  private_subnet_names = local.private_subnets_all_names
}
locals {
  partition          = cidrsubnets(data.aws_vpc_ipam_preview_next_cidr.previewed_cidr.cidr, 1, 2, 3, 3) # result = 3 Sub CIDRs with prefixes 25, 26, 27, 27
  cidrsubnet_public  = cidrsubnets(local.partition[2], 1, 1)                                         # Result = 1 Sub CIDR with prefix 28
  cidrsubnet_wld     = cidrsubnets(local.partition[0], 1, 1)                                         # Result = 1 Sub CIDR with prefix 26
  cidrsubnet_data    = cidrsubnets(local.partition[1], 1, 1)                                         # Result = 1 Sub CIDR with prefix 27
  cidrsubnet_tgw     = cidrsubnets(local.partition[3], 1, 1)                                         # Result = 1 Sub CIDR with prefix 28
  azs                = formatlist("${data.aws_region.current.name}%s", ["a", "b"])
  cidrsubnet_private = tolist(concat(local.cidrsubnet_wld, local.cidrsubnet_data, local.cidrsubnet_tgw))
}
locals {
  vpc_name           = "xxxxxx"
  public_subnet_name = "public_subnet"
}
locals {
  private_subnet_workload_name = [for value in local.azs : join("-", [value, "workload_subnet"])]
  private_subnet_datatier_name = [for value in local.azs : join("-", [value, "datatier_subnet"])]
  private_subnet_tgw_name      = [for value in local.azs : join("-", [value, "transit_gateway_subnet"])]
  private_subnets_all_names    = tolist(concat(local.private_subnet_workload_name, local.private_subnet_datatier_name, local.private_subnet_tgw_name))
}

Expected behavior

create 2 AZ, each AZ has 3 private & 1 public subnet. In total 8 subnets

Actual behavior

Only VPC was created

Terminal Output Screenshot(s)

Error: creating EC2 VPC: InvalidParameterValue: The allocation size is too big for the pool. status code: 400, request id: 4b211e71-05f7-474c-90f3-ef3f43e4a3ba

Additional context

But when I add database_subnet_names, elasticache_subnet_names to seperate the private subnet names. It works

module "vpc" {
  source              = "terraform-aws-modules/vpc/aws"
  ipv4_ipam_pool_id   = data.aws_vpc_ipam_pool.ipv4_prod.id
  cidr                = data.aws_vpc_ipam_preview_next_cidr.previewed_cidr.cidr
  database_subnets    = local.cidrsubnet_data
  elasticache_subnets = local.cidrsubnet_tgw
  private_subnets     = local.cidrsubnet_wld
  public_subnets      = local.cidrsubnet_public
  name                = local.vpc_name

  azs = local.azs
  public_subnet_names      = [for value in local.azs : join("-", [value, local.public_subnet_name])]
  private_subnet_names     = [for value in local.azs : join("-", [value, local.private_subnet_workload_name])]
  database_subnet_names    = [for value in local.azs : join("-", [value, local.private_subnet_datatier_name])]
  elasticache_subnet_names = [for value in local.azs : join("-", [value, local.private_subnet_tgw_name])]
}
locals {
  partition         = cidrsubnets(data.aws_vpc_ipam_preview_next_cidr.previewed_cidr.cidr, 1, 2, 3, 3) # result = 3 Sub CIDRs with prefixes 25, 26, 27, 27
  cidrsubnet_public = cidrsubnets(local.partition[2], 1, 1)                                            # Result = 1 Sub CIDR with prefix 28
  cidrsubnet_wld    = cidrsubnets(local.partition[0], 1, 1)                                            # Result = 1 Sub CIDR with prefix 26
  cidrsubnet_data   = cidrsubnets(local.partition[1], 1, 1)                                            # Result = 1 Sub CIDR with prefix 27
  cidrsubnet_tgw    = cidrsubnets(local.partition[3], 1, 1)                                            # Result = 1 Sub CIDR with prefix 28
  azs               = formatlist("${data.aws_region.current.name}%s", ["a", "b"])
}
locals {
  vpc_name           = "xxxxxx"
  public_subnet_name = "public_subnet"
}
locals {
  private_subnet_workload_name = "workload_subnet"
  private_subnet_datatier_name = "datatier_subnet"
  private_subnet_tgw_name      = "transit_gateway_subnet"
}
github-actions[bot] commented 1 year ago

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[bot] commented 1 year ago

This issue was automatically closed because of stale in 10 days

github-actions[bot] commented 1 year ago

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.