What is Terraform?
Terraform is a tool that builds cloud things from text files. Instead of clicking in a web page, you write what you want, and Terraform creates it. AWS (Amazon Web Services) is a cloud company that rents out servers and storage. A module is a folder of Terraform files that you can reuse, like a recipe card. You write it once and use it many times with different inputs.

Plan the folder
A simple module has these files:
main.tf: the things to create.variables.tf: the inputs, like blanks in a form.outputs.tf: the answers you send back.versions.tf: the Terraform and provider versions.
Steps
- Make a folder:
mkdir -p modules/s3-bucket
This creates a home for your module.
- Create
modules/s3-bucket/variables.tfwith the inputs:
variable "bucket_name" {
description = "Name of the bucket"
type = string
}
variable "tags" {
description = "Labels to add"
type = map(string)
default = {}
}
These define two inputs. The tags input is optional because it has a default.
- Create
modules/s3-bucket/main.tf:
resource "aws_s3_bucket" "this" {
bucket = var.bucket_name
tags = var.tags
}
This creates one S3 bucket, which is a storage box in AWS.
- Create
modules/s3-bucket/outputs.tf:
output "bucket_arn" {
value = aws_s3_bucket.this.arn
}
This shares the bucket's unique AWS ID, called an ARN.
- Create
modules/s3-bucket/versions.tf:
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.0"
}
}
}
This says which AWS provider the module needs. Do not put the provider region or login details inside the module.
- Use the module from a root file called
main.tf:
provider "aws" {
region = "us-east-1"
}
module "logs_bucket" {
source = "./modules/s3-bucket"
bucket_name = "my-unique-logs-bucket-123"
tags = { env = "dev" }
}
This calls the module. Call it again with other values to make more buckets.
- Run the tool:
terraform init
terraform plan
Init downloads what is needed. Plan shows what would be created without changing anything.
- Apply when the plan looks right:
terraform apply
This creates the resources. AWS may charge for them, so check your AWS bill settings.
Good habits
- Keep a module small and focused on one job.
- Give every variable a description and a type.
- Use defaults only when they are safe.
- Never put passwords or keys in module files.
- Pin provider versions.
terraform fmt and terraform validate to tidy and check your code.