DEV Community

Kshitij Sharma
Kshitij Sharma

Posted on

Day 1 of #TerraWeek β€” From Zero to First `terraform init`

🌱 TerraWeek Challenge – Day 1

Introduction to Infrastructure as Code (IaC) & Terraform Basics

πŸ“… Date: 12 July 2026

Welcome to Day 1 of my TerraWeek Challenge! πŸš€

Today was all about understanding Infrastructure as Code (IaC), learning the fundamentals of Terraform, and provisioning my first resource locally. Although the project itself was simple, it helped me understand the workflow that powers modern infrastructure automation.


🎯 Learning Objectives

By the end of Day 1, I was able to:

  • Understand what Infrastructure as Code (IaC) is.
  • Learn why Terraform is one of the most popular IaC tools.
  • Install and configure Terraform.
  • Learn Terraform's core workflow.
  • Understand important Terraform concepts.
  • Create and destroy my first infrastructure.
  • Explore OpenTofu and Terraform's lock file.

πŸ“– Why Infrastructure as Code?

Before writing any Terraform configuration, I wanted to understand why Infrastructure as Code exists.

Managing cloud infrastructure manually through a web console may work for a personal project, but it quickly becomes difficult as projects grow.

Some common problems with manual infrastructure are:

  • Human errors while configuring resources.
  • Difficulty recreating the exact same environment.
  • Poor collaboration among teams.
  • No version history for infrastructure changes.
  • Slow deployments.

Infrastructure as Code solves these problems by allowing infrastructure to be written, reviewed, and version-controlled just like application code.

Instead of remembering every click in a cloud console, everything is defined inside configuration files that can be executed repeatedly.


🌍 What is Terraform?

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp.

It uses HashiCorp Configuration Language (HCL) to describe the desired infrastructure, and Terraform automatically determines the changes required to reach that desired state.

One of Terraform's biggest strengths is that it is provider agnostic, meaning the same tool can manage resources across:

  • AWS
  • Azure
  • Google Cloud
  • Docker
  • Kubernetes
  • GitHub
  • Cloudflare
  • DigitalOcean
  • VMware
  • Hundreds of other providers

⭐ Why Terraform?

Terraform has become one of the industry's most widely adopted Infrastructure as Code tools because it offers:

  • Declarative configuration
  • Multi-cloud support
  • Huge provider ecosystem
  • State management
  • Reusable modules
  • Version-controlled infrastructure
  • Easy CI/CD integration

βš–οΈ Terraform vs Alternatives

Tool Comparison
Terraform Multi-cloud Infrastructure as Code using HCL
OpenTofu Community-driven open-source fork of Terraform
Pulumi Uses programming languages like Python and Go instead of HCL
CloudFormation AWS-only Infrastructure as Code service
Ansible Primarily used for configuration management rather than provisioning infrastructure

πŸ›  Installing Terraform

The first practical step was installing the latest version of Terraform.

After installation, I verified everything using:

terraform version
terraform -help
Enter fullscreen mode Exit fullscreen mode

Terraform Version


Terraform Help


VS Code Extension

To improve the development experience, I installed the official HashiCorp Terraform Extension.

Features include:

  • Syntax Highlighting
  • IntelliSense
  • Auto Completion
  • Formatting
  • Validation

Screenshot

πŸ“˜ Important Terraform Terminologies

Before creating any infrastructure, I learned the six core concepts that form the foundation of every Terraform project.

Provider

A provider is a plugin that allows Terraform to communicate with a specific platform.

Example:

provider "aws" {
  region = "ap-south-1"
}
Enter fullscreen mode Exit fullscreen mode

Resource

A resource represents any infrastructure object managed by Terraform.

Example:

resource "local_file" "example" {
  filename = "hello.txt"
  content  = "Hello Terraform"
}
Enter fullscreen mode Exit fullscreen mode

State

Terraform stores information about all managed resources inside a file named:

terraform.tfstate
Enter fullscreen mode Exit fullscreen mode

The state file allows Terraform to understand what already exists and what changes need to be made.


Plan

Before applying any changes, Terraform generates an execution plan showing exactly what will happen.

terraform plan
Enter fullscreen mode Exit fullscreen mode

This provides an additional safety check before modifying infrastructure.


HCL

HCL (HashiCorp Configuration Language) is the language used to write Terraform configurations.

Example:

resource "random_pet" "name" {
  length = 2
}
Enter fullscreen mode Exit fullscreen mode

Module

A module is a reusable collection of Terraform configuration.

Instead of rewriting the same infrastructure repeatedly, modules allow configurations to be packaged and reused.

Example:

module "network" {
  source = "./modules/network"
}
Enter fullscreen mode Exit fullscreen mode

πŸš€ My First Terraform Workflow

The challenge uses the local and random providers, allowing me to learn Terraform without needing a cloud account.

I followed the complete Terraform workflow.


Step 1 – Initialize Terraform

terraform init
Enter fullscreen mode Exit fullscreen mode

Terraform downloaded the required providers and initialized the project.


Step 2 – Format Code

terraform fmt
Enter fullscreen mode Exit fullscreen mode

Automatically formatted the Terraform configuration files.


Step 3 – Validate Configuration

terraform validate
Enter fullscreen mode Exit fullscreen mode

Terraform checked the configuration for syntax errors.


Step 4 – Preview Changes

terraform plan
Enter fullscreen mode Exit fullscreen mode

Terraform displayed the execution plan before creating any resources.

Step 5 – Apply Configuration

terraform apply
Enter fullscreen mode Exit fullscreen mode

Terraform created the required resources.


Generated Output

cat greeting.txt
Enter fullscreen mode Exit fullscreen mode

The local file was successfully created.


Step 6 – Destroy Infrastructure

terraform destroy
Enter fullscreen mode Exit fullscreen mode

Terraform removed every resource it had created.


πŸ”„ Terraform Workflow

Write Configuration
        β”‚
        β–Ό
terraform init
        β”‚
        β–Ό
terraform fmt
        β”‚
        β–Ό
terraform validate
        β”‚
        β–Ό
terraform plan
        β”‚
        β–Ό
terraform apply
        β”‚
        β–Ό
terraform destroy
Enter fullscreen mode Exit fullscreen mode

🍫 Bonus Exploration

Enable CLI Autocomplete

terraform -install-autocomplete
Enter fullscreen mode Exit fullscreen mode


OpenTofu

OpenTofu is a community-driven fork of Terraform that remains fully open source while maintaining compatibility with existing Terraform configurations.

tofu version
Enter fullscreen mode Exit fullscreen mode


Understanding .terraform.lock.hcl

During initialization, Terraform generated a file named:

.terraform.lock.hcl
Enter fullscreen mode Exit fullscreen mode

This file records:

  • Provider versions
  • Provider checksums
  • Dependency information

Tracking this file in Git ensures that every developer and CI/CD pipeline uses the exact same provider versions.


πŸ’‘ Key Takeaways

Day 1 helped me understand that Terraform is much more than a provisioning tool.

The biggest lesson was learning how Infrastructure as Code brings consistency, automation, and version control to infrastructure management. Even with a simple local project, I experienced Terraform's complete lifecycleβ€”from initialization to clean destruction of resources.

This foundation will make it much easier to build real cloud infrastructure in the upcoming TerraWeek sessions.


πŸ“‚ Project Structure

Day-01/
│── README.md
│── example/
│── images/
β”‚   β”œβ”€β”€ terraform-version.png
β”‚   β”œβ”€β”€ terraform-help.png
β”‚   β”œβ”€β”€ vscode-extension.png
β”‚   β”œβ”€β”€ init.png
β”‚   β”œβ”€β”€ fmt.png
β”‚   β”œβ”€β”€ validate.png
β”‚   β”œβ”€β”€ plan.png
β”‚   β”œβ”€β”€ apply.png
β”‚   β”œβ”€β”€ greeting.png
β”‚   β”œβ”€β”€ destroy.png
β”‚   β”œβ”€β”€ autocomplete.png
β”‚   β”œβ”€β”€ opentofu-version.png
β”‚   └── lock-file.png
Enter fullscreen mode Exit fullscreen mode

πŸš€ Conclusion

Day 1 laid the foundation for my Terraform journey. I learned why Infrastructure as Code has become an essential DevOps practice, explored Terraform's core concepts, completed my first Terraform workflow, and understood how infrastructure can be managed in a consistent, repeatable, and version-controlled way.

Looking forward to Day 2, where I'll dive deeper into HCL, variables, expressions, and reusable configurations.


🏷️ Tags

#Terraform #InfrastructureAsCode #DevOps #HashiCorp #OpenTofu #GitHub #CloudComputing #TrainWithShubham #TerraWeekChallenge

Top comments (0)