0
0
Terraformcloud~5 mins

Monorepo vs multi-repo for Terraform - Performance Comparison

Choose your learning style9 modes available
Time Complexity: Monorepo vs multi-repo for Terraform
O(n)
Understanding Time Complexity

We want to understand how the time to manage infrastructure changes grows when using one big repository versus many smaller ones in Terraform.

How does the number of repositories affect the work Terraform does?

Scenario Under Consideration

Analyze the time complexity of applying Terraform configurations in two setups.


# Monorepo example
module "network" {
  source = "./modules/network"
}
module "compute" {
  source = "./modules/compute"
}

# Multi-repo example
# Separate repos for network and compute modules

This shows a single repo with multiple modules versus separate repos each with their own module.

Identify Repeating Operations

Look at what Terraform does repeatedly when applying changes.

  • Primary operation: Terraform plan and apply commands for each repo or module.
  • How many times: Once per repo in multi-repo, once for all modules in monorepo.
How Execution Grows With Input

As the number of modules or repos grows, the work changes differently.

Input Size (n)Approx. Api Calls/Operations
10~10 applies in multi-repo, 1 apply with 10 modules in monorepo
100~100 applies in multi-repo, 1 apply with 100 modules in monorepo
1000~1000 applies in multi-repo, 1 apply with 1000 modules in monorepo

Multi-repo grows linearly with number of repos; monorepo runs once regardless of module count.

Final Time Complexity

Time Complexity: O(n)

This means the time grows directly with the number of repositories in multi-repo, but stays mostly constant in monorepo.

Common Mistake

[X] Wrong: "More repos always mean faster Terraform runs because each is smaller."

[OK] Correct: Running Terraform separately for many repos adds overhead each time, making total time grow with repo count.

Interview Connect

Understanding how repo structure affects Terraform run time helps you design infrastructure code that scales well and stays manageable.

Self-Check

"What if we split a monorepo into fewer but larger repos? How would the time complexity change?"