Terraform Cost Optimization for AWS - Reduce Your Cloud Bill
Practical Terraform patterns to reduce AWS costs: right-sizing, spot instances, scheduling, and reserved capacity. Step-by-step guide with code examples and ...
Guides
Complete guide to Terraform modules: creating, using, versioning, and publishing reusable infrastructure code. Step-by-step guide with code examples and best...
A module is a container for multiple resources that are used together. Every Terraform configuration is technically a module (the root module). Child modules let you organize and reuse infrastructure code.
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.1.0"
name = "my-vpc"
cidr = "10.0.0.0/16"
azs = ["us-east-1a", "us-east-1b"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24"]
enable_nat_gateway = true
}# Terraform Registry (recommended)
source = "terraform-aws-modules/vpc/aws"
# GitHub
source = "github.com/org/repo//modules/vpc"
# Local path
source = "./modules/networking"
# S3 bucket
source = "s3::https://bucket.s3.amazonaws.com/modules/vpc.zip"
# Git over SSH
source = "git@github.com:org/repo.git//modules/vpc?ref=v1.0.0"modules/networking/
├── main.tf # Resources
├── variables.tf # Input variables
├── outputs.tf # Output values
├── versions.tf # Required providers
└── README.md # Documentationvariables.tf:
variable "vpc_cidr" {
type = string
description = "CIDR block for the VPC"
}
variable "environment" {
type = string
description = "Environment name (dev, staging, prod)"
}main.tf:
resource "aws_vpc" "this" {
cidr_block = var.vpc_cidr
enable_dns_hostnames = true
tags = { Name = "${var.environment}-vpc" }
}outputs.tf:
output "vpc_id" {
value = aws_vpc.this.id
description = "The ID of the VPC"
}terraform-docs to auto-generate documentationterraform testRelated: How to install AWS CLI on macOS using Homebrew — set up AWS CLI in minutes.
Practical Terraform patterns to reduce AWS costs: right-sizing, spot instances, scheduling, and reserved capacity. Step-by-step guide with code examples and ...
How to achieve zero-downtime deployments with Terraform using blue-green, rolling updates, and create_before_destroy. Step-by-step guide with code examples a...
Complete guide to testing Terraform configurations with terraform test, Terratest, and validation rules. Step-by-step guide with code examples and best pract...
Complete guide to Terraform data sources: querying existing infrastructure, filtering, and common patterns. Step-by-step guide with code examples and best pr...