Hi,
I was using this module Terraform Registry
I want to create private subnets without using 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
this is the code: main.tf
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
# For every value of numbers of AZ, join the AZ name with subnet name
public_subnet_names = [for value in local.azs : join("-", [value, local.public_subnet_name])]
private_subnet_names = local.private_subnets_all_names
}
locals:
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))
}
# Reusable local variables for VPC module
locals {
vpc_name = "xxxxxx"
public_subnet_name = "public_subnet"
}
# List of multiple private subnet names
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))
}
but when adding the additional resources such as database_subnets or elasticache_subnets 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
# For every value of numbers of AZ, join the AZ name with subnet name
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"])
}
# Reusable local variables for VPC module
locals {
vpc_name = "xxxxxx"
public_subnet_name = "public_subnet"
}
# List of multiple private subnet names
locals {
private_subnet_workload_name = "workload_subnet"
private_subnet_datatier_name = "datatier_subnet"
private_subnet_tgw_name = "transit_gateway_subnet"
}
what is the issue here? Thank you in advance.