Organization: motoshare | Project: proezi | Workspaces: proezi_dev, proezi_stage, proezi_prod
1. Terraform CLI — Complete Command Reference
| Category | Command | Purpose / Usage |
|---|---|---|
| Installation | terraform version | Check installed Terraform version |
| Help | terraform -help | List available commands |
| Help | terraform plan -help | View usage and options for a specific command |
| Authentication | terraform login | Authenticate with HCP Terraform |
| Authentication | terraform logout | Remove locally saved HCP credentials |
| Initialization | terraform init | Initialize configuration, providers, modules, and HCP workspace connection |
| Initialization | terraform init -upgrade | Upgrade providers and modules within configured version constraints |
| Initialization | terraform init -reconfigure | Reinitialize cloud/backend configuration |
| Initialization | terraform init -migrate-state | Migrate Terraform state to another backend |
| Formatting | terraform fmt | Format Terraform configuration |
| Formatting | terraform fmt -recursive | Format Terraform files recursively |
| Formatting | terraform fmt -check | Check formatting without modifying files |
| Validation | terraform validate | Validate configuration syntax and structure |
| Planning | terraform plan | Preview infrastructure changes |
| Planning | terraform plan -var="replicas=3" | Override an input variable for a run |
| Planning | terraform plan -var-file=dev.tfvars | Use a specific variable file |
| Planning | terraform plan -out=tfplan | Save a plan for later review and apply |
| Planning | terraform plan -detailed-exitcode | Return 0 = no changes, 1 = error, 2 = changes |
| Planning | terraform plan -refresh-only | Preview updates to state based on actual infrastructure |
| Planning | terraform plan -replace=aws_instance.web | Plan replacement of a specific resource |
| Planning | terraform plan -target=aws_instance.web | Plan changes for a targeted resource and dependencies |
| Apply | terraform apply | Execute Terraform changes |
| Apply | terraform apply -auto-approve | Apply without interactive confirmation |
| Apply | terraform apply tfplan | Apply a previously saved plan |
| Apply | terraform apply -refresh-only | Update state to reflect actual infrastructure |
| Destroy | terraform plan -destroy | Preview resource destruction |
| Destroy | terraform destroy | Destroy managed infrastructure in the selected state |
| Destroy | terraform destroy -target=aws_instance.web | Target a resource for destruction |
| State | terraform state list | List resources in Terraform state |
| State | terraform state show aws_instance.web | Show details of one tracked resource |
| State | terraform state pull | Retrieve state from HCP Terraform |
| State | terraform state mv OLD NEW | Move or rename a resource address in state |
| State | terraform state rm ADDRESS | Remove resource tracking without destroying the object |
| State | terraform state replace-provider OLD NEW | Replace provider references within state |
| Import | terraform import ADDRESS ID | Import existing infrastructure into Terraform state |
| Locking | terraform force-unlock LOCK_ID | Release a stuck state lock where supported |
| Workspace | terraform workspace list | List available workspaces |
| Workspace | terraform workspace show | Display currently selected workspace |
| Workspace | terraform workspace select proezi_dev | Select an existing workspace where supported |
| Workspace | terraform workspace new demo | Create a new workspace where supported |
| Workspace | terraform workspace delete demo | Delete an eligible workspace |
| Outputs | terraform output | Display Terraform outputs |
| Outputs | terraform output -json | Display outputs in JSON format |
| Outputs | terraform output -raw app_name | Retrieve an output as a raw string |
| Inspection | terraform show | Display current state information |
| Inspection | terraform show tfplan | Display a saved execution plan |
| Inspection | terraform show -json tfplan | Display a saved plan as JSON |
| Providers | terraform providers | List provider dependencies |
| Modules | terraform get | Download modules; terraform init is generally preferred |
| Console | terraform console | Test Terraform expressions interactively |
| Graph | terraform graph | Generate an infrastructure dependency graph |
| Testing | terraform test | Run Terraform configuration tests |
| Directory | terraform -chdir=dev plan | Execute a command inside a selected directory |
2. Terraform Cloud Environment Variables
| Variable / Command | Purpose |
|---|---|
export TF_TOKEN_app_terraform_io="$TFC_TOKEN" | Authenticate to HCP Terraform using an API token |
export TF_WORKSPACE=proezi_dev | Select an existing workspace when the cloud configuration supports selection |
export TF_VAR_replicas=3 | Supply a Terraform input variable |
export TF_LOG=DEBUG | Enable detailed Terraform CLI logging |
export TF_LOG_PATH=terraform.log | Save diagnostic logs to a file |
export TF_IN_AUTOMATION=true | Adjust CLI output for automation |
terraform plan -input=false | Disable interactive input |
terraform apply -input=false | Disable interactive input during apply |
unset TF_VAR_replicas | Remove the shell variable override |
3. HCP Terraform REST API — Command Summary
These are API operations executed using curl, not built-in terraform subcommands.
Base URL:
https://app.terraform.io/api/v2
| Operation | Method | API endpoint |
|---|---|---|
| List organization workspaces | GET | /organizations/motoshare/workspaces |
| Get Dev workspace details | GET | /organizations/motoshare/workspaces/proezi_dev |
| Get Stage workspace details | GET | /organizations/motoshare/workspaces/proezi_stage |
| Get Prod workspace details | GET | /organizations/motoshare/workspaces/proezi_prod |
| Create workspace | POST | /organizations/motoshare/workspaces |
| Update workspace | PATCH | /workspaces/:workspace_id |
| List workspace variables | GET | /workspaces/:workspace_id/vars |
| Create workspace variable | POST | /workspaces/:workspace_id/vars |
| Update workspace variable | PATCH | /workspaces/:workspace_id/vars/:variable_id |
| Delete workspace variable | DELETE | /workspaces/:workspace_id/vars/:variable_id |
| List workspace runs | GET | /workspaces/:workspace_id/runs |
| Create a run | POST | /runs |
| Get run details | GET | /runs/:run_id |
| Apply a run | POST | /runs/:run_id/actions/apply |
| Lock workspace | POST | /workspaces/:workspace_id/actions/lock |
| Unlock workspace | POST | /workspaces/:workspace_id/actions/unlock |
| Safely delete empty workspace | POST | /workspaces/:workspace_id/actions/safe-delete |
Example — List all workspaces in motoshare:
curl -fsS \
-H "Authorization: Bearer $TFC_TOKEN" \
"https://app.terraform.io/api/v2/organizations/motoshare/workspaces" \
| jq -r '.data[].attributes.name'
4. Most Important Commands for Daily DevOps Work
| Step | Command | When to use |
|---|---|---|
| 1 | terraform login | First-time HCP authentication |
| 2 | terraform init | Initialize a working directory |
| 3 | terraform fmt -check | Check code formatting |
| 4 | terraform validate | Validate configuration |
| 5 | terraform plan | Review proposed changes |
| 6 | terraform plan -out=tfplan | Save an executable plan |
| 7 | terraform show tfplan | Review the saved plan |
| 8 | terraform apply tfplan | Apply the approved plan |
| 9 | terraform output | View infrastructure outputs |
| 10 | terraform state list | Inspect tracked resources |
| 11 | terraform workspace show | Confirm the selected workspace |
| 12 | terraform plan -refresh-only | Check for external infrastructure changes |
Critical HCP Terraform rules: With a fixed cloud.workspaces.name, you cannot switch between Dev, Stage, and Prod using terraform workspace select. Remote VCS-driven workspaces also do not support applying local configurations directly with terraform apply. Saved remote plans require a supported CLI version (Terraform 1.6+) and must be applied in their originating workspace.
For your motoshare organization, I recommend keeping CLI experimentation in a dedicated lab workspace and using reviewed plans and protected approval workflows for proezi_prod.