Day 61- Terraform — Basic Commands

Radheya Zunjur
3 min readSep 5, 2023

Welcome to Day 61 of your journey into the world of Terraform! In today’s module, we will delve into the fundamental building blocks of Terraform by exploring its basic commands.

Terraform, a powerful Infrastructure as Code (IaC) tool, has gained immense popularity for its ability to simplify and automate the provisioning and management of infrastructure in a declarative manner. Whether you are a seasoned DevOps engineer or just beginning your IaC journey, mastering Terraform’s basic commands is an essential step towards harnessing its potential.

Task) Find purpose of basic Terraform commands which you’ll use often

1) terraform init

Purpose: Initializes a new or existing Terraform working directory by downloading provider plugins and modules defined in your configuration.

Example:

terraform init

We’ve created a variable.tf file on our ec2 instance.

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

2) terraform init -upgrade

Purpose: Performs the same initialization as terraform init but also upgrades installed provider plugins to their latest versions.

Example:

terraform init -upgrade

3) terraform plan

Purpose: Generates an execution plan based on your Terraform configuration, showing what changes would be made to your infrastructure without actually applying them.

Example:

terraform plan

4) terraform apply

Purpose: Applies the changes specified in the execution plan to your infrastructure, creating, modifying, or deleting resources as needed.

Example:

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 created. Means we have successfully configured terraform configuration file.

5) terraform validate

Purpose: Validates the syntax and configuration of your Terraform files, checking for errors and potential issues.

Example:

terraform validate

6) terraform fmt

Purpose: Automatically formats your Terraform configuration files to ensure consistent code style and readability.

Example:

terraform fmt

7) terraform destroy

Purpose: Destroys all the resources created by your Terraform configuration, effectively tearing down your infrastructure.

Example:

terraform destroy

These commands are essential for managing your infrastructure using Terraform. They help you initialize, plan, apply changes, validate configurations, format code, and destroy resources as needed in your infrastructure-as-code (IaC) workflow.

Also along with these tasks its important to know about Terraform in general-

Who are Terraform’s main competitors?

The main competitors are — Ansible, Packer, Cloud Foundry, Kubernetes

--

--

Radheya Zunjur

Database Engineer At Harbinger | DevOps | Cloud Ops | Technical Writer