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 =
customer 2 → VPC =
customer 3 → VPC =
customer 4 → VPC =
customer 5 → VPC =
customer 6 → VPC =

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?


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

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