Skip to content

Commit

Permalink
Fix logic for optional dynamodb table (#103)
Browse files Browse the repository at this point in the history
* 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 <11232728+cloudpossebot@users.noreply.github.com>
  • Loading branch information
thiagoalmeidasa and cloudpossebot authored Nov 22, 2021
1 parent 9fa8fdc commit 3a7cc2e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ locals {
bucket_enabled = local.enabled && var.bucket_enabled
dynamodb_enabled = local.enabled && var.dynamodb_enabled

dynamodb_table_name = coalesce(var.dynamodb_table_name, module.dynamodb_table_label.id)
dynamodb_table_name = local.dynamodb_enabled ? coalesce(var.dynamodb_table_name, module.dynamodb_table_label.id) : ""

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

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

dynamodb_table = element(
dynamodb_table = local.dynamodb_enabled ? element(
coalescelist(
aws_dynamodb_table.with_server_side_encryption.*.name,
aws_dynamodb_table.without_server_side_encryption.*.name
),
0
)
) : ""

encrypt = var.enable_server_side_encryption ? "true" : "false"
role_arn = var.role_arn
Expand Down
2 changes: 2 additions & 0 deletions templates/terraform.tf.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ terraform {
region = "${region}"
bucket = "${bucket}"
key = "${terraform_state_file}"
%{~ if dynamodb_table != "" ~}
dynamodb_table = "${dynamodb_table}"
%{~ endif ~}
profile = "${profile}"
role_arn = "${role_arn}"
encrypt = "${encrypt}"
Expand Down

0 comments on commit 3a7cc2e

Please sign in to comment.