PSA-compliant RDS and Aurora module with mandatory encryption, RDS Proxy support, and Serverless v2 integration.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Full auto-generated documentation of inputs, outputs, and resources: TERRAFORM-DOCS.md
Table of Contents
This module provides a production-ready, security-first foundation for relational databases on AWS. It supports standard RDS instances, Aurora Clusters (including Serverless v2), and RDS Proxy for advanced connection management.
- Standard RDS & Aurora: Toggle between standalone instances and high-availability clusters.
- Aurora Serverless v2: Native support for autoscaling compute capacity.
- RDS Proxy: Integrated connection pooling and security filtering.
- KMS Encryption: Mandatory encryption at rest with optional CMK creation.
- IAM Authentication: Enabled by default for modern access control.
- Performance Insights: Integrated monitoring for database performance tuning.
module "db" {
source = "./terraform-aws-rds"
project_name = "myapp"
environment = "prod"
engine = "postgres"
engine_version = "15.4"
instance_class = "db.t3.medium"
master_password = var.db_password # Use Secrets Manager in production
vpc_id = module.vpc.vpc_id
subnet_ids = module.vpc.database_subnets
security_group_ids = [module.sg.db_tier_sg_id]
}module "aurora" {
source = "./terraform-aws-rds"
create_aurora_cluster = true
engine = "aurora-postgresql"
aurora_serverless_v2_scaling_configuration = {
min_capacity = 0.5
max_capacity = 16
}
create_db_proxy = true
db_proxy_auth = [
{
auth_scheme = "SECRETS"
secret_arn = aws_secretsmanager_secret.db_creds.arn
iam_auth = "REQUIRED"
}
]
# ... other variables
}- Encryption at Rest: Mandatory SSE-KMS for all storage and snapshots.
- SSL/TLS Enforcement: Parameter groups are pre-configured to force encrypted connections (e.g.,
rds.force_ssl=1). - No Public Access:
publicly_accessibleis hardcoded tofalseto prevent exposure. - Deletion Protection: Enabled by default to prevent accidental data loss.
- IAM Auth: Enabled by default to allow token-based authentication.
This module implements the following PSA compliance features (referencing 05-Strukturierte_PSA_Anforderungen_DB_Hadoop_LLM.pdf):
- Req 2 (TLS Enforcement): Enforced via parameter groups (
rds.force_sslorrequire_secure_transport). - Req 5 (Least Privilege): Integration with IAM Database Authentication.
- Req 7 (Custom Master User): Defaulted to
dbadminto avoid commonadmin/rootnames. - Req 14 (Complex Passwords): Recommended integration with AWS Secrets Manager.
- Req 3.50-01 (Encryption): KMS mandatory for all storage.
- Verify the Security Group allows traffic on the configured port (default 5432 for Postgres).
- Ensure the calling resource is in a VPC subnet that can route to the database subnets.
- Ensure the database user has been created within the DB engine with
rds_iamrole. - Verify the client IAM policy allows
rds-db:connect.
| Name | Version |
|---|---|
| terraform | >=1.3 |
| Name | Version |
|---|---|
| aws | n/a |
No modules.
| Name | Type |
|---|---|
| aws_db_instance.this | resource |
| aws_db_parameter_group.this | resource |
| aws_db_proxy.this | resource |
| aws_db_proxy_default_target_group.this | resource |
| aws_db_proxy_target.this | resource |
| aws_db_subnet_group.this | resource |
| aws_kms_alias.rds | resource |
| aws_kms_key.rds | resource |
| aws_rds_cluster.this | resource |
| aws_rds_cluster_instance.this | resource |
| aws_rds_cluster_parameter_group.this | resource |
| aws_caller_identity.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| allocated_storage | The allocated storage in gigabytes | number |
20 |
no |
| aurora_instance_count | Number of Aurora instances in the cluster | number |
2 |
no |
| aurora_serverless_v2_scaling_configuration | Aurora Serverless v2 scaling configuration | object({ |
null |
no |
| auto_minor_version_upgrade | Indicates that minor engine upgrades will be applied automatically to the DB instance during the maintenance window | bool |
true |
no |
| backup_retention_period | The days to retain backups for | number |
7 |
no |
| backup_window | The daily time range (in UTC) during which automated backups are created if they are enabled | string |
"03:00-06:00" |
no |
| ca_cert_identifier | The identifier of the CA certificate for the DB instance | string |
"rds-ca-rsa2048-g1" |
no |
| create_aurora_cluster | Whether to create an Aurora cluster instead of a standard RDS instance | bool |
false |
no |
| create_db_proxy | Whether to create an RDS Proxy | bool |
false |
no |
| create_kms_key | Whether to create a KMS key for RDS encryption | bool |
true |
no |
| create_parameter_group | Whether to create a custom parameter group | bool |
true |
no |
| create_read_replica | Whether to create a read replica | bool |
false |
no |
| custom_parameters | Custom parameters to add to the parameter group | list(object({ |
[] |
no |
| database_name | The name of the database to create when the DB instance is created | string |
null |
no |
| database_port | The port on which the DB accepts connections | number |
5432 |
no |
| db_proxy_auth | Configuration block for DB Proxy authentication | list(object({ |
[] |
no |
| db_proxy_role_arn | ARN of the IAM role for RDS Proxy to access Secrets Manager | string |
"" |
no |
| delete_automated_backups | Specifies whether to remove automated backups immediately after the DB instance is deleted | bool |
false |
no |
| deletion_protection | The database can't be deleted when this value is set to true | bool |
true |
no |
| enable_enhanced_monitoring | Specifies whether Enhanced Monitoring is enabled | bool |
false |
no |
| enable_performance_insights | Specifies whether Performance Insights are enabled | bool |
true |
no |
| enabled_cloudwatch_logs_exports | List of log types to enable for exporting to CloudWatch logs | list(string) |
[ |
no |
| engine | The database engine to use (postgres, mysql, mariadb, oracle-ee, sqlserver-ex, etc.) | string |
"postgres" |
no |
| engine_version | The engine version to use | string |
"15.4" |
no |
| environment | Environment (e.g., prod, dev, test) | string |
n/a | yes |
| iam_database_authentication_enabled | Specifies whether mapping of AWS Identity and Access Management (IAM) accounts to database accounts is enabled | bool |
true |
no |
| instance_class | The instance type of the RDS instance | string |
"db.t3.medium" |
no |
| kms_key_id | The ARN of an existing KMS key to use for encryption | string |
"" |
no |
| log_retention_days | Specifies the number of days you want to retain log events in the specified log group | number |
30 |
no |
| maintenance_window | The window to perform maintenance in | string |
"Mon:00:00-Mon:03:00" |
no |
| master_password | Password for the master DB user. Note that this may show up in logs, and it is recommended to use Secrets Manager. | string |
n/a | yes |
| master_username | Username for the master DB user | string |
"dbadmin" |
no |
| max_allocated_storage | The upper limit to which Amazon RDS can automatically scale the storage of the DB instance | number |
100 |
no |
| monitoring_role_arn | The ARN for the IAM role that permits RDS to send enhanced monitoring metrics to CloudWatch Logs | string |
"" |
no |
| multi_az | Specifies if the RDS instance is multi-AZ | bool |
true |
no |
| mysql_security_parameters | Security-focused parameters for MySQL/MariaDB | list(object({ |
[ |
no |
| name_prefix | Prefix for resource names (if not provided, will use project-environment pattern) | string |
"" |
no |
| parameter_group_family | The family of the DB parameter group | string |
"postgres15" |
no |
| parameter_group_name | Name of the existing DB parameter group to use (if create_parameter_group is false) | string |
null |
no |
| postgres_security_parameters | Security-focused parameters for PostgreSQL | list(object({ |
[ |
no |
| project_name | Name of the project | string |
n/a | yes |
| replica_instance_class | The instance type of the RDS read replica | string |
"db.t3.medium" |
no |
| security_group_ids | List of VPC security groups to associate | list(string) |
n/a | yes |
| skip_final_snapshot | Determines whether a final DB snapshot is created before the DB instance is deleted | bool |
false |
no |
| snapshot_identifier | Specifies whether or not to create this database from a snapshot | string |
null |
no |
| storage_type | One of 'standard' (magnetic), 'gp2' (general purpose SSD), 'gp3' (general purpose SSD), or 'io1' (provisioned IOPS SSD) | string |
"gp3" |
no |
| subnet_ids | A list of VPC subnet IDs | list(string) |
n/a | yes |
| tags | Additional tags for all resources | map(string) |
{} |
no |
| Name | Description |
|---|---|
| cluster_endpoint | The cluster endpoint |
| cluster_id | The ID of the Aurora cluster |
| cluster_reader_endpoint | The cluster reader endpoint |
| db_instance_arn | The ARN of the RDS instance |
| db_instance_endpoint | The connection endpoint |
| db_instance_id | The RDS instance ID |
| db_proxy_endpoint | The endpoint of the RDS Proxy |
| db_proxy_id | The ID of the RDS Proxy |
| db_subnet_group_name | The name of the DB subnet group |
| instance_identifier | The primary database instance identifier |
| kms_key_arn | The ARN of the KMS key used for encryption |
| monitoring_role_arn | The IAM role ARN used for enhanced monitoring |
| parameter_group_name | The name of the active parameter group |