Create a project
mkdir terraform-demo
cd terraform-demo
touch main.tfProvider docs live in the Terraform Registry.
Core blocks
Terraform block
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}This tells Terraform which providers to download and which versions are allowed.
Provider block
provider "aws" {
region = "ap-southeast-1"
}This connects Terraform to AWS in a specific region using your local credentials.
Resource block
resource "aws_s3_bucket" "demo" {
bucket = "terraform-demo-bucket"
}Syntax:
resource "<resource_type>" "<local_name>" {
# arguments
}resource_type— AWS resource kind (aws_instance,aws_s3_bucket, …)local_name— name you use inside Terraform (not the AWS display name)
EC2 docs: aws_instance.
Resource 1 — S3 bucket
main.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-southeast-1"
}
resource "aws_s3_bucket" "demo" {
bucket = "venkat-terraform-demo-bucket"
}S3 bucket names must be globally unique. Change venkat-terraform-demo-bucket to something only you will use.
Apply:
terraform init
terraform validate
terraform plan
terraform applyType yes when prompted. Verify in the AWS Console under S3.
Resource 2 — EC2 instance
Update main.tf (replace or add the instance resource):
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "ap-southeast-1"
}
resource "aws_instance" "web" {
ami = "ami-0df7a207adb9748c7"
instance_type = "t2.micro"
tags = {
Name = "Terraform-EC2"
}
}AMI IDs are region-specific. If ap-southeast-1 is not your region, look up a current Amazon Linux AMI ID for your region in the EC2 console.
terraform init
terraform plan
terraform applyVerify in EC2 → Instances. You should see Terraform-EC2 running.
Hands-on labs
Lab 1 — Launch EC2
Create with Terraform:
- 1 EC2 instance
Nametag sett2.microinstance type
Verify the instance is running in the console.
Lab 2 — Create S3
Create with Terraform:
- 1 S3 bucket
- A unique bucket name
Verify the bucket appears in the S3 console.
Clean up
When you are done experimenting:
terraform destroyConfirm with yes so you are not billed for leftover resources.
Day 1 summary
Infrastructure & IaC
↓
Why Terraform + workflow
↓
Install Terraform
↓
AWS CLI + IAM credentials
↓
terraform / provider / resource blocks
↓
Create S3 + EC2
↓
Hands-on labs