From c66c0a663e56e6e8f5562e3d5828ced932df2e23 Mon Sep 17 00:00:00 2001 From: Hamza aziz <56886089+Hamza-Aziz@users.noreply.github.com> Date: Thu, 7 Mar 2024 15:33:11 +0100 Subject: [PATCH] feature: Add support for deletion_protection_enabled attribute for DynamoDB (#156) * feat: support Dynamodb deletion_protection_enabled attribute * feat: support Dynamodb deletion_protection_enabled attribute * Generated readme * Update readme * Fix: make deletion_protection_enabled defaults to false * Update readme --------- Co-authored-by: Hans D --- README.md | 1 + docs/terraform.md | 1 + main.tf | 11 ++++++----- variables.tf | 7 +++++++ 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 822bf61..884cc1a 100644 --- a/README.md +++ b/README.md @@ -278,6 +278,7 @@ Available targets: | [bucket\_enabled](#input\_bucket\_enabled) | Whether to create the S3 bucket. | `bool` | `true` | no | | [bucket\_ownership\_enforced\_enabled](#input\_bucket\_ownership\_enforced\_enabled) | Set bucket object ownership to "BucketOwnerEnforced". Disables ACLs. | `bool` | `true` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | +| [deletion\_protection\_enabled](#input\_deletion\_protection\_enabled) | A boolean that enables deletion protection for DynamoDB table | `bool` | `false` | no | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | | [dynamodb\_enabled](#input\_dynamodb\_enabled) | Whether to create the DynamoDB table. | `bool` | `true` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 3e386b1..76301ab 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -64,6 +64,7 @@ | [bucket\_enabled](#input\_bucket\_enabled) | Whether to create the S3 bucket. | `bool` | `true` | no | | [bucket\_ownership\_enforced\_enabled](#input\_bucket\_ownership\_enforced\_enabled) | Set bucket object ownership to "BucketOwnerEnforced". Disables ACLs. | `bool` | `true` | no | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` |
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no | +| [deletion\_protection\_enabled](#input\_deletion\_protection\_enabled) | A boolean that enables deletion protection for DynamoDB table | `bool` | `false` | no | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no | | [dynamodb\_enabled](#input\_dynamodb\_enabled) | Whether to create the DynamoDB table. | `bool` | `true` | no | diff --git a/main.tf b/main.tf index bf9bab2..6ad19f0 100644 --- a/main.tf +++ b/main.tf @@ -257,11 +257,12 @@ module "dynamodb_table_label" { } resource "aws_dynamodb_table" "with_server_side_encryption" { - count = local.dynamodb_enabled ? 1 : 0 - name = local.dynamodb_table_name - billing_mode = var.billing_mode - read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null - write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null + count = local.dynamodb_enabled ? 1 : 0 + name = local.dynamodb_table_name + billing_mode = var.billing_mode + read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null + write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null + deletion_protection_enabled = var.deletion_protection_enabled # https://www.terraform.io/docs/backends/types/s3.html#dynamodb_table hash_key = "LockID" diff --git a/variables.tf b/variables.tf index b6f31ab..59925a9 100644 --- a/variables.tf +++ b/variables.tf @@ -34,6 +34,13 @@ variable "force_destroy" { default = false } +variable "deletion_protection_enabled" { + type = bool + description = "A boolean that enables deletion protection for DynamoDB table" + default = false +} + + variable "mfa_delete" { type = bool description = "A boolean that indicates that versions of S3 objects can only be deleted with MFA. ( Terraform cannot apply changes of this value; https://github.com/terraform-providers/terraform-provider-aws/issues/629 )"