Getting CLI help
Open a terminal in your working directory and request top-level help to see global usage and available subcommands:
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)
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:
Notes:
- Use
-outif you want to guarantee thatapplyperforms the same actions as planned. - Prefer
-var-fileor 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 theTF_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:
terraform plan will now use that value without prompting:
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):
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 --helpandterraform <subcommand> --helpto discover commands, flags, and usage examples. terraform plansupports many customization flags (-replace,-target,-var,-var-file,-out); use-outwhen 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.
- Terraform CLI documentation: https://www.terraform.io/docs/cli
- Terraform Providers: https://registry.terraform.io/browse/providers
- AWS provider docs: https://registry.terraform.io/providers/hashicorp/aws/latest/docs
- HashiCorp Vault: https://www.vaultproject.io/docs