DEV Community

Gias Uddin
Gias Uddin

Posted on

Terraform Basic Commands: A Quick Guide

Terraform Basic Commands: A Quick Guide

Terraform is an open-source tool that allows you to manage infrastructure as code across various cloud providers. Here’s a brief overview of the essential Terraform commands every DevOps engineer should know:

1. terraform init

  • Purpose: Initializes a Terraform working directory by downloading necessary plugins and setting up the backend.
  • Usage: terraform init

2. terraform fmt

  • Purpose: Formats Terraform configuration files for consistency.
  • Usage: terraform fmt

3. terraform validate

  • Purpose: Validates the syntax and consistency of your configuration files.
  • Usage: terraform validate

4. terraform plan

  • Purpose: Creates an execution plan, showing the changes Terraform will make to your infrastructure.
  • Usage: terraform plan

5. terraform apply

  • Purpose: Applies the changes required to reach the desired state of the configuration.
  • Usage: terraform apply

6. terraform destroy

  • Purpose: Destroys all the resources defined in your configuration, effectively tearing down your infrastructure.
  • Usage: terraform destroy

7. terraform show

  • Purpose: Displays the current state or details of a saved plan.
  • Usage: terraform show

8. terraform state

  • Purpose: Manages Terraform’s state, including listing and modifying resources.
  • Usage: terraform state <subcommand>

9. terraform refresh

  • Purpose: Updates the state file with the real infrastructure’s current state.
  • Usage: terraform refresh

10. terraform import

  • Purpose: Imports existing resources into Terraform's state.
  • Usage: terraform import <resource_type>.<resource_name> <resource_id>

11. terraform output

  • Purpose: Retrieves the value of output variables from your configuration.
  • Usage: terraform output

12. terraform workspace

  • Purpose: Manages multiple workspaces, allowing you to handle different environments.
  • Usage: terraform workspace <subcommand>

These commands form the core of Terraform operations, enabling you to efficiently manage your cloud infrastructure with confidence.

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay