Important Terraform Commands

This is Day 61 of #90daysofdevops challenge

Important Terraform Commands

Hope you've already got the gist of What Working with Terraform would be like. Let's begin with day 2 of Terraform!

Task: Find the purpose of basic Terraform commands which you'll use often.

1) terraform init:- This initializes Terraform and downloads any necessary providers. It must be run before most other commands.

  • Command:
terraform init

-> Let's create a test.tf file in our EC2 instance and run the commands:

resource "local_file" "devops" {
 filename = "/home/ubuntu/terraform/first_file.txt"
 content = "this is my file"
}

  • Now, run the above command...

2) terraform init -upgrade:- Upgrades Terraform to the latest version.

  • Command:
terraform init -upgrade

3) terraform plan:- Generates an execution plan to show what Terraform would do if you ran apply. This allows you to preview the changes.

  • Command:
terraform plan

4) terraform apply:- Applies the changes required to reach the desired state specified in the configuration files.

  • Command:
terraform apply

We have applied the terraform, Let’s check if the file is created in our /home/ubuntu/terraform directory

Our file has been successfully created.

5) terraform validate:- Validates the configuration files and checks for syntax errors.

  • Command:
terraform validate

6) terraform fmt:- Formats the configuration files to follow the Hashicorp style guide.

  • Command:
terraform fmt

7) terraform destroy:- Destroys all the resources managed by Terraform that were created with apply.

  • Command:
terraform destroy

In summary:

  • init initializes Terraform and downloads providers

  • plan previews the changes

  • apply applies the changes to create/update infrastructure

  • validate checks for syntax errors

  • fmt formats the configuration files

  • destroy deletes all resources created by Terraform

Who are Terraform’s main competitors?

The main competitors of Terraform are:

  • Ansible - For configuration management

  • Packer - For infrastructure templates and images

  • Cloud Foundry - For PaaS deployment

  • Kubernetes - For container orchestration


"Thank you for enjoying my DevOps blog! Your positive response fuels my passion to dive deeper into technology and innovation.

Stay tuned for more captivating DevOps articles, where we'll explore this dynamic field together. Follow me on Hashnode and connect on LinkedIn (https://www.linkedin.com/in/som-shanker-pandey/) for the latest updates and discussions.

Did you find this article valuable?

Support Som Pandey's blog by becoming a sponsor. Any amount is appreciated!