# ------------------------------------------------------------------------------ # Core & Environment # ------------------------------------------------------------------------------ variable "environment" { description = "Deployment environment name." type = string validation { condition = contains(["dev", "stage", "prod"], var.environment) error_message = "Environment must be one of: dev, stage, or prod." } } variable "aws_region" { description = "AWS region where resources will be provisioned." type = string default = "ap-south-1" validation { condition = can(regex("^[a-z]{2}-[a-z]+-[0-9]{1}$", var.aws_region)) error_message = "Must be a valid AWS region identifier (e.g. ap-south-1, us-east-1)." } } # ------------------------------------------------------------------------------ # Networking # ------------------------------------------------------------------------------ variable "vpc_cidr" { description = "CIDR block for the VPC." type = string validation { condition = can(cidrhost(var.vpc_cidr, 0)) error_message = "Must be a valid IPv4 CIDR block (e.g., 10.10.0.0/16)." } } variable "availability_zones" { description = "List of AWS Availability Zones to deploy subnets across." type = list(string) validation { condition = length(var.availability_zones) >= 2 error_message = "At least two Availability Zones must be provided for subnet redundancy." } } variable "single_nat_gateway" { description = "Use a single NAT Gateway instead of one per Availability Zone." type = bool default = true } # ------------------------------------------------------------------------------ # Compute (EC2 / Auto Scaling / ECS) # ------------------------------------------------------------------------------ variable "instance_type" { description = "EC2 instance type for compute nodes." type = string validation { condition = can(regex("^[a-z0-9]+\\.[a-z0-9]+$", var.instance_type)) error_message = "Must be a valid AWS EC2 instance type format (e.g., t3.small, m6i.large)." } } variable "min_capacity" { description = "Minimum number of instances in the Auto Scaling Group." type = number validation { condition = var.min_capacity >= 1 error_message = "Minimum capacity must be at least 1." } } variable "max_capacity" { description = "Maximum number of instances in the Auto Scaling Group." type = number validation { condition = var.max_capacity >= var.min_capacity error_message = "Maximum capacity must be greater than or equal to min_capacity." } } variable "desired_capacity" { description = "Desired number of instances at launch." type = number validation { condition = var.desired_capacity >= var.min_capacity && var.desired_capacity <= var.max_capacity error_message = "Desired capacity must fall between min_capacity and max_capacity." } } # ------------------------------------------------------------------------------ # Database (RDS) # ------------------------------------------------------------------------------ variable "db_instance_class" { description = "RDS instance class." type = string validation { condition = startswith(var.db_instance_class, "db.") error_message = "RDS instance class must begin with 'db.' (e.g., db.t4g.micro)." } } variable "db_allocated_storage" { description = "Allocated storage for the RDS instance in GiB." type = number validation { condition = var.db_allocated_storage >= 20 && var.db_allocated_storage <= 65536 error_message = "Allocated storage must be between 20 GiB and 65,536 GiB." } } variable "db_multi_az" { description = "Enable Multi-AZ deployment for RDS high availability." type = bool default = false } variable "backup_retention" { description = "Number of days to retain automated RDS backups." type = number validation { condition = var.backup_retention >= 1 && var.backup_retention <= 35 error_message = "RDS backup retention must be between 1 and 35 days." } } # ------------------------------------------------------------------------------ # Security & Operations # ------------------------------------------------------------------------------ variable "deletion_protection" { description = "Prevent accidental deletion of critical resources (RDS, ALB, etc.)." type = bool default = false } variable "enable_monitoring" { description = "Enable enhanced CloudWatch monitoring and alarms." type = bool default = false } variable "tags" { description = "Common resource tags applied across all AWS resources." type = map(string) validation { condition = contains(keys(var.tags), "Environment") && contains(keys(var.tags), "ManagedBy") error_message = "Tags map must include both 'Environment' and 'ManagedBy' keys." } }