Have you ever worked with Terraform?
For those working in DevOps and Cloud Computing, Terraform can be a very important tool for Infrastructure as Code (IaC).
Thatβs why I created this cheat sheet with the essential Terraform commands every professional should know by heart.
Basic workflow (most important commands):
Check and Apply (Create/Change resources):
terraform init: Initializes your working directory and configures the backend for new and existing projects.
terraform plan: Generates the execution plan, showing which resources will be created or changed in the infrastructure.
terraform apply: Applies the planned changes to build your infrastructure and deploy the resources.
Check and Manage:
terraform validate: Checks the code for errors to ensure your configuration is syntactically correct.
terraform show & terraform state: Display the current Terraform state in a readable format and allow you to inspect, list, and manipulate resources directly in the state file. Essential for understanding the current state of your infrastructure.
Destroy your deployment:
terraform destroy: Removes all resources managed by Terraform. Be careful with this command! π
Command explanations:
terraform init β Initializes the project by downloading providers and configuring the backend.
terraform plan β Shows what will be created, changed, or destroyed before applying.
terraform apply β Applies the changes defined in the Terraform code.
terraform show β Displays the current state or plan in a readable format.
terraform destroy β Removes all resources managed by Terraform.
terraform validate β Validates the syntax and structure of Terraform files.
terraform output β Shows the output values defined in the state.
terraform state β Allows you to inspect and manipulate the state file.
terraform fmt β Formats Terraform files according to the official style.
terraform graph β Generates a graph of dependencies between resources.
terraform import β Imports existing resources into the Terraform state.
terraform refresh β Updates the state with what exists in the real environment.
terraform taint β Marks a resource to be recreated on the next apply.
terraform untaint β Removes the recreation mark from a resource.
Thatβs all, folks!
I hope this cheat sheet helps you remember the commands and better understand the IaC lifecycle with Terraform.

Top comments (0)