|
| 1 | +# AWS RDS PostgreSQL Terraform Module |
| 2 | + |
| 3 | +This Terraform module provisions a PostgreSQL database instance on Amazon RDS with configurable settings and security groups. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Creates a PostgreSQL RDS instance with customizable configuration |
| 8 | +- Sets up a dedicated VPC security group with configurable access rules |
| 9 | +- Configures subnet groups for the RDS instance |
| 10 | +- Supports encryption, backups, and maintenance windows |
| 11 | +- Generates random pet names for resource identification |
| 12 | + |
| 13 | +## Usage |
| 14 | + |
| 15 | +```hcl |
| 16 | +module "postgres" { |
| 17 | + source = "github.com/ryvn-technologies/aws-rds-postgres" |
| 18 | +
|
| 19 | + # Required variables |
| 20 | + vpc_id = "vpc-xxxxxxxx" |
| 21 | + subnet_ids = ["subnet-xxxxxxxx", "subnet-yyyyyyyy"] |
| 22 | + database_name = "myapp" |
| 23 | + username = "dbadmin" |
| 24 | + password = "your-secure-password" |
| 25 | +
|
| 26 | + # Optional variables |
| 27 | + instance_class = "db.t3.micro" |
| 28 | + allocated_storage = 20 |
| 29 | + |
| 30 | + # Configure access rules |
| 31 | + ingress_cidr_blocks = ["10.0.0.0/8"] # Restrict access to internal network |
| 32 | + |
| 33 | + tags = { |
| 34 | + Environment = "production" |
| 35 | + Project = "myapp" |
| 36 | + } |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +## Requirements |
| 41 | + |
| 42 | +- Terraform >= 1.0.0 |
| 43 | +- AWS Provider >= 4.0.0 |
| 44 | +- Random Provider >= 3.0.0 |
| 45 | + |
| 46 | +## Providers |
| 47 | + |
| 48 | +| Name | Version | |
| 49 | +|--------|---------| |
| 50 | +| aws | >= 4.0.0 | |
| 51 | +| random | >= 3.0.0 | |
| 52 | + |
| 53 | +## Inputs |
| 54 | + |
| 55 | +### Required Variables |
| 56 | + |
| 57 | +| Name | Description | Type | Default | |
| 58 | +|------|-------------|------|---------| |
| 59 | +| vpc_id | VPC ID where RDS will be deployed | `string` | - | |
| 60 | +| subnet_ids | A list of VPC subnet IDs | `list(string)` | - | |
| 61 | +| database_name | The name of the database to create | `string` | - | |
| 62 | +| username | Username for the master DB user | `string` | - | |
| 63 | +| password | Password for the master DB user | `string` | - | |
| 64 | + |
| 65 | +### Optional Variables |
| 66 | + |
| 67 | +| Name | Description | Type | Default | |
| 68 | +|------|-------------|------|---------| |
| 69 | +| region | AWS region for the provider configuration | `string` | - | |
| 70 | +| engine_version | PostgreSQL engine version | `string` | `"17.4"` | |
| 71 | +| instance_class | The instance type of the RDS instance | `string` | `"db.t3.micro"` | |
| 72 | +| allocated_storage | The allocated storage in gigabytes | `number` | `20` | |
| 73 | +| storage_type | Storage type (standard, gp2, or io1) | `string` | `"gp2"` | |
| 74 | +| storage_encrypted | Specifies whether the DB instance is encrypted | `bool` | `true` | |
| 75 | +| multi_az | Specifies if the RDS instance is multi-AZ | `bool` | `false` | |
| 76 | +| backup_retention_period | The days to retain backups for | `number` | `7` | |
| 77 | +| backup_window | The daily time range for automated backups | `string` | `"03:00-04:00"` | |
| 78 | +| maintenance_window | The window to perform maintenance in | `string` | `"Mon:04:00-Mon:05:00"` | |
| 79 | +| skip_final_snapshot | Skip final snapshot before deletion | `bool` | `false` | |
| 80 | +| ingress_cidr_blocks | List of CIDR blocks to allow access to the database | `list(string)` | `["0.0.0.0/0"]` | |
| 81 | +| egress_cidr_blocks | List of CIDR blocks to allow egress traffic from the database | `list(string)` | `["0.0.0.0/0"]` | |
| 82 | +| tags | A mapping of tags to assign to all resources | `map(string)` | `{}` | |
| 83 | + |
| 84 | +## Outputs |
| 85 | + |
| 86 | +| Name | Description | |
| 87 | +|------|-------------| |
| 88 | +| db_instance_id | The RDS instance ID | |
| 89 | +| db_instance_address | The address of the RDS instance | |
| 90 | +| db_instance_endpoint | The connection endpoint | |
| 91 | +| db_instance_port | The database port | |
| 92 | +| db_subnet_group_id | The db subnet group name | |
| 93 | +| db_security_group_id | The security group ID | |
| 94 | + |
| 95 | +## Security Considerations |
| 96 | + |
| 97 | +- By default, the security group allows inbound access on port 5432 from all IP addresses (0.0.0.0/0). It's strongly recommended to restrict this using the `ingress_cidr_blocks` variable in production environments. |
| 98 | +- Database encryption is enabled by default using AWS KMS. |
| 99 | +- Final snapshots are created by default when destroying the database (skip_final_snapshot = false). |
| 100 | +- The module uses Kubernetes backend configuration. Ensure your Terraform environment is properly configured for this. |
| 101 | + |
| 102 | +## License |
| 103 | + |
| 104 | +This module is maintained by Ryvn Technologies. |
0 commit comments