0
0
Terraformcloud~5 mins

Terraform in GitHub Actions - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Terraform in GitHub Actions
O(n)
Understanding Time Complexity

When using Terraform inside GitHub Actions, it's important to understand how the time to complete tasks grows as you add more resources.

We want to know how the number of Terraform operations affects the total execution time.

Scenario Under Consideration

Analyze the time complexity of running Terraform apply on multiple resources in a GitHub Actions workflow.


name: "Terraform Apply"
on:
  push:
jobs:
  terraform:
    runs-on: ubuntu-latest
    steps:
      - uses: "actions/checkout@v3"
      - uses: "hashicorp/setup-terraform@v3"
      - name: "Terraform Init"
        run: terraform init
      - name: "Terraform Apply"
        run: terraform apply -auto-approve
    

This workflow runs Terraform commands to initialize and apply infrastructure changes on each push.

Identify Repeating Operations

Look at what happens repeatedly during the Terraform apply step.

  • Primary operation: Terraform API calls to create or update each resource.
  • How many times: Once per resource defined in the Terraform configuration.
How Execution Grows With Input

As you add more resources, Terraform makes more API calls to create or update them.

Input Size (n)Approx. Api Calls/Operations
10About 10 API calls
100About 100 API calls
1000About 1000 API calls

Pattern observation: The number of API calls grows directly with the number of resources.

Final Time Complexity

Time Complexity: O(n)

This means the time to apply infrastructure changes grows in a straight line as you add more resources.

Common Mistake

[X] Wrong: "Terraform apply time stays the same no matter how many resources I have."

[OK] Correct: Each resource needs its own API call, so more resources mean more work and longer time.

Interview Connect

Understanding how Terraform operations scale helps you design efficient workflows and manage infrastructure growth confidently.

Self-Check

"What if we split the Terraform apply into multiple smaller jobs in GitHub Actions? How would the time complexity change?"