When to Run Terraform Apply – Quick Usage Examples

Terraform apply

In this post, I will explain what the terraform apply command is used for, what it does, the available options, and when to run it.

What is Terraform Apply?

The terraform apply command executes the actions proposed in a terraform plan. It is used to deploy your infrastructure. Typically apply should be run after terraform init and terraform plan.

What Does the Terraform Apply Command Do?

Quick Usage Examples

Is It Safe to Run Terraform Apply Multiple Times?

If there are no changes in the configuration files compared to the current Terraform state, then no changes will be made to the infrastructure. Terraform is a declarative language, so it is absolutely safe to run the apply command multiple times.

Running Terraform Apply in Automation

In automation terraform apply can be run after the plan stage, passing in the plan output file. If there is no plan stage prior to the apply stage (not recommended), then the terraform apply -auto-approve option can be used. Another useful option to avoid encoding issues when running pipelines in some CI/CD systems, i.e. Azure DevOps, is the terraform apply -no-color option, as the colored output is not handled correctly by the build agents.

Key Points

Manage Terraform Better and Faster

If you are struggling with Terraform automation and management, check out Spacelift. It helps you manage Terraform state, build more complex workflows, and adds several must-have capabilities for end-to-end infrastructure management.

Start free trial