│ Error: Invalid function argument
│
│ on .terraform/modules/vpc.vpc.calculate_subnets.subnet_calculator/main.tf line 6, in locals:
│ 6: addrs_by_idx = cidrsubnets(var.base_cidr_block, local.networks_netmask_to_bits[*].new_bits...)
│ ├────────────────
│ │ while calling cidrsubnets(prefix, newbits...)
│
│ Invalid value for "newbits" parameter: not enough remaining address space
│ for a subnet with a prefix of 28 bits after 10.3.192.0/18.
Which seems to be caused by the order of subnet calculation. When changing the subnet to a smaller size it became clear why:
I needed to figure out why my Terraform run gave an IP exhaustion error.
I ran the following Terraform code:
Error:
Which seems to be caused by the order of subnet calculation. When changing the subnet to a smaller size it became clear why:
Output:
This happens because maps in Terraform are put in lexicographic order. Changing the network names using prefixes like 0 1 2 or a b c fixes this.