Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Terraform Tutorias: CLI environment and predefined/meta variables Complete Reference

Terraform CLI environment variables reference

Environment VariableDescriptionExample Usage
TF_LOGControls logging verbosity. Values: TRACE, DEBUG, INFO, WARN, ERROR, OFF.export TF_LOG=DEBUG
TF_LOG_PATHSpecifies log file path to store logs.export TF_LOG_PATH=./terraform.log
TF_INPUTDetermines if Terraform prompts for user input. Set to false to disable.export TF_INPUT=false
TF_VAR_nameSets Terraform input variables from the environment. Example: TF_VAR_region.export TF_VAR_region=us-west-1
TF_CLI_ARGS and TF_CLI_ARGS_nameDefines default CLI arguments for Terraform commands. Example: TF_CLI_ARGS_plan.export TF_CLI_ARGS=’-input=false’
TF_DATA_DIRChanges Terraform data directory from the default `.terraform`.export TF_DATA_DIR=/custom/data/dir
TF_WORKSPACESpecifies the workspace to use in Terraform.export TF_WORKSPACE=production
TF_IN_AUTOMATIONIndicates if Terraform is running in an automated environment (CI/CD).export TF_IN_AUTOMATION=true
TF_REGISTRY_DISCOVERY_RETRYNumber of retries for Terraform Registry discovery.export TF_REGISTRY_DISCOVERY_RETRY=5
TF_REGISTRY_CLIENT_TIMEOUTSets timeout duration for Terraform Registry client operations.export TF_REGISTRY_CLIENT_TIMEOUT=30
TF_STATE_PERSIST_INTERVALDefines how frequently Terraform writes its state file.export TF_STATE_PERSIST_INTERVAL=10
TF_CLI_CONFIG_FILESpecifies custom path for Terraform CLI configuration file.export TF_CLI_CONFIG_FILE=$HOME/.terraformrc
TF_PLUGIN_CACHE_DIRSpecifies the directory for Terraform plugin cache.export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache
TF_IGNOREDefines patterns for files and directories that Terraform should ignore.export TF_IGNORE=’*.bak’

Terraform predefined and meta variables reference

Built-in VariableDescription
terraform.workspaceReturns the current workspace name.
path.moduleReturns the current module path.
path.rootReturns the root module path.
path.cwdReturns the current working directory.
count.indexCurrent index in a count loop.
each.key, each.valueCurrent key-value in a for_each loop.
var.<variable_name>References an input variable.
local.<local_variable>References a local variable.
module.<module_name>.<output>Retrieves an output from a child module.
selfRefers to current resource instance.
depends_onExplicitly sets dependencies between resources.
env.<ENV_VAR>Retrieves environment variables from the shell.

Comprehensive Guide: Terraform CLI Environment Variables & Predefined Variables

1. Terraform CLI Environment Variables Reference

Terraform allows configuring its behavior using various environment variables. These variables control logging, input handling, workspace management, and registry discovery settings. Below is a detailed guide with use cases and examples.

1.1 Logging & Debugging

TF_LOG

  • Description: Controls Terraform logging verbosity.
  • Possible Values: TRACE, DEBUG, INFO, WARN, ERROR, OFF
  • Use Case: Useful for debugging Terraform execution.
  • Example: export TF_LOG=DEBUG terraform apply

TF_LOG_PATH

  • Description: Specifies a log file path to store logs.
  • Use Case: Useful when debugging Terraform automation pipelines.
  • Example: export TF_LOG_PATH=./terraform.log terraform apply

1.2 Input Handling

TF_INPUT

  • Description: Determines if Terraform prompts for user input. Set to false to disable interactive prompts.
  • Use Case: Useful in CI/CD environments.
  • Example: export TF_INPUT=false terraform apply

1.3 Variable Handling

TF_VAR_name

  • Description: Sets Terraform input variables from the environment.
  • Use Case: Allows dynamic configuration of Terraform variables without modifying the .tf file.
  • Example: export TF_VAR_region=us-west-1 terraform apply

TF_CLI_ARGS and TF_CLI_ARGS_name

  • Description: Defines default CLI arguments for Terraform commands.
  • Use Case: Ensures that Terraform always runs with specific flags.
  • Example: export TF_CLI_ARGS='-input=false' terraform apply export TF_CLI_ARGS_plan='-refresh=false' terraform plan

1.4 Terraform State & Data Management

TF_DATA_DIR

  • Description: Changes Terraform data directory from the default .terraform.
  • Use Case: Useful when running multiple Terraform executions in parallel.
  • Example: export TF_DATA_DIR=/custom/data/dir terraform init

TF_WORKSPACE

  • Description: Specifies the workspace to use in Terraform.
  • Use Case: Automate Terraform workspace switching.
  • Example: export TF_WORKSPACE=production terraform apply

TF_IN_AUTOMATION

  • Description: Indicates if Terraform is running in an automated environment (CI/CD).
  • Use Case: Helps Terraform suppress interactive prompts.
  • Example: export TF_IN_AUTOMATION=true terraform apply

1.5 Terraform Registry & Plugin Management

TF_REGISTRY_DISCOVERY_RETRY

  • Description: Number of retries for Terraform Registry discovery.
  • Use Case: Useful when working in unstable network environments.
  • Example: export TF_REGISTRY_DISCOVERY_RETRY=5

TF_REGISTRY_CLIENT_TIMEOUT

  • Description: Sets timeout duration for Terraform Registry client operations.
  • Use Case: Useful in slow networks.
  • Example: export TF_REGISTRY_CLIENT_TIMEOUT=30

TF_PLUGIN_CACHE_DIR

  • Description: Specifies the directory for Terraform plugin cache.
  • Use Case: Helps speed up Terraform runs by avoiding plugin downloads.
  • Example: export TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache

1.6 Miscellaneous Terraform Configurations

TF_STATE_PERSIST_INTERVAL

  • Description: Defines how frequently Terraform writes its state file.
  • Example: export TF_STATE_PERSIST_INTERVAL=10

TF_CLI_CONFIG_FILE

  • Description: Specifies a custom path for the Terraform CLI configuration file.
  • Example: export TF_CLI_CONFIG_FILE=$HOME/.terraformrc

TF_IGNORE

  • Description: Defines patterns for files and directories that Terraform should ignore.
  • Example: export TF_IGNORE='*.bak'

2. Terraform Predefined and Meta Variables Reference

Terraform provides a set of predefined variables that allow access to system metadata.

Built-in VariableDescription
terraform.workspaceReturns the current workspace name.
path.moduleReturns the current module path.
path.rootReturns the root module path.
path.cwdReturns the current working directory.
count.indexCurrent index in a count loop.
each.key, each.valueCurrent key-value in a for_each loop.
var.<variable_name>References an input variable.
local.<local_variable>References a local variable.
module.<module_name>.<output>Retrieves an output from a child module.
selfRefers to the current resource instance.
depends_onExplicitly sets dependencies between resources.
env.<ENV_VAR>Retrieves environment variables from the shell.

Example Usage:

output "workspace" {
  value = terraform.workspace
}
Code language: JavaScript (javascript)
output "current_path" {
  value = path.module
}
Code language: JavaScript (javascript)

By understanding and utilizing these Terraform environment variables and predefined expressions, users can optimize their infrastructure as code (IaC) workflows efficiently.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
I'm Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Team Foundation Server 2015 Installation Guide (SQL Express + Update 3)

Install Team Foundation Server 2015 using the original Microsoft download paths, with clear guidance for online, offline, and ISO-based setup. This revised guide also includes an installation workflow, command example, and practical pitfalls to avoid.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Host Your Own NuGet Feed: Local Source vs NuGet.Server vs NuGetGallery

Learn how to host a private NuGet feed using three practical approaches: a local folder source, NuGet.Server, and NuGetGallery. This revised guide includes setup steps, command examples, and a workflow diagram to help you choose the right model.

Read More

Publish NuGet Packages to NuGet.org: CLI Steps, Workflow, and CI Example

Learn how to publish a NuGet package to NuGet.org using either nuget.exe or the dotnet CLI. This revised guide includes a workflow diagram, command comparison, and a CI-friendly example.

Read More

How to Create NuGet Packages with nuget.exe (Assembly, .nuspec, and .csproj Methods)

Learn three practical ways to build NuGet packages using nuget.exe: from an existing assembly, from a convention-based folder layout, or directly from a Visual Studio project. This guide includes commands, folder conventions, token behavior, and common pitfalls.

Read More

Virtualization in DevOps: Using Vagrant, Docker, and Cloud Platforms Together

This guide explains how VM-based workflows, containers, and cloud platforms complement each other in DevOps. It includes a practical workflow, trade-off table, and command examples for day-to-day use.

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
0
Would love your thoughts, please comment.x
()
x