At some point, every Terraform user asks the same question: can we skip the manual approval step and just apply changes automatically?
The answer is yes — Terraform supports auto apply via the -auto-approve flag. But whether you should use it is a different conversation entirely.
Let’s walk through how Terraform auto apply works, where it fits in a CI/CD pipeline, and how to avoid turning a convenience feature into a production incident.
What “Auto Apply” Actually Means in Terraform
By default, Terraform requires confirmation before applying changes:
1terraform applyYou’ll see a plan and then be prompted to confirm.
Auto apply removes that interactive step:
1terraform apply -auto-approveThis tells Terraform: “Go ahead and apply the changes without asking me.”
That’s perfect for automation — but it also removes a critical safety checkpoint.
Where Auto Apply Fits in CI/CD
Auto apply is most commonly used in pipelines where human interaction isn’t possible.
Here’s a simplified workflow:
- Developer pushes code
- Pipeline runs
terraform plan - Changes are reviewed (optionally)
- Pipeline runs
terraform apply -auto-approve
In practice, this might look like:
1terraform init
2terraform plan -out=tfplan
3terraform apply -auto-approve tfplanNotice something important here: we’re applying a saved plan, not recalculating it. That’s a key safety practice.
Here’s Where Things Get Risky
Auto apply isn’t dangerous by itself. The risk comes from what you allow to reach that step.
A few common mistakes:
- Running auto apply on every commit to main
- Skipping plan review entirely
- Applying directly to production environments
- Allowing drifted state to go unnoticed
A small typo in Terraform can result in:
- Deleting resources
- Recreating databases
- Breaking networking rules
With auto apply enabled, that mistake is executed instantly.
A Safer Pattern for Terraform Auto Apply
Instead of disabling auto apply entirely, most teams adopt a layered approach.
1. Auto Apply Only in Non-Production
Use auto apply freely in:
- Dev environments
- Sandbox accounts
- Ephemeral test stacks
Example condition in a pipeline:
1if [ "$ENV" = "dev" ]; then
2 terraform apply -auto-approve tfplan
3fi2. Require Approval for Production
For production, keep a manual gate:
- Pull request approval
- Plan output review
- Manual pipeline trigger
Some CI systems (like GitHub Actions or GitLab) support approval steps before deployment.
3. Always Apply a Saved Plan
This avoids a subtle but critical issue: plan drift.
Bad pattern:
1terraform apply -auto-approveGood pattern:
1terraform plan -out=tfplan
2terraform apply -auto-approve tfplanThis guarantees that what you reviewed is exactly what gets applied.
Automating Terraform Without Losing Control
Let’s look at a more realistic CI example using GitHub Actions:
1jobs:
2 terraform:
3 runs-on: ubuntu-latest
4
5 steps:
6 - uses: actions/checkout@v3
7
8 - name: Setup Terraform
9 uses: hashicorp/setup-terraform@v2
10
11 - name: Terraform Init
12 run: terraform init
13
14 - name: Terraform Plan
15 run: terraform plan -out=tfplan
16
17 - name: Terraform Apply (Auto)
18 if: github.ref == 'refs/heads/dev'
19 run: terraform apply -auto-approve tfplanNotice the condition: auto apply only runs on the dev branch.
When Auto Apply Actually Makes Sense
Despite the risks, there are scenarios where auto apply is the right choice:
Ephemeral Environments
Spin up infrastructure for testing and tear it down automatically.
Internal Tools or Low-Risk Services
Systems where downtime or recreation isn’t critical.
Highly Controlled Pipelines
Where:
- Code reviews are mandatory
- Plans are validated automatically
- Changes are predictable
Guardrails You Should Add
If you’re going to use Terraform auto apply, add some protection:
Use Policy Checks
Tools like Sentinel or OPA can block dangerous changes before apply.
Enable State Locking
Prevents concurrent applies that could corrupt state.
Limit Permissions
Your CI system should not have unrestricted access to your cloud account.
Monitor Changes
Log every apply and integrate alerts for unexpected modifications.
A Common Misconception
Some developers assume auto apply is “more DevOps” or “more automated.”
That’s not necessarily true.
Automation without control isn’t maturity — it’s just speed without brakes.
The goal is predictable, observable infrastructure changes, not just faster ones.
Quick Decision Guide
- Use auto apply → dev, test, short-lived environments
- Avoid auto apply → production, shared infrastructure
- Always → apply saved plans, review changes, add guardrails
Closing Thought
Terraform auto apply is one of those features that feels small but has big implications. Used carefully, it unlocks smooth, fully automated workflows. Used carelessly, it can take down real systems just as quickly.
If you treat it as a convenience tool rather than a default setting, you’ll get the benefits without the surprises.