Building Your First Terraform Project
Creating a Basic Infrastructure Configuration
- Create a small project that launches an Ubuntu EC2 web server in a sandbox AWS account. The example uses an existing default VPC, looks up a current Ubuntu AMI, creates an HTTP security group and outputs the instance's public IP.
- Review the provider documentation and account permissions before applying.
Initializing, Planning and Provisioning Infrastructure
- Run terraform init, terraform fmt and terraform validate. Review terraform plan and confirm it targets the intended account and creates only the expected resources.
- Apply only after review. Stop if the plan shows unexpected deletion or replacement.
Verifying Resources and Destroying Infrastructure Safely
- Verify the EC2 instance and security group in the AWS console. When finished, run terraform plan -destroy and inspect the resources listed before running terraform destroy.
- Never use destroy as a cleanup shortcut in a shared or production workspace.
1. Worked Terraform Configuration
This example launches an Ubuntu EC2 web server in the default VPC. It looks up an Ubuntu AMI, creates an HTTP security group, launches the instance and outputs its public IP.
Review costs and access settings before applying.
terraform {required_providers {aws = {source = "hashicorp/aws"version = "~> 6.0"}}}
provider "aws" {region = "us-east-1"}
data "aws_ami" "ubuntu" {most_recent = trueowners = ["099720109477"]
filter {name = "name"values = ["ubuntu/images/hvm-ssd/ubuntu-noble-24.04-amd64-server-*"]}}
data "aws_vpc" "default" {default = true}
resource "aws_security_group" "web" {name = "terraform-web-sg"description = "Allow HTTP traffic"vpc_id = data.aws_vpc.default.id
ingress {from_port = 80to_port = 80protocol = "tcp"cidr_blocks = ["0.0.0.0/0"]}
egress {from_port = 0to_port = 0protocol = "-1"cidr_blocks = ["0.0.0.0/0"]}}
resource "aws_instance" "web" {ami = data.aws_ami.ubuntu.idinstance_type = "t3.micro"vpc_security_group_ids = [aws_security_group.web.id]
tags = {Name = "terraform-web-server"Environment = "learning"}}
output "instance_public_ip" {value = aws_instance.web.public_ip}
Project: launch a small Ubuntu EC2 instance in an existing default VPC. The configuration looks up a current Ubuntu AMI, creates a security group, restricts SSH access to your IP address, launches the instance, displays its ID and public IP, and removes the lab resources safely.
2. What You Should Be Able to Do
Explain IaC, identify Terraform's main components, write a small Terraform configuration, initialize a project, review a plan, provision a resource and clean it up safely.

Figure : The write–initialize–plan–apply sequence. Always review the plan before applying.
You can also explore Interactive Beginner Lab: https://astonishing-phoenix-1c9916.netlify.app
Level Summary
You have learned the Terraform fundamentals: what infrastructure as code solves, how Terraform uses providers and state, and how to write configurations in HashiCorp Configuration Language. You have also provisioned a first resource using a safe workflow.
Terraform Tutorial
Harini A









