Skip to content

Commit 3a7cc2e

Browse files
Fix logic for optional dynamodb table (#103)
* Fix dynamodb optional parameter. Fixed some template logic and locals that didn't work out of the box with the optional dynamodb table creation. * Auto Format * Revert dynamodb_table_name output value The table name is derived from the resource itself. * Auto Format Co-authored-by: cloudpossebot <[email protected]>
1 parent 9fa8fdc commit 3a7cc2e

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

main.tf

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ 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)
7+
dynamodb_table_name = local.dynamodb_enabled ? coalesce(var.dynamodb_table_name, module.dynamodb_table_label.id) : ""
88

99
prevent_unencrypted_uploads = local.enabled && var.prevent_unencrypted_uploads && var.enable_server_side_encryption
1010

@@ -25,13 +25,13 @@ locals {
2525
region = data.aws_region.current.name
2626
bucket = join("", aws_s3_bucket.default.*.id)
2727

28-
dynamodb_table = element(
28+
dynamodb_table = local.dynamodb_enabled ? element(
2929
coalescelist(
3030
aws_dynamodb_table.with_server_side_encryption.*.name,
3131
aws_dynamodb_table.without_server_side_encryption.*.name
3232
),
3333
0
34-
)
34+
) : ""
3535

3636
encrypt = var.enable_server_side_encryption ? "true" : "false"
3737
role_arn = var.role_arn

templates/terraform.tf.tpl

+2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ terraform {
55
region = "${region}"
66
bucket = "${bucket}"
77
key = "${terraform_state_file}"
8+
%{~ if dynamodb_table != "" ~}
89
dynamodb_table = "${dynamodb_table}"
10+
%{~ endif ~}
911
profile = "${profile}"
1012
role_arn = "${role_arn}"
1113
encrypt = "${encrypt}"

0 commit comments

Comments
 (0)