Terraform Registry modules - Time & Space Complexity
When using Terraform Registry modules, it is important to understand how the number of modules affects the time it takes to apply your infrastructure changes.
We want to know how the execution time grows as we add more modules to our Terraform configuration.
Analyze the time complexity of applying multiple Terraform Registry modules.
module "network" {
source = "terraform-aws-modules/vpc/aws"
version = "3.14.0"
name = "my-vpc"
cidr_block = "10.0.0.0/16"
}
module "compute" {
source = "terraform-aws-modules/ec2-instance/aws"
version = "4.5.0"
instance_count = 3
name = "my-instance"
}
// More modules can be added similarly
This sequence shows how multiple modules from the Terraform Registry are declared and used to provision resources.
Each module triggers API calls to create or update resources.
- Primary operation: Terraform applies each module, which provisions resources via cloud provider API calls.
- How many times: Once per module, but each module may provision multiple resources internally.
As you add more modules, the total number of API calls grows roughly in proportion to the number of modules and their internal resources.
| Input Size (n modules) | Approx. API Calls/Operations |
|---|---|
| 10 | Depends on resources per module, roughly 10 times the calls of one module |
| 100 | About 100 times the calls of one module |
| 1000 | About 1000 times the calls of one module |
Pattern observation: The total work grows linearly as you add more modules.
Time Complexity: O(n)
This means the time to apply your Terraform configuration grows roughly in direct proportion to the number of modules you use.
[X] Wrong: "Adding more modules won't affect apply time much because modules are just references."
[OK] Correct: Each module provisions real resources, so more modules mean more API calls and longer apply times.
Understanding how Terraform modules affect execution time helps you design scalable infrastructure and manage deployment expectations confidently.
"What if we changed from using many small modules to one large module with all resources? How would the time complexity change?"