top of page

Terraform Command Cheat Sheet

Updated: Jun 10, 2023

Terraform commands are used to manage and provision infrastructure using code. They are used to perform various tasks such as creating, updating, and destroying resources, managing the state, and more.

Here is a summary of the most commonly used Terraform commands:

  1. terraform init - Initializes a Terraform working directory by downloading provider plugins and setting up the backend for storing state.

  2. terraform plan - Generates and shows an execution plan for the Terraform code in the current directory. It's used to preview the resources that will be created, updated or deleted before applying the changes.

  3. terraform apply - Applies the changes required to reach the desired state of the configuration, or the previously generated plan.

  4. terraform show - Shows the state or plan file in a human-readable format.

  5. terraform destroy - Destroys the Terraform-managed infrastructure.

  6. terraform import - Import existing infrastructure into your Terraform state.

  7. terraform fmt - Automatically formats the Terraform configuration files in a consistent style.

  8. terraform validate - Validate the syntax of the Terraform files.

  9. terraform output - Reads an output from a Terraform state file and prints its value.

  10. terraform refresh - Update local state file against real resources, it's used to synchronize the state file with the current infrastructure.

Additionally, Terraform also provides a set of advanced commands such as terraform graph, terraform taint, terraform force-unlock and terraform state which is used for more specific tasks and troubleshooting.

It's also important to note that these are just a few of the available commands, and there are many others that can be used for specific tasks such as debugging, testing and more. It's always recommended to refer to the Terraform documentation for more information on the available commands and their usage.

32 views0 comments

Recent Posts

See All

How to secure your AWS account .

Securing your AWS account is crucial to protect your data and resources from potential threats. Amazon Web Services (AWS) provides a wide range of security features that can help you secure your accou


bottom of page