Dynamic VPCs creation

Hello guys,

We want to use Terraform to create the infrastructure for each customer in a dynamic way.

Each customer will receive their product in our private vpc. Each VPC, must have a different and unique IP range (/25 subnet).

We have a problem here. How can we make terraform automatically manage the IP ranges it will use for the VPCs?

Some similar to this:

customer 1 → VPC = 10.100.0.0/25
customer 2 → VPC = 10.100.0.128/25
customer 3 → VPC = 10.100.1.0/25
customer 4 → VPC = 10.100.1.128/25
customer 5 → VPC = 10.100.2.0/25
customer 6 → VPC = 10.100.2.128/25

We need to give each customer the next ips range consecutive to the last one used.

We have been looking at the option to use IPAM for this, but we couldn’t get it to work.
The other option is to use a python script that takes care of this, but we would like to handle everything with Terraform.

Do you have any other ideas?

Best,

Have you looked at the cidrsubnet function? cidrsubnet - Functions - Configuration Language - Terraform by HashiCorp

You could use something like cidrsubnet("10.100.0.0/16", 9, count.index) inside a resource using count or have a customer number inside a map used in a for_each.