Skip to main content
This lesson walks through practical Terraform CLI features you’ll use every day: the built-in help system, command-specific help (for validate, plan, etc.), variable usage, and passing values with environment variables — including credentials used by providers.

Getting general help

To see Terraform’s built-in usage and global options, run:
This prints usage, primary subcommands, and global options. Example output (trimmed):
Note: Some legacy commands (for example taint/untaint) may still appear for backward compatibility; they are deprecated in favor of modern flags such as -replace on plan/apply.

Command-specific help

You can request help for any subcommand to see flags and usage details:
Example validate options:
terraform validate checks configuration syntax and internal references in the module. It does not contact providers or create resources; use it to catch common errors before planning or applying. terraform plan --help lists many plan customization options. Example (trimmed):
These built-in help pages are an authoritative and quick way to recall flags and behavior while you work.

Using Terraform variables and environment variables

Below is an example Terraform configuration that uses a numeric variable to control the length argument of two random_pet resources. The root output publishes the random_pet.name.id.
If you run terraform plan without setting num_of_pets, Terraform will prompt you:
To avoid interactive prompts, provide variables using one of Terraform’s supported methods. Common approaches: Environment variables prefixed with TF_VAR_ map directly to input variables in the root module. For example, to set num_of_pets:
Now running terraform plan uses that value and will not prompt:
Apply the plan (confirm with yes when prompted):
Sample apply output (trimmed):
If you change TF_VAR_num_of_pets (for example to 6) and re-run terraform apply, the length values will reflect that updated variable value.
Environment variables prefixed with TF_VAR_ map directly to input variables in your root module. This is a convenient way to provide non-sensitive values or CI/CD overrides without modifying configuration files.

Provider credentials and environment variables

Providers (AWS, Azure, GCP, Vault, and others) typically support environment variables as one of their authentication methods. Terraform provider plugins read those variables to authenticate and perform actions on the target platform. Example: AWS provider in your configuration:
Then in your shell set credentials:
For Vault you might set a token:
Terraform and the provider plugins will pick up these environment variables during operations. Each provider documents its supported environment variables and priority rules (see links below).
Do not store sensitive credentials in source-controlled files or expose them in logs. Use secure secret management (Vault, cloud secret stores, CI/CD secrets) and ephemeral credentials where possible.

Quick reference: common CLI flags and options

Summary

  • Use terraform --help and terraform <subcommand> --help to discover commands and flags quickly.
  • Variables can be supplied interactively, via -var/-var-file, or via environment variables (TF_VAR_<name>).
  • Provider credentials (AWS, Vault, etc.) are commonly supplied via environment variables; handle secrets securely.
  • The CLI help pages are authoritative and the fastest reference when working with Terraform.

Watch Video