Skip to main content

Command Palette

Search for a command to run...

Day 61 - Terraform Command🔥

Updated
•2 min read

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

Now run terraform init

  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:
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:
terraform plan

This will tell you what will be created?

  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

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

     terraform validate
    

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

  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

After terraform destroy command:

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

More from this blog

Ajay Patel

116 posts

Day 61 - Terraform Command🔥