Working on multi-region Terraform deployments on AWS

Terraform AWS provider works with only one region at a time. If we want to work on multiple regions, provider aliases need to be used. But using a variable value for this in a resource block or within a module is not possible.

Given a map of regions and VPC CIDRs, let’s try to create VPCs using modules. Note that we do not pass provider info here. It is passed when calling the module.

Root module files. Setup provider aliases for each region :

Root module where we call the VPC module. We pass provider info into each module. As of writing this, providers block cannot be dynamically generated as well.

Applying above will create 7 VPCs:



DevOps, IoT and amateur radio

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store