Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions terraform/aws/modules/composition/application-storage/data.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Data sources for Aurora composition module

# Current AWS region
data "aws_region" "current" {}

# Current AWS caller identity (account ID)
data "aws_caller_identity" "current" {}

# VPC information for validation and reference
data "aws_vpc" "selected" {
id = var.vpc_id
}

# Subnet information for validation
data "aws_subnets" "database" {
filter {
name = "subnet-id"
values = var.database_subnet_ids
}
}

# Get subnet details for each database subnet
data "aws_subnet" "database" {
for_each = toset(var.database_subnet_ids)
id = each.value
}

# Application security group information for validation
data "aws_security_group" "application" {
id = var.application_security_group_id
}

# Get available Aurora PostgreSQL engine versions (for validation)
data "aws_rds_engine_versions" "postgresql" {
engine = "aurora-postgresql"
preferred_versions = [var.engine_version]
}

# Default KMS key for RDS (if no custom key provided)
data "aws_kms_key" "rds_default" {
count = var.kms_key_id == null ? 1 : 0
key_id = "alias/aws/rds"
}
48 changes: 48 additions & 0 deletions terraform/aws/modules/composition/application-storage/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Local values for naming and tagging
locals {
# Naming convention following the established pattern
name_prefix = "${var.environment}-${var.project_name}-app-storage"

# Instance class mapping by environment
instance_class_map = {
dev = "db.r6g.large" # 2 vCPUs, 16 GB RAM - suitable for development
integ = "db.r6g.xlarge" # 4 vCPUs, 32 GB RAM - suitable for integration testing
prod = "db.r6g.xlarge" # 4 vCPUs, 32 GB RAM - production workload
sandbox = "db.r6g.large" # 2 vCPUs, 16 GB RAM - sandbox environment
sbx = "db.r6g.large" # 2 vCPUs, 16 GB RAM - sandbox environment (short form)
}

# Select instance class based on environment or override
instance_class = coalesce(
var.instance_class_override,
lookup(local.instance_class_map, var.environment, "db.r6g.large")
)

# Common tags applied to all resources - following established pattern
common_tags = merge(var.tags, {
Environment = var.environment
Service = "application-storage"
ManagedBy = "Terraform"
Module = "composition/application-storage"
})

# Environment-specific configuration flags
is_production = contains(["prod", "production"], var.environment)
is_sandbox = contains(["sandbox", "sbx"], var.environment)
is_dev = contains(["dev", "development"], var.environment)

# Dynamic configuration based on environment
enhanced_monitoring_enabled = local.is_production ? true : var.monitoring_interval > 0
performance_insights_enabled = local.is_production ? true : var.performance_insights_enabled
deletion_protection_enabled = local.is_production ? true : var.deletion_protection

# Backup configuration adjustments
backup_retention_days = local.is_production ? max(var.backup_retention_period, 14) : var.backup_retention_period

# RDS Proxy configuration
rds_proxy_enabled = var.enable_rds_proxy

# Environment-specific RDS Proxy defaults
proxy_max_connections = local.is_production ? 100 : 75
proxy_max_idle_connections = local.is_production ? 25 : 50
}
Loading