Skip to content

Commit

Permalink
feat: Add support for table restores (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenbaum authored Aug 25, 2024
1 parent 696ceab commit 998e0a7
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 13 deletions.
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ Users of Terragrunt can achieve similar results by using modules provided in the
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.64 |

## Modules

Expand Down Expand Up @@ -119,6 +119,10 @@ No modules.
| <a name="input_range_key"></a> [range\_key](#input\_range\_key) | The attribute to use as the range (sort) key. Must also be defined as an attribute | `string` | `null` | no |
| <a name="input_read_capacity"></a> [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 |
| <a name="input_replica_regions"></a> [replica\_regions](#input\_replica\_regions) | Region names for creating replicas for a global DynamoDB table. | `any` | `[]` | no |
| <a name="input_restore_date_time"></a> [restore\_date\_time](#input\_restore\_date\_time) | Time of the point-in-time recovery point to restore. | `string` | `null` | no |
| <a name="input_restore_source_name"></a> [restore\_source\_name](#input\_restore\_source\_name) | Name of the table to restore. Must match the name of an existing table. | `string` | `null` | no |
| <a name="input_restore_source_table_arn"></a> [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 |
| <a name="input_restore_to_latest_time"></a> [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 |
| <a name="input_server_side_encryption_enabled"></a> [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 |
| <a name="input_server_side_encryption_kms_key_arn"></a> [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 |
| <a name="input_stream_enabled"></a> [stream\_enabled](#input\_stream\_enabled) | Indicates whether Streams are to be enabled (true) or disabled (false). | `bool` | `false` | no |
Expand Down
2 changes: 1 addition & 1 deletion examples/autoscaling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers
Expand Down
2 changes: 1 addition & 1 deletion examples/autoscaling/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21"
version = ">= 5.64"
}
random = {
source = "hashicorp/random"
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers
Expand Down
2 changes: 1 addition & 1 deletion examples/basic/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21"
version = ">= 5.64"
}
random = {
source = "hashicorp/random"
Expand Down
6 changes: 3 additions & 3 deletions examples/global-tables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ Note that this example may create resources which can cost money (AWS Elastic IP
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.21 |
| <a name="provider_aws.euwest2"></a> [aws.euwest2](#provider\_aws.euwest2) | >= 5.21 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.64 |
| <a name="provider_aws.euwest2"></a> [aws.euwest2](#provider\_aws.euwest2) | >= 5.64 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.0 |

## Modules
Expand Down
2 changes: 1 addition & 1 deletion examples/global-tables/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21"
version = ">= 5.64"
}
random = {
source = "hashicorp/random"
Expand Down
2 changes: 1 addition & 1 deletion examples/s3-import/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Note that this example may create resources which can cost money (AWS Elastic IP
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.21 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.64 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.0 |

## Providers
Expand Down
2 changes: 1 addition & 1 deletion examples/s3-import/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21"
version = ">= 5.64"
}
random = {
source = "hashicorp/random"
Expand Down
12 changes: 12 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.21"
version = ">= 5.64"
}
}
}
4 changes: 4 additions & 0 deletions wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 998e0a7

Please sign in to comment.