- Write — declare the infrastructure you want using configuration files (HCL).
- Plan — preview what Terraform will change by comparing your configuration to the current state.
- Apply — execute those changes to create or update real infrastructure, with Terraform resolving resource dependencies automatically.

terraform init is a required setup step for each new project directory and whenever you add or change provider/module blocks.
Always run
terraform init when you start working in a new Terraform project or after adding new provider/module references. Without initialization, terraform plan and terraform apply will fail.
- Write your configuration files (.tf) in HCL to declare the desired state.
- Initialize the directory: run
terraform init. - Preview changes: run
terraform plan. - Apply changes: run
terraform apply.
| Stage | Purpose | Typical command |
|---|---|---|
| Initialize | Download providers/modules and prepare the working directory | terraform init |
| Plan | Compare configuration against current state and preview changes | terraform plan |
| Apply | Execute changes to reach the desired state | terraform apply |
| Write | Create or modify .tf files (HCL) to declare intended resources | edit .tf files |
.tf files describing the desired state. The key principle is declarative configuration: you describe the end state you want, and Terraform determines API calls and operation order to achieve that state.
Best practices and workflow tips
- Start small: create a minimal resource (for example, a single VM or instance) and iterate.
- Iterate frequently: after each change, run
terraform planandterraform applyto converge toward the desired state. - Keep state and sensitive data secure: use remote state backends (e.g., S3, Azure Storage, or Terraform Cloud) and avoid embedding secrets in plain text.
- Group related resources into modules for reusability and organization.
