Skip to content

Commit a8795cf

Browse files
nitrocodecloudpossebotaknysh
authored
Dynamodb table name (#97)
* dynamodb_table_name * dynamodb_table_name * Auto Format * Update variables.tf Co-authored-by: Andriy Knysh <[email protected]> * Auto Format * Update main.tf * Update main.tf Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: Andriy Knysh <[email protected]>
1 parent d084523 commit a8795cf

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ Available targets:
300300
| <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 |
301301
| <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 |
302302
| <a name="input_dynamodb_enabled"></a> [dynamodb\_enabled](#input\_dynamodb\_enabled) | Whether to create the dynamodb table. | `bool` | `true` | no |
303+
| <a name="input_dynamodb_table_name"></a> [dynamodb\_table\_name](#input\_dynamodb\_table\_name) | Override the name of the DynamoDB table which defaults to using `module.dynamodb_table_label.id` | `string` | `null` | no |
303304
| <a name="input_enable_point_in_time_recovery"></a> [enable\_point\_in\_time\_recovery](#input\_enable\_point\_in\_time\_recovery) | Enable DynamoDB point-in-time recovery | `bool` | `true` | no |
304305
| <a name="input_enable_public_access_block"></a> [enable\_public\_access\_block](#input\_enable\_public\_access\_block) | Enable Bucket Public Access Block | `bool` | `true` | no |
305306
| <a name="input_enable_server_side_encryption"></a> [enable\_server\_side\_encryption](#input\_enable\_server\_side\_encryption) | Enable DynamoDB server-side encryption | `bool` | `true` | no |

docs/terraform.md

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
| <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 |
5656
| <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 |
5757
| <a name="input_dynamodb_enabled"></a> [dynamodb\_enabled](#input\_dynamodb\_enabled) | Whether to create the dynamodb table. | `bool` | `true` | no |
58+
| <a name="input_dynamodb_table_name"></a> [dynamodb\_table\_name](#input\_dynamodb\_table\_name) | Override the name of the DynamoDB table which defaults to using `module.dynamodb_table_label.id` | `string` | `null` | no |
5859
| <a name="input_enable_point_in_time_recovery"></a> [enable\_point\_in\_time\_recovery](#input\_enable\_point\_in\_time\_recovery) | Enable DynamoDB point-in-time recovery | `bool` | `true` | no |
5960
| <a name="input_enable_public_access_block"></a> [enable\_public\_access\_block](#input\_enable\_public\_access\_block) | Enable Bucket Public Access Block | `bool` | `true` | no |
6061
| <a name="input_enable_server_side_encryption"></a> [enable\_server\_side\_encryption](#input\_enable\_server\_side\_encryption) | Enable DynamoDB server-side encryption | `bool` | `true` | no |

main.tf

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ locals {
44
bucket_enabled = local.enabled && var.bucket_enabled
55
dynamodb_enabled = local.enabled && var.dynamodb_enabled
66

7+
dynamodb_table_name = coalesce(var.dynamodb_table_name, module.dynamodb_table_label.id)
8+
79
prevent_unencrypted_uploads = local.enabled && var.prevent_unencrypted_uploads && var.enable_server_side_encryption
810

911
policy = local.prevent_unencrypted_uploads ? join(
@@ -201,7 +203,7 @@ module "dynamodb_table_label" {
201203

202204
resource "aws_dynamodb_table" "with_server_side_encryption" {
203205
count = local.dynamodb_enabled && var.enable_server_side_encryption ? 1 : 0
204-
name = module.dynamodb_table_label.id
206+
name = local.dynamodb_table_name
205207
billing_mode = var.billing_mode
206208
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
207209
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null
@@ -227,7 +229,7 @@ resource "aws_dynamodb_table" "with_server_side_encryption" {
227229

228230
resource "aws_dynamodb_table" "without_server_side_encryption" {
229231
count = local.dynamodb_enabled && ! var.enable_server_side_encryption ? 1 : 0
230-
name = module.dynamodb_table_label.id
232+
name = local.dynamodb_table_name
231233
billing_mode = var.billing_mode
232234
read_capacity = var.billing_mode == "PROVISIONED" ? var.read_capacity : null
233235
write_capacity = var.billing_mode == "PROVISIONED" ? var.write_capacity : null

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,9 @@ variable "dynamodb_enabled" {
164164
default = true
165165
description = "Whether to create the dynamodb table."
166166
}
167+
168+
variable "dynamodb_table_name" {
169+
type = string
170+
default = null
171+
description = "Override the name of the DynamoDB table which defaults to using `module.dynamodb_table_label.id`"
172+
}

0 commit comments

Comments
 (0)