Skip to content

Commit 5f582aa

Browse files
s2504sconst-bon
authored andcommitted
Add snapshot_identifier (#6)
1 parent 57f05a1 commit 5f582aa

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ The module will create:
2020
- `dns_zone_id` - The ID of the DNS Zone in Route53 where a new DNS record will be created for the DB host name
2121
- `host_name` - The DB host name created in Route53
2222
- `security_group_ids` - The IDs of the security groups from which to allow `ingress` traffic to the DB instance
23-
- `database_name` - The name of the database (_e.g._ `wordpress`)
24-
- `database_user` - Admin user name (_e.g._ `admin`)
25-
- `database_password` - Admin password
23+
- `database_name` - (Optional) The name of the database to create when the DB instance is created
24+
- `database_user` - (Required unless a `snapshot_identifier` or `replicate_source_db` is provided) Username for the master DB user
25+
- `database_password` - (Required unless a snapshot_identifier or replicate_source_db is provided) Password for the master DB user
2626
- `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`
2727
- `multi_az` - Default `false`. Set to `true` for a multi-AZ deployment (recommended for production)
2828
- `storage_type` - One of `standard` (magnetic), `gp2` (general purpose SSD), or `io1` (provisioned IOPS SSD). Default `standard` (magnetic)
@@ -36,15 +36,16 @@ The module will create:
3636
- `subnet_ids` - List of subnets IDs in the VPC, _e.g._ `["sb-1234567890", "sb-0987654321"]`
3737
- `vpc_id` - VPC ID the DB instance will be connected to
3838
- `auto_minor_version_upgrade` - Automatically upgrade minor version of the DB (eg. from Postgres 9.5.3 to Postgres 9.5.4). Default `true`
39-
- `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+
- `allow_major_version_upgrade` - Allow upgrading of major version of database. Default `false`. **Important**: if you are using a snapshot for creating an instance, this option should be set to `true` (if engine versions specified in the manifest and in the snapshot are different)
4040
- `apply_immediately` - Specifies whether any database modifications are applied immediately, or during the next maintenance window. Default `false`
4141
- `maintenance_window` - The window to perform maintenance in. Default `"Mon:03:00-Mon:04:00"`
4242
- `skip_final_snapshot` - If `true` (default), DB won't be backed up before deletion
4343
- `copy_tags_to_snapshot` - Copy all tags from RDS database to snapshot. Default `true`
4444
- `backup_retention_period` - Backup retention period in days (default `0`). Must be `> 0` to enable backups
4545
- `backup_window` - When to perform DB snapshots. Default `"22:00-03:00"`. Can't overlap with the maintenance window
46-
- `db_parameter` - A list of DB parameters to apply. Note that parameters may differ from a family to an other.
47-
46+
- `db_parameter` - A list of DB parameters to apply. Note that parameters may differ from a family to an other
47+
- `snapshot_identifier` - Specifies whether or not to create this database from a snapshot. This correlates to the snapshot ID you'd find in the RDS console, e.g: `rds:production-2015-06-26-06-05`
48+
- `final_snapshot_identifier` - Specifies whether or not to create a final snapshot for this database when destroing. This option **must** be set if `skip_final_snapshot` = `false`. E.g.: `"dbname-final-snapshot-${md5(timestamp())}"`
4849

4950

5051
## Outputs
@@ -85,6 +86,7 @@ module "rds_instance" {
8586
publicly_accessible = false
8687
subnet_ids = ["sb-xxxxxxxxx", "sb-xxxxxxxxx"]
8788
vpc_id = "vpc-xxxxxxxx"
89+
snapshot_identifier = "rds:production-2015-06-26-06-05"
8890
auto_minor_version_upgrade = true
8991
allow_major_version_upgrade = false
9092
apply_immediately = false

main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ resource "aws_db_instance" "default" {
2525
storage_type = "${var.storage_type}"
2626
iops = "${var.iops}"
2727
publicly_accessible = "${var.publicly_accessible}"
28+
snapshot_identifier = "${var.snapshot_identifier}"
2829
allow_major_version_upgrade = "${var.allow_major_version_upgrade}"
2930
auto_minor_version_upgrade = "${var.auto_minor_version_upgrade}"
3031
apply_immediately = "${var.apply_immediately}"
@@ -34,6 +35,7 @@ resource "aws_db_instance" "default" {
3435
backup_retention_period = "${var.backup_retention_period}"
3536
backup_window = "${var.backup_window}"
3637
tags = "${module.label.tags}"
38+
final_snapshot_identifier = "${var.final_snapshot_identifier}"
3739
}
3840

3941
resource "aws_db_parameter_group" "default" {

variables.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,12 @@ variable "db_parameter" {
153153
type = "list"
154154
default = []
155155
}
156+
157+
variable "snapshot_identifier" {
158+
description = "Snapshot name e.g: rds:production-2015-06-26-06-05"
159+
default = ""
160+
}
161+
162+
variable "final_snapshot_identifier" {
163+
default = ""
164+
}

0 commit comments

Comments
 (0)