Skip to main content
This concise guide walks through practical Terraform CLI features: built-in help, command-specific help, plan customization flags, and using environment variables both to set Terraform variables and to provide provider credentials. Keep this as a quick reference while working with Terraform locally or in CI. Minimal Terraform example (we’ll use this throughout)

Getting CLI help

Open a terminal in your working directory and request top-level help to see global usage and available subcommands:
Common and advanced commands (excerpt) Further down in the full help output you’ll also find less-common and deprecated commands (for example, taint and untaint were deprecated in favor of flags such as -replace). Global options (use these before the subcommand)
Request help for any specific subcommand:
This prints what the subcommand does and all supported flags (for example, validate documents JSON output and color control flags). Callout: subcommand help
You can get help for any subcommand (for example, terraform plan --help) to see detailed options, examples, and usage notes.

Deep dive: terraform plan

terraform plan generates a speculative execution plan showing what Terraform would do to bring infrastructure in line with the configuration. It does not perform any changes unless you later pass a saved plan file to apply. Example help excerpt:
Plan customization flags — quick reference Notes:
  • Use -out if you want to guarantee that apply performs the same actions as planned.
  • Prefer -var-file or environment variables in CI to avoid leaking secrets in shell history.

Passing Terraform variables via environment

Terraform supports setting input variables from the environment using the TF_VAR_<variable_name> pattern. For the example above, set TF_VAR_num_of_pets to provide num_of_pets from the environment. If you run terraform plan without supplying num_of_pets, Terraform will prompt:
Set the variable in a POSIX shell (macOS / Linux):
Rerunning terraform plan will now use that value without prompting:
If you change TF_VAR_num_of_pets to another number (for example 6), resources depending on var.num_of_pets will reflect the new value on the next plan or apply. Callout: using TF_VAR_ environment variables
Use TF_VAR_<variable_name> to inject Terraform variable values from the environment. Example: export TF_VAR_num_of_pets=3. This is useful in CI/CD pipelines and local scripts.

Environment variables for provider authentication

Provider SDKs typically read standard environment variables for authentication. These are provider-specific and are not Terraform-level variables. Common provider authentication environment variables: AWS example (POSIX shell):
And an AWS provider block in HCL:
Terraform will use the environment variables above to authenticate with AWS during plan or apply. Callout: protect credentials
Never commit credentials, tokens, or secret keys to version control. Use secure secrets management, environment injection in CI/CD, or a secrets backend (e.g., HashiCorp Vault) instead of hardcoding secrets in files.

Summary and quick checklist

  • Use terraform --help and terraform <subcommand> --help to discover commands, flags, and usage examples.
  • terraform plan supports many customization flags (-replace, -target, -var, -var-file, -out); use -out when you need a reproducible apply step.
  • Supply Terraform input variables via the environment using TF_VAR_<variable_name> for automation-friendly workflows.
  • Provider authentication commonly relies on provider-specific environment variables (for example, AWS and Vault); consult provider docs for exact variable names.
  • Never store secrets in source control—use secure vaults or platform-managed secret injection.
Further reading and references That’s it — a compact, practical walkthrough of helpful Terraform CLI commands, plan options, and environment-based variable and credential patterns.

Watch Video