# Example Terraform Configuration for AWS Web Application # This example creates a simple web application infrastructure terraform { required_version = ">= 1.6.0" required_providers { aws = { source = "hashicorp/aws" version = "~> 5.0" } } } provider "aws" { region = var.aws_region } # VPC Module module "vpc" { source = "../../modules/vpc" name_prefix = var.name_prefix vpc_cidr = "10.0.0.0/16" availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c"] public_subnet_cidrs = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"] private_subnet_cidrs = ["10.0.11.0/24", "10.0.12.0/24", "10.0.13.0/24"] enable_nat_gateway = true single_nat_gateway = false # One NAT per AZ for HA tags = local.common_tags } # Security Groups resource "aws_security_group" "alb" { name = "${var.name_prefix}-alb-sg" description = "Security group for Application Load Balancer" vpc_id = module.vpc.vpc_id ingress { from_port = 443 to_port = 443 protocol = "tcp" cidr_blocks = ["0.0.0.0/0"] description = "HTTPS from internet" } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = ["0.0.0.0/0"] } tags = merge( local.common_tags, { Name = "${var.name_prefix}-alb-sg" } ) } # Application Load Balancer resource "aws_lb" "main" { name = "${var.name_prefix}-alb" internal = false load_balancer_type = "application" security_groups = [aws_security_group.alb.id] subnets = module.vpc.public_subnet_ids enable_deletion_protection = var.environment == "prod" tags = merge( local.common_tags, { Name = "${var.name_prefix}-alb" } ) } # Common tags locals { common_tags = { Environment = var.environment Project = var.project_name ManagedBy = "Terraform" Owner = var.owner } } # Variables variable "aws_region" { description = "AWS region" type = string default = "us-east-1" } variable "name_prefix" { description = "Prefix for resource names" type = string } variable "environment" { description = "Environment name" type = string } variable "project_name" { description = "Project name" type = string } variable "owner" { description = "Owner email" type = string } # Outputs output "vpc_id" { description = "VPC ID" value = module.vpc.vpc_id } output "alb_dns_name" { description = "ALB DNS name" value = aws_lb.main.dns_name }