How to Auto Approve Terraform Apply Commands Easily
To auto approve a Terraform apply, use the
-auto-approve flag with the terraform apply command. This skips the interactive approval prompt and applies changes immediately.Syntax
The terraform apply command applies changes to your infrastructure. Adding the -auto-approve flag skips the confirmation prompt, allowing the command to run without manual input.
terraform apply: Starts the apply process.-auto-approve: Automatically approves the plan without asking.
bash
terraform apply -auto-approve
Example
This example shows how to run terraform apply with auto approval to deploy infrastructure changes without manual confirmation.
bash
terraform init terraform plan terraform apply -auto-approve
Output
Initializing the backend...
Terraform has been successfully initialized!
An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
+ create
Plan: 1 to add, 0 to change, 0 to destroy.
Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
Common Pitfalls
Using -auto-approve can be risky because it applies changes immediately without review. Common mistakes include:
- Running
terraform apply -auto-approvewithout checking the plan first. - Applying destructive changes unintentionally.
- Using auto-approve in production without safeguards.
Always run terraform plan first to review changes before auto approving.
bash
terraform apply
# waits for user confirmation
# Wrong: skipping plan and auto approving blindly
terraform apply -auto-approve
# Right: plan first, then auto approve
terraform plan
terraform apply -auto-approveQuick Reference
Use this cheat sheet to remember how to auto approve Terraform applies safely:
| Command | Description |
|---|---|
| terraform plan | Shows what changes Terraform will make |
| terraform apply | Applies changes with manual confirmation |
| terraform apply -auto-approve | Applies changes immediately without confirmation |
Key Takeaways
Use the -auto-approve flag with terraform apply to skip manual approval.
Always run terraform plan first to review changes before applying.
Auto approval is useful for automation but can cause unintended changes if used carelessly.
Avoid using -auto-approve in production without proper safeguards.
Review your Terraform plan output carefully before auto approving.