Skip to main content
Navigation
HomeTechnical ReferenceJournalGitHubGitHub
Sidebar — toggle document categories via the logo
Categories

Terraform Overview

Terraform is an infrastructure-as-code tool for building, changing, and versioning cloud and on-premises resources safely and efficiently.

Core concepts

  • Providers — plugins that interact with cloud APIs (AWS, Azure, GCP, Kubernetes, etc.).
  • Resources — the infrastructure objects managed by Terraform (e.g., aws_instance, kubernetes_deployment).
  • State — a snapshot of managed resources stored in terraform.tfstate.
  • Modules — reusable, composable packages of Terraform configuration.
  • Workspaces — isolated state environments within the same configuration.

Common CLI commands

CommandPurpose
terraform initInitialize the working directory and download providers.
terraform planPreview changes before applying.
terraform applyApply the planned changes.
terraform destroyRemove all resources defined in the configuration.
terraform validateCheck configuration syntax and consistency.
terraform fmtFormat configuration files to canonical style.

State operations

OperationCommand
Show current stateterraform show
List resources in stateterraform state list
Move a resource in stateterraform state mv <source> <destination>
Remove a resource from stateterraform state rm <address>
Pull remote stateterraform state pull

Workspace commands

  • terraform workspace list — show available workspaces.
  • terraform workspace new <name> — create a new workspace.
  • terraform workspace select <name> — switch to an existing workspace.
  • terraform workspace delete <name> — remove a workspace.

Best practices

  • Store remote state in a shared backend with locking (S3, DynamoDB, Terraform Cloud, etc.).
  • Keep modules small, focused, and versioned.
  • Run terraform plan in CI before every apply.
  • Use variable validation and output descriptions.
  • Test infrastructure code with Terratest and OPA.

In-depth reference