# Day 61 - Terraform Command🔥

In today's blog, we will explore some of the fundamental Terraform commands that you'll frequently use to manage your infrastructure as code. These commands lay the foundation for efficient provisioning, modification, and destruction of resources using Terraform. Let's dive in!

1. `terraform init`  
    This command initializes a new or existing Terraform configuration in your working directory. It downloads necessary provider plugins and sets up the environment for Terraform operations. Think of it as a setup phase that prepares your infrastructure project.
    

we will understand by example : we will create a file using terraform . create a `create_file.tf` using vim

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687745525001/85d80f8f-2b0f-4854-9f49-c4cacd69a1e3.png align="center")

Now run `terraform init`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687745662693/478329d4-4d26-4066-96f0-8a059a45921c.png align="center")

1. `terraform init -upgrade`: Adding the `-upgrade` flag to `terraform init` ensures that Terraform attempts to upgrade provider plugins to their latest versions. For example:
    

```bash
terraform init -upgrade
```

1. `terraform plan`: This command generates an execution plan by comparing the desired state (as defined in your Terraform configuration) with the current state (as tracked by Terraform). For example:
    

```bash
terraform plan
```

This will tell you what will be created?

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687745811749/8fdac4be-dffa-4f91-aaa6-8a4cfcdd0528.png align="center")

1. `terraform apply`: Applying the changes to your infrastructure is done using the `terraform apply` command. For example:
    

It will create a file in our example

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687745948959/98d6adba-2170-4bd0-91f0-c82004c5b9c6.png align="center")

1. `terraform validate`: Use this command to validate the syntax and configuration of your Terraform files. For example:
    
    ```bash
    terraform validate
    ```
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687746024802/167089a5-030c-47fa-ae1d-f6510ebe71e8.png align="center")

1. `terraform fmt`: Terraform's `fmt` command automatically formats your Terraform files to follow a consistent style.
    

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687746107293/f2ba3bf1-da89-4c19-bc93-41a545e607e3.png align="center")

1. `terraform destroy`: When you no longer need your infrastructure, the `terraform destroy` command tears down all the resources created by your Terraform configuration. For example:
    

before terraform destroy

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687746282313/1fc5b563-dab6-40a7-96ec-0c89c622c094.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687746175717/19cf60e2-6b8d-452f-8e09-c53d76a32f69.png align="center")

After terraform destroy command:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1687746298738/d91f1757-093b-4ad1-b25d-2133852f69d4.png align="center")

That was all for today. see you another day with another project.
