Skip to content

Commit 1a11bea

Browse files
ignacioSuayNacho Suay Masmilldrjoe-niland
authored
Issue 110: Add enable deletion protection (#112)
Co-authored-by: Nacho Suay Mas <[email protected]> Co-authored-by: Dan Miller <[email protected]> Co-authored-by: Joe Niland <[email protected]>
1 parent 382d0dd commit 1a11bea

File tree

6 files changed

+34
-26
lines changed

6 files changed

+34
-26
lines changed

README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,14 @@ Available targets:
232232
| Name | Version |
233233
|------|---------|
234234
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
235-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.22 |
235+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.59 |
236236
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
237237

238238
## Providers
239239

240240
| Name | Version |
241241
|------|---------|
242-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.22 |
242+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.59 |
243243
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
244244

245245
## Modules
@@ -273,6 +273,7 @@ Available targets:
273273
| <a name="input_autoscaler_tags"></a> [autoscaler\_tags](#input\_autoscaler\_tags) | Additional resource tags for the autoscaler module | `map(string)` | `{}` | no |
274274
| <a name="input_billing_mode"></a> [billing\_mode](#input\_billing\_mode) | DynamoDB Billing mode. Can be PROVISIONED or PAY\_PER\_REQUEST | `string` | `"PROVISIONED"` | no |
275275
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
276+
| <a name="input_deletion_protection_enabled"></a> [deletion\_protection\_enabled](#input\_deletion\_protection\_enabled) | Enable/disable DynamoDB table deletion protection | `bool` | `false` | no |
276277
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
277278
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
278279
| <a name="input_dynamodb_attributes"></a> [dynamodb\_attributes](#input\_dynamodb\_attributes) | Additional DynamoDB attributes in the form of a list of mapped values | <pre>list(object({<br> name = string<br> type = string<br> }))</pre> | `[]` | no |

docs/terraform.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
| Name | Version |
55
|------|---------|
66
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.0 |
7-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.22 |
7+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 4.59 |
88
| <a name="requirement_null"></a> [null](#requirement\_null) | >= 2.0 |
99

1010
## Providers
1111

1212
| Name | Version |
1313
|------|---------|
14-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.22 |
14+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 4.59 |
1515
| <a name="provider_null"></a> [null](#provider\_null) | >= 2.0 |
1616

1717
## Modules
@@ -45,6 +45,7 @@
4545
| <a name="input_autoscaler_tags"></a> [autoscaler\_tags](#input\_autoscaler\_tags) | Additional resource tags for the autoscaler module | `map(string)` | `{}` | no |
4646
| <a name="input_billing_mode"></a> [billing\_mode](#input\_billing\_mode) | DynamoDB Billing mode. Can be PROVISIONED or PAY\_PER\_REQUEST | `string` | `"PROVISIONED"` | no |
4747
| <a name="input_context"></a> [context](#input\_context) | Single object for setting entire context at once.<br>See description of individual variables for details.<br>Leave string and numeric variables as `null` to use default value.<br>Individual variable settings (non-null) override settings in context object,<br>except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | <pre>{<br> "additional_tag_map": {},<br> "attributes": [],<br> "delimiter": null,<br> "descriptor_formats": {},<br> "enabled": true,<br> "environment": null,<br> "id_length_limit": null,<br> "label_key_case": null,<br> "label_order": [],<br> "label_value_case": null,<br> "labels_as_tags": [<br> "unset"<br> ],<br> "name": null,<br> "namespace": null,<br> "regex_replace_chars": null,<br> "stage": null,<br> "tags": {},<br> "tenant": null<br>}</pre> | no |
48+
| <a name="input_deletion_protection_enabled"></a> [deletion\_protection\_enabled](#input\_deletion\_protection\_enabled) | Enable/disable DynamoDB table deletion protection | `bool` | `false` | no |
4849
| <a name="input_delimiter"></a> [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.<br>Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
4950
| <a name="input_descriptor_formats"></a> [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.<br>Map of maps. Keys are names of descriptors. Values are maps of the form<br>`{<br> format = string<br> labels = list(string)<br>}`<br>(Type is `any` so the map values can later be enhanced to provide additional options.)<br>`format` is a Terraform format string to be passed to the `format()` function.<br>`labels` is a list of labels, in order, to pass to `format()` function.<br>Label values will be normalized before being passed to `format()` so they will be<br>identical to how they appear in `id`.<br>Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
5051
| <a name="input_dynamodb_attributes"></a> [dynamodb\_attributes](#input\_dynamodb\_attributes) | Additional DynamoDB attributes in the form of a list of mapped values | <pre>list(object({<br> name = string<br> type = string<br> }))</pre> | `[]` | no |

main.tf

+14-14
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,17 @@ resource "null_resource" "local_secondary_index_names" {
4444
}
4545

4646
resource "aws_dynamodb_table" "default" {
47-
count = local.enabled ? 1 : 0
48-
name = module.this.id
49-
billing_mode = var.billing_mode
50-
read_capacity = var.billing_mode == "PAY_PER_REQUEST" ? null : var.autoscale_min_read_capacity
51-
write_capacity = var.billing_mode == "PAY_PER_REQUEST" ? null : var.autoscale_min_write_capacity
52-
hash_key = var.hash_key
53-
range_key = var.range_key
54-
stream_enabled = length(var.replicas) > 0 ? true : var.enable_streams
55-
stream_view_type = length(var.replicas) > 0 || var.enable_streams ? var.stream_view_type : ""
56-
table_class = var.table_class
57-
47+
count = local.enabled ? 1 : 0
48+
name = module.this.id
49+
billing_mode = var.billing_mode
50+
read_capacity = var.billing_mode == "PAY_PER_REQUEST" ? null : var.autoscale_min_read_capacity
51+
write_capacity = var.billing_mode == "PAY_PER_REQUEST" ? null : var.autoscale_min_write_capacity
52+
hash_key = var.hash_key
53+
range_key = var.range_key
54+
stream_enabled = length(var.replicas) > 0 ? true : var.enable_streams
55+
stream_view_type = length(var.replicas) > 0 || var.enable_streams ? var.stream_view_type : ""
56+
table_class = var.table_class
57+
deletion_protection_enabled = var.deletion_protection_enabled
5858

5959
server_side_encryption {
6060
enabled = var.enable_encryption
@@ -132,9 +132,9 @@ module "dynamodb_autoscaler" {
132132

133133
attributes = concat(module.this.attributes, var.autoscaler_attributes)
134134
tags = var.tags_enabled ? merge(module.this.tags, var.autoscaler_tags) : null
135-
dynamodb_table_name = join("", aws_dynamodb_table.default.*.id)
136-
dynamodb_table_arn = join("", aws_dynamodb_table.default.*.arn)
137-
dynamodb_indexes = null_resource.global_secondary_index_names.*.triggers.name
135+
dynamodb_table_name = join("", aws_dynamodb_table.default[*].id)
136+
dynamodb_table_arn = join("", aws_dynamodb_table.default[*].arn)
137+
dynamodb_indexes = null_resource.global_secondary_index_names[*].triggers.name
138138
autoscale_write_target = var.autoscale_write_target
139139
autoscale_read_target = var.autoscale_read_target
140140
autoscale_min_read_capacity = var.autoscale_min_read_capacity

outputs.tf

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
11
output "table_name" {
2-
value = join("", aws_dynamodb_table.default.*.name)
2+
value = join("", aws_dynamodb_table.default[*].name)
33
description = "DynamoDB table name"
44
}
55

66
output "table_id" {
7-
value = join("", aws_dynamodb_table.default.*.id)
7+
value = join("", aws_dynamodb_table.default[*].id)
88
description = "DynamoDB table ID"
99
}
1010

1111
output "table_arn" {
12-
value = join("", aws_dynamodb_table.default.*.arn)
12+
value = join("", aws_dynamodb_table.default[*].arn)
1313
description = "DynamoDB table ARN"
1414
}
1515

1616
output "global_secondary_index_names" {
17-
value = null_resource.global_secondary_index_names.*.triggers.name
17+
value = null_resource.global_secondary_index_names[*].triggers.name
1818
description = "DynamoDB secondary index names"
1919
}
2020

2121
output "local_secondary_index_names" {
22-
value = null_resource.local_secondary_index_names.*.triggers.name
22+
value = null_resource.local_secondary_index_names[*].triggers.name
2323
description = "DynamoDB local index names"
2424
}
2525

2626
output "table_stream_arn" {
27-
value = join("", aws_dynamodb_table.default.*.stream_arn)
27+
value = join("", aws_dynamodb_table.default[*].stream_arn)
2828
description = "DynamoDB table stream ARN"
2929
}
3030

3131
output "table_stream_label" {
32-
value = join("", aws_dynamodb_table.default.*.stream_label)
32+
value = join("", aws_dynamodb_table.default[*].stream_label)
3333
description = "DynamoDB table stream label"
3434
}

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -174,3 +174,9 @@ variable "table_class" {
174174
default = "STANDARD"
175175
description = "DynamoDB storage class of the table. Can be STANDARD or STANDARD_INFREQUENT_ACCESS"
176176
}
177+
178+
variable "deletion_protection_enabled" {
179+
type = bool
180+
default = false
181+
description = "Enable/disable DynamoDB table deletion protection"
182+
}

versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 4.22"
7+
version = ">= 4.59"
88
}
99
null = {
1010
source = "hashicorp/null"

0 commit comments

Comments
 (0)