DEV Community

Cover image for Terraform Commands Every Cloud Engineer Should Know
Joseph Ibeh
Joseph Ibeh

Posted on

2 1 1 1 1

Terraform Commands Every Cloud Engineer Should Know

Infrastructure as Code (IaC) has revolutionized the way cloud environments are managed, and Terraform stands out as one of the most popular IaC tools today. Whether you're provisioning compute resources, managing storage, or automating networking setups, Terraform provides a consistent and powerful CLI experience.

In this article, I'll walk you through essential Terraform commands every Cloud Engineer should know—especially if you're just getting started or want a solid foundation for managing infrastructure efficiently.


1. terraform init

terraform init
Enter fullscreen mode Exit fullscreen mode

This is the first command you run when starting a new Terraform configuration. It initializes the working directory, downloads the required provider plugins, and prepares your project for further actions.

Use it when:

  • You clone a new Terraform repo
  • You add/change providers
  • You're setting up a new module

2. terraform validate

terraform validate
Enter fullscreen mode Exit fullscreen mode

This command checks your configuration files for syntax errors and ensures they're internally consistent.

Think of it as your syntax checker.


3. terraform plan

terraform plan
Enter fullscreen mode Exit fullscreen mode

This is your preview command. It shows what actions Terraform will take to reach the desired state, without actually making any changes.

Why it's important:

  • Avoid unintended resource changes
  • Review planned changes with your team

4. terraform apply

terraform apply
Enter fullscreen mode Exit fullscreen mode

This command executes the changes outlined in the plan. You’ll be prompted to approve before any infrastructure is provisioned or updated.

You can auto-approve using:

terraform apply -auto-approve
Enter fullscreen mode Exit fullscreen mode

Pro tip: Avoid using -auto-approve in production unless you really know what you're doing.


5. terraform destroy

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Need to tear down everything? This command removes all infrastructure created by Terraform. Use with caution!


6. terraform output

terraform output
Enter fullscreen mode Exit fullscreen mode

Displays the values of output variables from your configuration. This is useful for retrieving endpoints, resource IDs, and other important data post-deployment.


7. terraform fmt

terraform fmt
Enter fullscreen mode Exit fullscreen mode

Automatically formats your Terraform code according to standard conventions. This keeps your code clean, readable, and consistent across teams.


8. terraform show

terraform show
Enter fullscreen mode Exit fullscreen mode

Want to inspect your Terraform state? This command gives you a human-readable view of what's currently managed in your state file.


9. terraform state

terraform state list
Enter fullscreen mode Exit fullscreen mode

Manage the current state of your resources. You can list, pull, move, or remove resources directly from the state file—but this command is powerful and risky, so use with understanding.


10. terraform taint

terraform taint <resource_name>
Enter fullscreen mode Exit fullscreen mode

Marks a specific resource for destruction and recreation during the next apply. Useful when a resource is in a bad state and you want to force a rebuild.


Bonus: terraform import

terraform import <resource_type.resource_name> <resource_id>
Enter fullscreen mode Exit fullscreen mode

This command lets you bring existing infrastructure under Terraform management. It doesn’t generate the code for you, but it links the resource to your state file.


Final Thoughts

Mastering these Terraform commands is a game-changer for any cloud engineer. They form the core toolkit for managing, updating, and troubleshooting infrastructure as code. Whether you're deploying your first EC2 instance or managing multi-cloud environments, these commands will make your work efficient and reliable.


Got more Terraform tips or favorite commands?

Drop them in the comments—I’d love to hear from fellow DevOps and Cloud Engineering enthusiasts!

DevCycle image

Fast, Flexible Releases with OpenFeature Built-in

Ship faster on the first feature management platform with OpenFeature built-in to all of our open source SDKs.

Start shipping

Top comments (0)

ITRS image

See What Users Experience in The Browser — Anywhere, Anytime

Simulate logins, checkouts, and payments on SaaS, APIs, and internal apps. Catch issues early, baseline web performance, and stay ahead of incidents. Easily record user journeys right from your browser.

Start Free Trial

👋 Kindness is contagious

Delve into a trove of insights in this thoughtful post, celebrated by the welcoming DEV Community. Programmers of every stripe are invited to share their viewpoints and enrich our collective expertise.

A simple “thank you” can brighten someone’s day—drop yours in the comments below!

On DEV, exchanging knowledge lightens our path and forges deeper connections. Found this valuable? A quick note of gratitude to the author can make all the difference.

Get Started