Course contentsShow
← Cloud and Infrastructure
Lesson 839 of 2,98915. Terraform in PracticeFree lesson

Parallel Execution and Performance

Optimize Terraform performance through parallelism configuration and resource targeting strategies.

Parallel Execution and Performance

What You'll Learn

You'll learn how to optimize Terraform's execution speed by configuring parallelism and using resource targeting to reduce plan and apply times in large infrastructures.

Understanding Terraform's Parallel Execution

By default, Terraform applies changes to up to 10 resources simultaneously. Think of it like a restaurant kitchen with 10 chefs working at once—some tasks can happen in parallel, but others must wait for dependencies to finish first.

Terraform's dependency graph determines which resources can be created concurrently. Resources without dependencies on each other run in parallel, while those with explicit or implicit dependencies wait their turn.

Configuring Parallelism

You can adjust the parallelism level using the -parallelism flag:

terraform apply -parallelism=20

This increases concurrent operations to 20. Higher values speed up large deployments but also increase API rate limit risks and resource contention on the Terraform host.

For slower, more conservative runs (useful with rate-limited APIs):

terraform apply -parallelism=1

Resource Targeting for Performance

When working with massive configurations, you can target specific resources to reduce scope:

terraform apply -target=module.networking
terraform plan -target=aws_instance.web_server

This limits Terraform's work to only the specified resources and their dependencies, dramatically reducing plan/apply time during development or troubleshooting.

Performance Considerations

  • Lower parallelism when hitting provider API rate limits
  • Higher parallelism when deploying many independent resources
  • Resource targeting reduces graph complexity but should not replace proper module boundaries
  • Monitor backend performance—large state files slow operations

Key Takeaway: Terraform's performance can be tuned by adjusting parallelism levels with -parallelism and focusing operations with -target, allowing you to balance speed against API limits and infrastructure constraints in large-scale deployments.