|
1 | 1 | # tf_rds
|
2 |
| -Terraform Template for AWS RDS |
| 2 | +Terraform module for AWS RDS |
| 3 | + |
| 4 | + |
| 5 | +The module will create: |
| 6 | +* DB instance (MySQL, Postgres, SQL Server, Oracle) |
| 7 | +* DB Parameter Group |
| 8 | +* DB Subnet Group |
| 9 | +* DB Security Group |
| 10 | +* DNS Record in Route53 for the DB endpoint |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | +## Input Variables |
| 15 | + |
| 16 | +- `stage` - The deployment stage (_e.g._ `prod`, `staging`, `dev`) |
| 17 | +- `namespace` - The namespace of the application the DB instance belongs to (_e.g._ `global`, `shared`, or the name of your company like `cloudposse`) |
| 18 | +- `name` - The name of the application the DB instance belongs to |
| 19 | +- `dns_zone_id` - The ID of the DNS Zone in Route53 where a new DNS record will be created for the DB host name |
| 20 | +- `host_name` - The DB host name created in Route53 |
| 21 | +- `security_group_ids` - The IDs of the security groups from which to allow `ingress` traffic to the DB instance |
| 22 | +- `database_name` - The name of the database (_e.g._ `wordpress`) |
| 23 | +- `database_user` - Admin user name (_e.g._ `admin`) |
| 24 | +- `database_password` - Admin password |
| 25 | +- `database_port` - Database port (_e.g._ `3306` for `MySQL`). Used in the DB Security Group to allow access to the DB instance from the provided `security_group_ids` |
| 26 | +- `multi_az` - Default `false`. Set to `true` for a multi-AZ deployment (recommended for production) |
| 27 | +- `storage_type` - One of `standard` (magnetic), `gp2` (general purpose SSD), or `io1` (provisioned IOPS SSD). Default `standard` (magnetic) |
| 28 | +- `iops` - The amount of provisioned IOPS. Setting this implies a storage_type of `io1`. Default is `0` if rds storage type is not `io1` |
| 29 | +- `allocated_storage` - The number of GBs to allocate for DB storage. Must be an integer, _e.g._ `10` |
| 30 | +- `engine` - Engine type, such as `mysql` or `postgres` |
| 31 | +- `engine_version` - DB Engine version, _e.g._ `9.5.4` for `Postgres` |
| 32 | +- `instance_class` - Instance class, _e.g._ `db.t2.micro` |
| 33 | +- `db_parameter_group` - DB Parameter Group, _e.g._ `mysql5.6` for MySQL, `postgres9.5` for `Postgres` |
| 34 | +- `publicly_accessible` - Determines if the DB instance can be publicly accessed from the Internet. Default `false` |
| 35 | +- `subnet_ids` - List of subnets IDs in the VPC, _e.g._ `["sb-1234567890", "sb-0987654321"]` |
| 36 | +- `vpc_id` - VPC ID the DB instance will be connected to |
| 37 | +- `auto_minor_version_upgrade` - Automatically upgrade minor version of the DB (eg. from Postgres 9.5.3 to Postgres 9.5.4). Default `true` |
| 38 | +- `allow_major_version_upgrade` - Allow upgrading of major version of database (eg. from Postgres 9.5.x to Postgres 9.6.x). Default `false` |
| 39 | +- `apply_immediately` - Specifies whether any database modifications are applied immediately, or during the next maintenance window. Default `false` |
| 40 | +- `maintenance_window` - The window to perform maintenance in. Default `"Mon:03:00-Mon:04:00"` |
| 41 | +- `skip_final_snapshot` - If `true` (default), DB won't be backed up before deletion |
| 42 | +- `copy_tags_to_snapshot` - Copy all tags from RDS database to snapshot. Default `true` |
| 43 | +- `backup_retention_period` - Backup retention period in days (default `0`). Must be `> 0` to enable backups |
| 44 | +- `backup_window` - When to perform DB snapshots. Default `"22:00-03:00"`. Can't overlap with the maintenance window |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +## Outputs |
| 49 | + |
| 50 | +- `instance_id` - ID of the instance |
| 51 | +- `instance_address` - Address of the instance |
| 52 | +- `instance_endpoint` - DNS Endpoint of the instance |
| 53 | +- `subnet_group_id` - ID of the Subnet Group |
| 54 | +- `security_group_id` - ID of the Security Group |
| 55 | +- `parameter_group_id` - ID of the Parameter Group |
| 56 | +- `hostname` - DNS host name of the instance |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | +## Usage |
| 61 | + |
| 62 | + |
| 63 | +``` |
| 64 | +module "rds_instance" { |
| 65 | + source = "git::https://github.com/cloudposse/tf_rds.git?ref=tags/0.1.0" |
| 66 | + stage = "prod" |
| 67 | + namespace = "cloudposse" |
| 68 | + name = "app" |
| 69 | + dns_zone_id = "Z89FN1IW975KPE" |
| 70 | + host_name = "db" |
| 71 | + security_group_ids = ["sg-xxxxxxxx"] |
| 72 | + database_name = "wordpress" |
| 73 | + database_user = "admin" |
| 74 | + database_password = "xxxxxxxxxxxx" |
| 75 | + database_port = 3306 |
| 76 | + multi_az = true |
| 77 | + storage_type = "gp2" |
| 78 | + allocated_storage = "100" |
| 79 | + engine = "mysql" |
| 80 | + engine_version = "5.7.17" |
| 81 | + instance_class = "db.t2.medium" |
| 82 | + db_parameter_group = "mysql5.6" |
| 83 | + publicly_accessible = false |
| 84 | + subnet_ids = ["sb-xxxxxxxxx", "sb-xxxxxxxxx"] |
| 85 | + vpc_id = "vpc-xxxxxxxx" |
| 86 | + auto_minor_version_upgrade = true |
| 87 | + allow_major_version_upgrade = false |
| 88 | + apply_immediately = false |
| 89 | + maintenance_window = "Mon:03:00-Mon:04:00" |
| 90 | + skip_final_snapshot = false |
| 91 | + copy_tags_to_snapshot = true |
| 92 | + backup_retention_period = 7 |
| 93 | + backup_window = "22:00-03:00" |
| 94 | +} |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +# License |
| 99 | + |
| 100 | +Apache 2 Licensed. See LICENSE for full details. |
0 commit comments