Skip to main content
Welcome to the Terraform CLI overview. The Terraform command-line interface (CLI) is the core tool for defining, provisioning, and managing infrastructure as code. It provides a consistent, provider-agnostic set of commands that work with AWS, Azure, GCP, on-premises systems, and many third-party services. Because the CLI workflow is the same across providers and operating systems (Linux, Windows, macOS), teams can adopt Terraform more quickly and reduce operational friction. This section introduces the essential Terraform commands you will use to create, review, and safely apply infrastructure changes. You’ll learn how these commands interact with one another, when to use each, and how they help you maintain predictable, repeatable infrastructure states.
The image shows a person speaking, with text saying "Using the Terraform CLI" on a purple background, suggesting it is a lecture on the topic.
Core objectives covered in this section:
  • Understand the Terraform CLI workflow from initialization to destruction.
  • Learn the purpose and typical usage of core commands: init, validate, plan, apply, destroy, and state management commands.
  • Learn best practices for safely reviewing and applying changes, managing remote state, and working with modules and workspaces.
Tip: Treat the CLI as your single source of truth for executing infrastructure changes. Combine careful use of terraform plan with remote state locking to avoid race conditions in team environments.
Essential Terraform CLI commands and their primary use cases:
CommandPurposeTypical example
terraform initInitialize a working directory, download providers and modules, and configure the backend.terraform init
terraform validateValidate configuration syntax and internal consistency.terraform validate
terraform fmtReformat configuration files to canonical style.terraform fmt
terraform planCreate an execution plan showing proposed changes without applying them.terraform plan -out=plan.tfplan
terraform applyApply the changes required to reach the desired state. Accepts a saved plan: terraform apply plan.tfplan.terraform apply
terraform destroyDestroy all resources defined in the configuration.terraform destroy
terraform stateInspect and modify the Terraform state. Useful for advanced state corrections.terraform state list
terraform outputRead outputs from the state.terraform output -json
terraform importImport existing resources into state.terraform import aws_instance.example i-1234567890abcdef0
terraform taint / untaintMark/unmark resources for recreation on next apply (legacy; prefer terraform apply -replace).terraform taint aws_instance.example
Warning: Avoid editing the Terraform state file directly. Use terraform state subcommands or remote state features (backends) to prevent corruption and ensure team safety.
Recommended CLI workflow (typical sequence):
  1. terraform init — set up the directory and backend.
  2. terraform validate and terraform fmt — ensure configuration quality.
  3. terraform plan -out=plan.tfplan — generate a reviewable plan.
  4. Review the plan carefully, then terraform apply plan.tfplan — apply changes.
  5. Use terraform output to retrieve values and terraform state to inspect state as needed.
  6. When decommissioning resources, use terraform destroy with caution.
Further reading and references: With this overview, you’re ready to dive into each command in detail. Next, we’ll look at how to initialize projects and configure backends for secure remote state management.

Watch Video