Terraform Most-Used Commands

FREE Terraform CLI AWS / Azure / GCP / Oracle Lite / Pro / Pro Plus coming soon

Terraform: FREE interactive emulator for AWS, Azure, GCP, and Oracle

Learn Terraform step by step with a visual learning-mode emulator. It includes guided challenges, a simulated terminal, infrastructure canvas output, and commands ready to copy or run.

40 explained Terraform commands

Use Copy to send the command to your clipboard or Run to load it into the emulator on this same page.

#CommandExplanationCopyRun
1terraform initInitializes the working directory and downloads required providers/modules.
2terraform init -upgradeUpgrades providers and modules while respecting version constraints.
3terraform init -backend=falseInitializes without configuring a remote backend; useful for local validation or CI.
4terraform fmtFormats .tf files using Terraform standard style.
5terraform fmt -recursiveFormats the current directory and all subdirectories.
6terraform validateValidates syntax, types and internal structure without creating resources.
7terraform validate -jsonReturns validation results as JSON for automated integrations.
8terraform planPreviews the changes Terraform would make to the infrastructure.
9terraform plan -out=tfplanSaves the plan so it can be applied later in a controlled way.
10terraform plan -destroyPreviews destruction of resources managed by the state.
11terraform plan -var="env=dev"Runs the plan using a variable passed from the command line.
12terraform plan -var-file="dev.tfvars"Runs the plan using variables from a tfvars file.
13terraform applyApplies proposed changes and creates, modifies or deletes resources.
14terraform apply tfplanApplies a plan previously saved with -out.
15terraform apply -auto-approveApplies without interactive approval; use only in labs or controlled CI/CD.
16terraform destroyDestroys infrastructure managed by the current state.
17terraform destroy -auto-approveDestroys without asking for confirmation; critical command to use carefully.
18terraform outputShows values defined in output blocks.
19terraform output -jsonShows outputs as JSON for integrations and scripts.
20terraform state listLists resources Terraform manages in the current state.
21terraform state show aws_instance.demoShows detailed attributes for one resource in state.
22terraform state mv old newRenames or moves a resource within state without recreating it.
23terraform state rm resourceRemoves a resource from state without deleting it from the real cloud.
24terraform import resource idImports an existing resource so Terraform can manage it.
25terraform refreshRefreshes state from provider data; newer workflows prefer plan/apply.
26terraform providersShows providers required by the configuration and modules.
27terraform providers lockGenerates or updates the provider lock file for repeatable runs.
28terraform versionShows the installed Terraform version and relevant provider versions.
29terraform consoleOpens an interactive console to evaluate Terraform expressions.
30terraform graphGenerates a DOT dependency graph between resources.
31terraform workspace listLists available workspaces.
32terraform workspace new devCreates a workspace to separate state by environment.
33terraform workspace select devSwitches to the dev workspace.
34terraform workspace showShows the active workspace.
35terraform taint resourceMarks a resource to be recreated on the next apply.
36terraform untaint resourceRemoves the taint mark from a resource.
37terraform loginLogs in to use Terraform Cloud or HCP Terraform.
38terraform logoutLogs out of the saved Terraform Cloud/HCP session.
39terraform testRuns native Terraform tests when test files exist.
40terraform modulesShows modules used by the configuration when supported by the CLI.

The emulator is educational: it does not request credentials, connect to real clouds, or create real resources.