rds-postgres
Creates an RDS PostgreSQL instance with Multi-AZ, KMS encryption, enhanced monitoring, read replicas, and RDS-managed master password.
Provisions an encrypted PostgreSQL RDS instance with gp3 storage autoscaling, a custom parameter group, Multi-AZ standby, automated backup, enhanced monitoring, Performance Insights, and optional read replicas. The master password can be managed by RDS and rotated automatically in Secrets Manager.
Usage
module "rds" {
source = "hcassc.jfrog.io/iac-terraform-modules-virtual/database/rds-postgres/aws"
version = "0.1.0"
identifier = "prod-postgres"
db_name = "appdb"
subnet_ids = module.vpc.isolated_subnet_id_list
security_group_ids = [module.security_groups.ids["rds"]]
kms_key_id = module.kms.key_arn
read_replicas = {
ro1 = "db.t3.medium"
}
}
Requirements
| Name | Version |
|---|---|
| terraform | ~> 1.5 |
| aws | ~> 6.50 |
Providers
| Name | Version |
|---|---|
| aws | 6.50.0 |
Resources
| Name | Type |
|---|---|
| aws_db_instance.replica | resource |
| aws_db_instance.this | resource |
| aws_db_parameter_group.this | resource |
| aws_db_subnet_group.this | resource |
Inputs
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| db_name | Initial database name | string |
n/a | yes |
| identifier | RDS instance identifier | string |
n/a | yes |
| security_group_ids | Security group IDs for the RDS instance | list(string) |
n/a | yes |
| allocated_storage | Initial allocated storage in GiB | number |
20 |
no |
| backup_retention_period | Days to retain automated backups | number |
7 |
no |
| backup_window | Preferred backup window (UTC) | string |
"03:00-04:00" |
no |
| deletion_protection | Enable deletion protection | bool |
true |
no |
| engine_version | PostgreSQL engine version | string |
"16.3" |
no |
| instance_class | RDS instance class | string |
"db.t3.medium" |
no |
| kms_key_id | KMS key ARN for storage encryption | string |
null |
no |
| maintenance_window | Preferred maintenance window | string |
"sun:05:00-sun:06:00" |
no |
| manage_master_user_password | Let RDS manage the master password in Secrets Manager | bool |
true |
no |
| max_allocated_storage | Maximum storage for autoscaling (0 disables) | number |
100 |
no |
| monitoring_interval | Enhanced monitoring interval in seconds (0 disables) | number |
60 |
no |
| multi_az | Enable Multi-AZ deployment | bool |
true |
no |
| parameter_group_family | DB parameter group family | string |
"postgres16" |
no |
| parameters | Map of DB parameter names to values | map(string) |
{} |
no |
| password | Master password (ignored when manage_master_user_password = true) | string |
null |
no |
| performance_insights_enabled | Enable Performance Insights | bool |
true |
no |
| performance_insights_kms_key_id | KMS key for Performance Insights encryption | string |
null |
no |
| read_replicas | Map of read replica logical names to instance class | map(string) |
{} |
no |
| skip_final_snapshot | Skip final snapshot on deletion | bool |
false |
no |
| subnet_group_name | DB subnet group name (created when subnet_ids is provided) | string |
null |
no |
| subnet_ids | Subnet IDs for the DB subnet group | list(string) |
[] |
no |
| tags | Resource tags to apply to all resources | map(string) |
{} |
no |
| username | Master username | string |
"postgres" |
no |
Outputs
| Name | Description |
|---|---|
| address | RDS instance hostname |
| arn | RDS instance ARN |
| db_name | Initial database name |
| endpoint | RDS instance connection endpoint |
| id | RDS instance identifier |
| master_user_secret_arn | Secrets Manager secret ARN for the master password (when manage_master_user_password = true) |
| port | RDS instance port |
| replica_endpoints | Map of replica logical key to endpoint |