Skip to main content

On This Page

TF_IN_AUTOMATION Tells Terraform: No Humans Here

2 min read
Share

These articles are AI-generated summaries. Please check the original sources for full details.

¿Qué es TF_IN_AUTOMATION?

TF_IN_AUTOMATION is an environment variable used by Terraform to detect execution within automated environments such as CI/CD pipelines (GitHub Actions, GitLab CI, Azure DevOps, Jenkins) or non-interactive scripts. Setting this variable to true alters Terraform’s behavior for optimized automation.

Why This Matters

Terraform, by default, is designed for interactive use, often including verbose output and prompts for confirmation. This is problematic for automated systems where human intervention is not possible, leading to pipeline failures or unreliable results. The cost of these failures can range from delayed deployments to significant infrastructure inconsistencies.

Key Insights

  • Terraform’s interactive prompts can halt CI/CD pipelines: 2023
  • TF_IN_AUTOMATION reduces unnecessary output for machine-readable logs: improves observability
  • Tools like Terraform Cloud and Sentinel offer alternative automation controls.

Working Example

# Setting the environment variable in a shell
export TF_IN_AUTOMATION=true
# Setting the environment variable in a GitHub Actions workflow
env:
  TF_IN_AUTOMATION: "true"
run: |
  terraform init
  terraform plan
  terraform apply -auto-approve

Practical Applications

  • Stripe: Uses TF_IN_AUTOMATION in their CI/CD pipelines for infrastructure deployments.
  • Pitfall: Relying solely on TF_IN_AUTOMATION without -input=false and -auto-approve can still lead to interactive prompts if Terraform requires user input.

References:

Continue reading

Next article

The Machine Learning Engineer’s Checklist: Best Practices for Reliable Models

Related Content