diff --git a/README.md b/README.md index 43ffdf23..53f495c7 100644 --- a/README.md +++ b/README.md @@ -299,6 +299,7 @@ Users have the ability to: | [publicly\_accessible](#input\_publicly\_accessible) | Bool to control if instance is publicly accessible | `bool` | `false` | no | | [random\_password\_length](#input\_random\_password\_length) | (Optional) Length of random password to create. (default: 10) | `number` | `10` | no | | [replicate\_source\_db](#input\_replicate\_source\_db) | Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate. | `string` | `null` | no | +| [restore\_to\_point\_in\_time](#input\_restore\_to\_point\_in\_time) | Restore to a point in time (MySQL is NOT supported) | `map(string)` | `null` | no | | [s3\_import](#input\_s3\_import) | Restore from a Percona Xtrabackup in S3 (only MySQL is supported) | `map(string)` | `null` | no | | [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from final\_snapshot\_identifier | `bool` | `false` | no | | [snapshot\_identifier](#input\_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. | `string` | `null` | no | diff --git a/main.tf b/main.tf index f656a9b2..7451e0ec 100644 --- a/main.tf +++ b/main.tf @@ -129,7 +129,8 @@ module "db_instance" { deletion_protection = var.deletion_protection delete_automated_backups = var.delete_automated_backups - s3_import = var.s3_import + restore_to_point_in_time = var.restore_to_point_in_time + s3_import = var.s3_import tags = merge(var.tags, var.db_instance_tags) } diff --git a/modules/db_instance/README.md b/modules/db_instance/README.md index d4d42ce3..5e72c378 100644 --- a/modules/db_instance/README.md +++ b/modules/db_instance/README.md @@ -80,6 +80,7 @@ No modules. | [port](#input\_port) | The port on which the DB accepts connections | `string` | `null` | no | | [publicly\_accessible](#input\_publicly\_accessible) | Bool to control if instance is publicly accessible | `bool` | `false` | no | | [replicate\_source\_db](#input\_replicate\_source\_db) | Specifies that this resource is a Replicate database, and to use this value as the source database. This correlates to the identifier of another Amazon RDS Database to replicate. | `string` | `null` | no | +| [restore\_to\_point\_in\_time](#input\_restore\_to\_point\_in\_time) | Restore to a point in time (MySQL is NOT supported) | `map(string)` | `null` | no | | [s3\_import](#input\_s3\_import) | Restore from a Percona Xtrabackup in S3 (only MySQL is supported) | `map(string)` | `null` | no | | [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | Determines whether a final DB snapshot is created before the DB instance is deleted. If true is specified, no DBSnapshot is created. If false is specified, a DB snapshot is created before the DB instance is deleted, using the value from final\_snapshot\_identifier | `bool` | `false` | no | | [snapshot\_identifier](#input\_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. | `string` | `null` | no | diff --git a/modules/db_instance/main.tf b/modules/db_instance/main.tf index c478943a..ca2b205c 100644 --- a/modules/db_instance/main.tf +++ b/modules/db_instance/main.tf @@ -78,8 +78,22 @@ resource "aws_db_instance" "this" { deletion_protection = var.deletion_protection delete_automated_backups = var.delete_automated_backups + + dynamic "restore_to_point_in_time" { + for_each = var.restore_to_point_in_time != null ? [var.restore_to_point_in_time] : [] + + content { + restore_time = lookup(restore_to_point_in_time.value, "restore_time", null) + source_db_instance_identifier = lookup(restore_to_point_in_time.value, "source_db_instance_identifier", null) + source_dbi_resource_id = lookup(restore_to_point_in_time.value, "source_dbi_resource_id", null) + use_latest_restorable_time = lookup(restore_to_point_in_time.value, "use_latest_restorable_time", null) + } + } + + dynamic "s3_import" { for_each = var.s3_import != null ? [var.s3_import] : [] + content { source_engine = "mysql" source_engine_version = s3_import.value.source_engine_version diff --git a/modules/db_instance/variables.tf b/modules/db_instance/variables.tf index 2c339738..4b2f3500 100644 --- a/modules/db_instance/variables.tf +++ b/modules/db_instance/variables.tf @@ -324,3 +324,10 @@ variable "s3_import" { type = map(string) default = null } + + +variable "restore_to_point_in_time" { + description = "Restore to a point in time (MySQL is NOT supported)" + type = map(string) + default = null +} diff --git a/variables.tf b/variables.tf index 40d1f5f8..fa6a91fb 100644 --- a/variables.tf +++ b/variables.tf @@ -219,6 +219,12 @@ variable "backup_window" { default = null } +variable "restore_to_point_in_time" { + description = "Restore to a point in time (MySQL is NOT supported)" + type = map(string) + default = null +} + variable "s3_import" { description = "Restore from a Percona Xtrabackup in S3 (only MySQL is supported)" type = map(string)