From 998e0a7d8f576ba8f0c9301f75e484912242b9b6 Mon Sep 17 00:00:00 2001 From: Melissa Greenbaum <69476188+magreenbaum@users.noreply.github.com> Date: Sun, 25 Aug 2024 19:39:31 -0400 Subject: [PATCH] feat: Add support for table restores (#87) --- README.md | 8 ++++++-- examples/autoscaling/README.md | 2 +- examples/autoscaling/versions.tf | 2 +- examples/basic/README.md | 2 +- examples/basic/versions.tf | 2 +- examples/global-tables/README.md | 6 +++--- examples/global-tables/versions.tf | 2 +- examples/s3-import/README.md | 2 +- examples/s3-import/versions.tf | 2 +- main.tf | 12 ++++++++++++ variables.tf | 24 ++++++++++++++++++++++++ versions.tf | 2 +- wrappers/main.tf | 4 ++++ 13 files changed, 57 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 5483e1a..a8f1682 100644 --- a/README.md +++ b/README.md @@ -68,13 +68,13 @@ Users of Terragrunt can achieve similar results by using modules provided in the | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.21 | +| [aws](#requirement\_aws) | >= 5.64 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.21 | +| [aws](#provider\_aws) | >= 5.64 | ## Modules @@ -119,6 +119,10 @@ No modules. | [range\_key](#input\_range\_key) | The attribute to use as the range (sort) key. Must also be defined as an attribute | `string` | `null` | no | | [read\_capacity](#input\_read\_capacity) | The number of read units for this table. If the billing\_mode is PROVISIONED, this field should be greater than 0 | `number` | `null` | no | | [replica\_regions](#input\_replica\_regions) | Region names for creating replicas for a global DynamoDB table. | `any` | `[]` | no | +| [restore\_date\_time](#input\_restore\_date\_time) | Time of the point-in-time recovery point to restore. | `string` | `null` | no | +| [restore\_source\_name](#input\_restore\_source\_name) | Name of the table to restore. Must match the name of an existing table. | `string` | `null` | no | +| [restore\_source\_table\_arn](#input\_restore\_source\_table\_arn) | ARN of the source table to restore. Must be supplied for cross-region restores. | `string` | `null` | no | +| [restore\_to\_latest\_time](#input\_restore\_to\_latest\_time) | If set, restores table to the most recent point-in-time recovery point. | `bool` | `null` | no | | [server\_side\_encryption\_enabled](#input\_server\_side\_encryption\_enabled) | Whether or not to enable encryption at rest using an AWS managed KMS customer master key (CMK) | `bool` | `false` | no | | [server\_side\_encryption\_kms\_key\_arn](#input\_server\_side\_encryption\_kms\_key\_arn) | The ARN of the CMK that should be used for the AWS KMS encryption. This attribute should only be specified if the key is different from the default DynamoDB CMK, alias/aws/dynamodb. | `string` | `null` | no | | [stream\_enabled](#input\_stream\_enabled) | Indicates whether Streams are to be enabled (true) or disabled (false). | `bool` | `false` | no | diff --git a/examples/autoscaling/README.md b/examples/autoscaling/README.md index f19f35e..442de4c 100644 --- a/examples/autoscaling/README.md +++ b/examples/autoscaling/README.md @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.21 | +| [aws](#requirement\_aws) | >= 5.64 | | [random](#requirement\_random) | >= 2.0 | ## Providers diff --git a/examples/autoscaling/versions.tf b/examples/autoscaling/versions.tf index d17ac73..4382ca0 100644 --- a/examples/autoscaling/versions.tf +++ b/examples/autoscaling/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.21" + version = ">= 5.64" } random = { source = "hashicorp/random" diff --git a/examples/basic/README.md b/examples/basic/README.md index 0c7c94c..66f736f 100644 --- a/examples/basic/README.md +++ b/examples/basic/README.md @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.21 | +| [aws](#requirement\_aws) | >= 5.64 | | [random](#requirement\_random) | >= 2.0 | ## Providers diff --git a/examples/basic/versions.tf b/examples/basic/versions.tf index d17ac73..4382ca0 100644 --- a/examples/basic/versions.tf +++ b/examples/basic/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.21" + version = ">= 5.64" } random = { source = "hashicorp/random" diff --git a/examples/global-tables/README.md b/examples/global-tables/README.md index 9a3e348..08cbfa6 100644 --- a/examples/global-tables/README.md +++ b/examples/global-tables/README.md @@ -20,15 +20,15 @@ Note that this example may create resources which can cost money (AWS Elastic IP | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.21 | +| [aws](#requirement\_aws) | >= 5.64 | | [random](#requirement\_random) | >= 2.0 | ## Providers | Name | Version | |------|---------| -| [aws](#provider\_aws) | >= 5.21 | -| [aws.euwest2](#provider\_aws.euwest2) | >= 5.21 | +| [aws](#provider\_aws) | >= 5.64 | +| [aws.euwest2](#provider\_aws.euwest2) | >= 5.64 | | [random](#provider\_random) | >= 2.0 | ## Modules diff --git a/examples/global-tables/versions.tf b/examples/global-tables/versions.tf index d17ac73..4382ca0 100644 --- a/examples/global-tables/versions.tf +++ b/examples/global-tables/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.21" + version = ">= 5.64" } random = { source = "hashicorp/random" diff --git a/examples/s3-import/README.md b/examples/s3-import/README.md index 55f7562..3b5a985 100644 --- a/examples/s3-import/README.md +++ b/examples/s3-import/README.md @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP | Name | Version | |------|---------| | [terraform](#requirement\_terraform) | >= 1.0 | -| [aws](#requirement\_aws) | >= 5.21 | +| [aws](#requirement\_aws) | >= 5.64 | | [random](#requirement\_random) | >= 2.0 | ## Providers diff --git a/examples/s3-import/versions.tf b/examples/s3-import/versions.tf index d17ac73..4382ca0 100644 --- a/examples/s3-import/versions.tf +++ b/examples/s3-import/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.21" + version = ">= 5.64" } random = { source = "hashicorp/random" diff --git a/main.tf b/main.tf index 8364a4f..6a86765 100644 --- a/main.tf +++ b/main.tf @@ -11,6 +11,10 @@ resource "aws_dynamodb_table" "this" { stream_view_type = var.stream_view_type table_class = var.table_class deletion_protection_enabled = var.deletion_protection_enabled + restore_date_time = var.restore_date_time + restore_source_name = var.restore_source_name + restore_source_table_arn = var.restore_source_table_arn + restore_to_latest_time = var.restore_to_latest_time ttl { enabled = var.ttl_enabled @@ -129,6 +133,10 @@ resource "aws_dynamodb_table" "autoscaled" { stream_view_type = var.stream_view_type table_class = var.table_class deletion_protection_enabled = var.deletion_protection_enabled + restore_date_time = var.restore_date_time + restore_source_name = var.restore_source_name + restore_source_table_arn = var.restore_source_table_arn + restore_to_latest_time = var.restore_to_latest_time ttl { enabled = var.ttl_enabled @@ -251,6 +259,10 @@ resource "aws_dynamodb_table" "autoscaled_gsi_ignore" { stream_view_type = var.stream_view_type table_class = var.table_class deletion_protection_enabled = var.deletion_protection_enabled + restore_date_time = var.restore_date_time + restore_source_name = var.restore_source_name + restore_source_table_arn = var.restore_source_table_arn + restore_to_latest_time = var.restore_to_latest_time ttl { enabled = var.ttl_enabled diff --git a/variables.tf b/variables.tf index 577ace5..903575e 100644 --- a/variables.tf +++ b/variables.tf @@ -179,3 +179,27 @@ variable "ignore_changes_global_secondary_index" { type = bool default = false } + +variable "restore_date_time" { + description = "Time of the point-in-time recovery point to restore." + type = string + default = null +} + +variable "restore_source_name" { + description = "Name of the table to restore. Must match the name of an existing table." + type = string + default = null +} + +variable "restore_source_table_arn" { + description = "ARN of the source table to restore. Must be supplied for cross-region restores." + type = string + default = null +} + +variable "restore_to_latest_time" { + description = "If set, restores table to the most recent point-in-time recovery point." + type = bool + default = null +} diff --git a/versions.tf b/versions.tf index 5cdb3d4..264f62f 100644 --- a/versions.tf +++ b/versions.tf @@ -4,7 +4,7 @@ terraform { required_providers { aws = { source = "hashicorp/aws" - version = ">= 5.21" + version = ">= 5.64" } } } diff --git a/wrappers/main.tf b/wrappers/main.tf index a7e5ac9..3833eb9 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -26,6 +26,10 @@ module "wrapper" { range_key = try(each.value.range_key, var.defaults.range_key, null) read_capacity = try(each.value.read_capacity, var.defaults.read_capacity, null) replica_regions = try(each.value.replica_regions, var.defaults.replica_regions, []) + restore_date_time = try(each.value.restore_date_time, var.defaults.restore_date_time, null) + restore_source_name = try(each.value.restore_source_name, var.defaults.restore_source_name, null) + restore_source_table_arn = try(each.value.restore_source_table_arn, var.defaults.restore_source_table_arn, null) + restore_to_latest_time = try(each.value.restore_to_latest_time, var.defaults.restore_to_latest_time, null) server_side_encryption_enabled = try(each.value.server_side_encryption_enabled, var.defaults.server_side_encryption_enabled, false) server_side_encryption_kms_key_arn = try(each.value.server_side_encryption_kms_key_arn, var.defaults.server_side_encryption_kms_key_arn, null) stream_enabled = try(each.value.stream_enabled, var.defaults.stream_enabled, false)