Terraform Cheat Sheet

  1. terraform init: Initializes a new or existing Terraform working directory by downloading and installing any required providers and creates a new state file.
  2. terraform plan: Generates an execution plan for Terraform, showing what actions will be taken when the plan is applied. This command can be used to validate changes before actually applying them.
  3. terraform apply: Applies the changes to the infrastructure, creating, modifying, or deleting resources as necessary.
  4. terraform destroy: Destroys all the resources created by Terraform for the given configuration.
  5. terraform validate: Validates the configuration files, ensuring that they follow the syntax of HCL (HashiCorp Configuration Language).
  6. terraform state: Allows you to inspect the current state of your infrastructure.
  7. terraform refresh: Updates the state file to match the current state of the infrastructure.
  8. terraform output: Displays the output variables defined in the Terraform configuration.
  9. terraform import: Imports an existing resource into the Terraform state, allowing you to manage that resource using Terraform.
  10. terraform graph: Generates a visual representation of the Terraform configuration as a graph.
  11. terraform show: Displays the current state or plan in a human-readable format.
  12. terraform taint: Manually marks a resource as tainted, forcing it to be destroyed and recreated on the next apply.
  13. terraform workspace: Allows you to manage multiple workspaces, which are separate instances of a Terraform configuration.
  14. terraform providers: Lists the providers currently available to your Terraform configuration.
  15. terraform fmt: Formats the configuration files to ensure that they follow the Terraform style guide.
  16. terraform force-unlock: Releases a stuck lock on a particular state file, allowing Terraform to continue working on that file.
  17. terraform plan -destroy: Generates a plan specifically for destroying all the resources created by Terraform.
  18. terraform state pull: Retrieves the current state of the infrastructure from a remote backend.
  19. terraform state push: Pushes the local state to the remote backend, allowing it to be shared across multiple users.
  20. terraform state mv: Moves a resource within the state file to a new address, allowing you to reorganize your infrastructure configuration.