Skip to content

Commit b382b21

Browse files
authored
Add restore_to_point_in_time variable (#165)
1 parent 833599a commit b382b21

File tree

4 files changed

+29
-3
lines changed

4 files changed

+29
-3
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,10 @@ Available targets:
286286
| <a name="input_publicly_accessible"></a> [publicly\_accessible](#input\_publicly\_accessible) | Determines if database can be publicly available (NOT recommended) | `bool` | `false` | no |
287287
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
288288
| <a name="input_replicate_source_db"></a> [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 (if replicating within a single region) or ARN of the Amazon RDS Database to replicate (if replicating cross-region). Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a `kms_key_id`. See [DB Instance Replication](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html) and [Working with PostgreSQL and MySQL Read Replicas](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html) for more information on using Replication. | `string` | `null` | no |
289+
| <a name="input_restore_to_point_in_time"></a> [restore\_to\_point\_in\_time](#input\_restore\_to\_point\_in\_time) | An object specifying the restore point in time for the DB instance to restore from. Only used when `snapshot_identifier` is not provided. | <pre>object({<br> restore_time = optional(string, null)<br> source_db_instance_identifier = optional(string, null)<br> source_db_instance_automated_backups_arn = optional(string, null)<br> source_dbi_resource_id = optional(string, null)<br> use_latest_restorable_time = optional(bool, null)<br> })</pre> | `null` | no |
289290
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | The IDs of the security groups from which to allow `ingress` traffic to the DB instance | `list(string)` | `[]` | no |
290291
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | If true (default), no snapshot will be made before deleting DB | `bool` | `true` | no |
291-
| <a name="input_snapshot_identifier"></a> [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: rds:production-2019-06-26-06-05. If specified, the module create cluster from the snapshot | `string` | `null` | no |
292+
| <a name="input_snapshot_identifier"></a> [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: `rds:production-2019-06-26-06-05` for automated or `manual-backup-2023-11-16` for manual. If specified, the module create the instance from the snapshot. | `string` | `null` | no |
292293
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
293294
| <a name="input_storage_encrypted"></a> [storage\_encrypted](#input\_storage\_encrypted) | (Optional) Specifies whether the DB instance is encrypted. The default is false if not specified | `bool` | `true` | no |
294295
| <a name="input_storage_throughput"></a> [storage\_throughput](#input\_storage\_throughput) | The storage throughput value for the DB instance. Can only be set when `storage_type` is `gp3`. Cannot be specified if the `allocated_storage` value is below a per-engine threshold. | `number` | `null` | no |

docs/terraform.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@
9999
| <a name="input_publicly_accessible"></a> [publicly\_accessible](#input\_publicly\_accessible) | Determines if database can be publicly available (NOT recommended) | `bool` | `false` | no |
100100
| <a name="input_regex_replace_chars"></a> [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.<br>Characters matching the regex will be removed from the ID elements.<br>If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
101101
| <a name="input_replicate_source_db"></a> [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 (if replicating within a single region) or ARN of the Amazon RDS Database to replicate (if replicating cross-region). Note that if you are creating a cross-region replica of an encrypted database you will also need to specify a `kms_key_id`. See [DB Instance Replication](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.Replication.html) and [Working with PostgreSQL and MySQL Read Replicas](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html) for more information on using Replication. | `string` | `null` | no |
102+
| <a name="input_restore_to_point_in_time"></a> [restore\_to\_point\_in\_time](#input\_restore\_to\_point\_in\_time) | An object specifying the restore point in time for the DB instance to restore from. Only used when `snapshot_identifier` is not provided. | <pre>object({<br> restore_time = optional(string, null)<br> source_db_instance_identifier = optional(string, null)<br> source_db_instance_automated_backups_arn = optional(string, null)<br> source_dbi_resource_id = optional(string, null)<br> use_latest_restorable_time = optional(bool, null)<br> })</pre> | `null` | no |
102103
| <a name="input_security_group_ids"></a> [security\_group\_ids](#input\_security\_group\_ids) | The IDs of the security groups from which to allow `ingress` traffic to the DB instance | `list(string)` | `[]` | no |
103104
| <a name="input_skip_final_snapshot"></a> [skip\_final\_snapshot](#input\_skip\_final\_snapshot) | If true (default), no snapshot will be made before deleting DB | `bool` | `true` | no |
104-
| <a name="input_snapshot_identifier"></a> [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: rds:production-2019-06-26-06-05. If specified, the module create cluster from the snapshot | `string` | `null` | no |
105+
| <a name="input_snapshot_identifier"></a> [snapshot\_identifier](#input\_snapshot\_identifier) | Snapshot identifier e.g: `rds:production-2019-06-26-06-05` for automated or `manual-backup-2023-11-16` for manual. If specified, the module create the instance from the snapshot. | `string` | `null` | no |
105106
| <a name="input_stage"></a> [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
106107
| <a name="input_storage_encrypted"></a> [storage\_encrypted](#input\_storage\_encrypted) | (Optional) Specifies whether the DB instance is encrypted. The default is false if not specified | `bool` | `true` | no |
107108
| <a name="input_storage_throughput"></a> [storage\_throughput](#input\_storage\_throughput) | The storage throughput value for the DB instance. Can only be set when `storage_type` is `gp3`. Cannot be specified if the `allocated_storage` value is below a per-engine threshold. | `number` | `null` | no |

main.tf

+12
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ resource "aws_db_instance" "default" {
8888
monitoring_interval = var.monitoring_interval
8989
monitoring_role_arn = var.monitoring_role_arn
9090

91+
dynamic "restore_to_point_in_time" {
92+
for_each = var.snapshot_identifier == null && var.restore_to_point_in_time != null ? [1] : []
93+
94+
content {
95+
restore_time = lookup(var.restore_to_point_in_time, "restore_time", null)
96+
source_db_instance_identifier = lookup(var.restore_to_point_in_time, "source_db_instance_identifier", null)
97+
source_db_instance_automated_backups_arn = lookup(var.restore_to_point_in_time, "source_db_instance_automated_backups_arn", null)
98+
source_dbi_resource_id = lookup(var.restore_to_point_in_time, "source_dbi_resource_id", null)
99+
use_latest_restorable_time = lookup(var.restore_to_point_in_time, "use_latest_restorable_time", null)
100+
}
101+
}
102+
91103
depends_on = [
92104
aws_db_subnet_group.default,
93105
aws_security_group.default,

variables.tf

+13-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ variable "db_options" {
269269

270270
variable "snapshot_identifier" {
271271
type = string
272-
description = "Snapshot identifier e.g: rds:production-2019-06-26-06-05. If specified, the module create cluster from the snapshot"
272+
description = "Snapshot identifier e.g: `rds:production-2019-06-26-06-05` for automated or `manual-backup-2023-11-16` for manual. If specified, the module create the instance from the snapshot."
273273
default = null
274274
}
275275

@@ -370,3 +370,15 @@ variable "timeouts" {
370370
delete = "60m"
371371
}
372372
}
373+
374+
variable "restore_to_point_in_time" {
375+
type = object({
376+
restore_time = optional(string, null)
377+
source_db_instance_identifier = optional(string, null)
378+
source_db_instance_automated_backups_arn = optional(string, null)
379+
source_dbi_resource_id = optional(string, null)
380+
use_latest_restorable_time = optional(bool, null)
381+
})
382+
description = "An object specifying the restore point in time for the DB instance to restore from. Only used when `snapshot_identifier` is not provided."
383+
default = null
384+
}

0 commit comments

Comments
 (0)