** WHAT IS TERRAFORM?**
Terraform is an infrastructure-as-code tool that lets you build, change, and version cloud and on-premises resources safely and efficiently.
HashiCorp Terraform is an infrastructure-as-code tool that lets you define both cloud and on-premises resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle. Terraform can manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features. It is widely considered the industry standard for cloud provisioning due to its ability to manage various services (AWS, Azure, GCP, Kubernetes, etc.) with a single, consistent workflow.
Key Concepts
Declarative Language (HCL): Unlike imperative tools that require you to script step-by-step instructions, Terraform uses HashiCorp Configuration Language to describe the desired end state of your infrastructure. You tell Terraform, "I want a virtual machine," and it determines how to create it.
Providers: These are plugins that allow Terraform to interact with cloud providers (AWS, Azure, GCP), SaaS services, and other APIs.
Resources: The individual infrastructure components defined in configuration files, such as virtual machines, storage buckets, or network security groups.
State (terraform tf state)**: Terraform creates a state file that maps your configuration to real-world resources. This acts as a "source of truth" to track changes, manage dependencies, and detect configuration drift.
Modules: Reusable containers for multiple resources used together, allowing for standardized, shareable code (e.g., a standard web server module)
** The Core Workflow**
Terraform follows a simple, repeatable three-stage workflow:
Write: Define resources in .tf configuration files.
Plan (terraform plan): Terraform compares the desired state to the current state (via the state file) and creates an execution plan, showing what it will create, update, or destroy.
Apply (terraform apply): Upon approval, Terraform executes the plan, interacting with APIs to bring the infrastructure to the desired state.
STEPS ON CONFIGURATION AND IMPLEMENTATION OF TERRAFORM ON YOUR COMPUTER AND THE CONFIGURATION FILE FOR EC2 CONSOLE.
Terraform is an open-source tool that allows you to define cloud resources in human-readable configuration files. This is called 'Infrastructure as Code'.
Implementation Guide
- Install Terraform
Set up your local environment for Infrastructure as Code (IaC).
(a) Install on Windows (using Chocolatey if you are window user)
$ choco install terraform
(b) Verify Installation
_ $ terraform --version_
Before writing code, you need a playground. Creating a directory keeps your state files and configurations separated from other projects.
2 Prepare Project Directory
Organize your Terraform files in a dedicated workspace.
(a) Create & Enter Folder
📘Instruction Summary
This creates a clean workspace for your infrastructure code.
_ $ mkdir my-terraform-lab_
Creates a new directory (folder).
$ cd my-terraform-lab
Changes the current directory.
3.Write Provider Config
Connect Terraform to your Cloud Provider.
The 'provider' block tells Terraform which cloud you want to talk to (AWS, Azure, GCP, etc.). It acts as a translator between your code and the cloud's API.
(a) Create main.tf
📘Instruction Summary
Add a file named main.tf in your project folder and paste the provider block.
Note: This is the 'Provider Block'. It tells Terraform we are targeting AWS in the US East region.
(b) Initialize Terraform
Initializes Terraform — downloads provider plugins and sets up the backend where state is stored.
This command downloads the AWS provider plugin into your project folder. Note the new terraform directory.
- ** Declare Resource**
Define what you want to build in the cloud.
Key Concept
The 'resource' block describes a specific piece of infrastructure, like a Virtual Machine (VM) or a Storage Bucket.
(a) Add a Resource Block
📘 Instruction Summary
Append this to your main.tf file.
resource "aws_instance" "my_server" {
ami = "ami-0c7217cdde317cfec"
instance_type = "t2.micro"
tags = {
Name = "SkillSchTerraformLab"
}
}
(b) Preview Your Changes
$ terraform plan
Shows a preview of what Terraform will create, change, or destroy — always review this before applying.
This shows you exactly what Terraform is about to create before it actually does it.
- Apply Changes
Actually deploy your infrastructure to the live cloud.
Key Concept
Running 'apply' makes the changes real. Terraform will reach out to the cloud API and create the resources.
(a) Deploy to Cloud
_ terraform apply_
Applies the planned changes to create or update your infrastructure. You'll be prompted to confirm.
Type 'yes' when prompted to confirm the deployment.
(b) ** Check Your State**
📘Instruction Summary
This command shows you the current state of your live infrastructure.
terraform show
Displays the current state or a saved plan in a human-readable format.
(6) ** Manage State & Backends**
Understand how Terraform tracks your infrastructure.
Terraform uses a 'state' file to keep track of what it built. For teams, we store this in a 'backend' like S3 or Azure Blob Storage.
(a) View Local State
📘Instruction Summary
Notice the local file created after your 'apply'.
ls terraform.tfstate
💡 Lists files and directories. -l shows details (permissions, size, date).
(b) Learn about Remotes
📘Instruction Summary
In a real job, you'll move this to a remote cloud storage bucket so your teammates don't overwrite your work.
(7) ** Clean Up & Share**
Destroy resources and push your code to GitHub.
(a) Destroy Everything
📘Instruction Summary
Always destroy your lab resources to keep your cloud bill at zero
terraform destroy
💡 Tears down all infrastructure managed by this Terraform config — use for cleanup.
(b) Push to Portfolio
git init
💡 Initializes a new Git repository in the current directory.
git add .
💡 Stages all changed files for the next commit.
git commit -m 'feat: terraform infrastructure lab'
💡 Creates a new commit with all staged changes and the message after -m.
git push origin main
💡 Uploads your local commits to the remote repository.


















Top comments (0)