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

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

Closed
Mysilver-cloud opened this issue Jul 20, 2023 · 3 comments
Labels

Comments

@Mysilver-cloud
Copy link

Mysilver-cloud commented Jul 20, 2023

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

  • Module version [omitted]:

  • Terraform version:

= 0.15.1

  • Provider version(s):

= 5.0.0

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
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 Aug 20, 2023
@github-actions
Copy link

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 Aug 30, 2023
@github-actions
Copy link

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 Sep 29, 2023
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

1 participant