diff --git a/main.tf b/main.tf index 4fa1f5f..3c19190 100644 --- a/main.tf +++ b/main.tf @@ -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 @@ -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 diff --git a/templates/terraform.tf.tpl b/templates/terraform.tf.tpl index 4563ddf..ee0e8fd 100644 --- a/templates/terraform.tf.tpl +++ b/templates/terraform.tf.tpl @@ -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}"