Top 10 Terraform Commands Every Beginner Should Know

Terraform has quickly become the go-to tool for provisioning and managing cloud infrastructure using Infrastructure as Code (IaC). But for beginners, getting comfortable with the Terraform CLI (Command Line Interface) is the first major step toward becoming proficient.

Here’s a breakdown of the top 10 Terraform commands every new Terraform user must know, along with what they do and when to use them.

1. terraform init

Initializes your Terraform working directory with the required provider plugins.

✅ Use it when:

  • You’re setting up a new project
  • You add/update providers or modules
terraform init

2. terraform plan

Creates an execution plan and shows you what changes will occur without actually applying them.

✅ Use it for:

  • Reviewing changes before deployment
  • Ensuring safety in critical environments
terraform plan

3. terraform apply

Applies the changes required to reach the desired state of the configuration.

✅ Use it after reviewing the plan to provision/update infrastructure.

terraform apply

4. terraform destroy

Destroys the infrastructure created by Terraform.

⚠️ Use cautiously, especially in production!

terraform destroy

5. terraform validate

Checks your Terraform configuration for syntax errors.

✅ Use it during development or in CI pipelines for early error detection.

terraform validate

6. terraform fmt

Formats Terraform files to the canonical style.

✅ Keeps code clean and consistent, especially in teams.

terraform fmt

7. terraform output

Extracts and displays the values of outputs defined in your configuration.

✅ Use it to fetch outputs like VPC ID, public IPs, etc.

terraform output

8. terraform state list

Lists all resources tracked in the Terraform state.

✅ Helpful for debugging or understanding what Terraform is managing.

terraform state list

9. terraform taint

Marks a resource for recreation during the next apply.

✅ Use when a specific resource needs to be rebuilt.

terraform taint aws_instance.example

10. Terraform Refresh (Legacy, use with caution)

Updates the state file with real-time resource values.

⚠️ In Terraform 1.0+, this is discouraged in favor of terraform apply.

terraform refresh

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *