Skip to main content

Workflow and CLI

Updated Jan 24, 2021 ·

Overview

Terraform work usually follows the same rhythm: write configuration, initialize the working directory, review the plan, apply the changes, and destroy the resources when they are no longer needed.

Common Workflow

StepCommandPurpose
Initializeterraform initDownloads providers and prepares the folder.
Formatterraform fmtRewrites configuration into standard style.
Validateterraform validateChecks syntax and internal consistency.
Planterraform planShows the changes Terraform intends to make.
Applyterraform applyCreates, updates, or removes resources.
Destroyterraform destroyRemoves resources managed by the state file.

For more details about each execution command, see Execution.

Workspaces

Workspaces let one configuration keep separate state for multiple environments.

To list all workspaces:

terraform workspace list

To create a new workspace,

terraform workpace new <name>

To select a workspace:

terraform workspace select <name>

Note: Workspaces separate state, but they do not automatically make a design production-ready. Keep environment naming, variables, and backend configuration clear.