Skip to content

Commit 6fd4263

Browse files
fix: Fix terraform_wrapper_module_for_each hook heredoc vars defaults (antonbabenko#554)
1 parent 9fe5655 commit 6fd4263

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

hooks/terraform_wrapper_module_for_each.sh

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,11 +323,11 @@ EOF
323323

324324
# Get names of module variables in all terraform files
325325
# shellcheck disable=SC2207
326-
module_vars=($(echo "$all_tf_content" | hcledit block list | { grep variable. || true; } | cut -d'.' -f 2))
326+
module_vars=($(echo "$all_tf_content" | hcledit block list | { grep variable. | cut -d'.' -f 2 || true; }))
327327

328328
# Get names of module outputs in all terraform files
329329
# shellcheck disable=SC2207
330-
module_outputs=($(echo "$all_tf_content" | hcledit block list | { grep output. || true; } | cut -d'.' -f 2))
330+
module_outputs=($(echo "$all_tf_content" | hcledit block list | { grep output. | cut -d'.' -f 2 || true; }))
331331

332332
# Looking for sensitive output
333333
local wrapper_output_sensitive="# sensitive = false # No sensitive module output found"
@@ -360,6 +360,13 @@ EOF
360360
# https://github.com/terraform-aws-modules/terraform-aws-security-group/blob/0bd31aa88339194efff470d3b3f58705bd008db0/rules.tf#L8
361361
# As a result, wrappers in terraform-aws-security-group module are missing values of the rules variable and is not useful. :(
362362
var_value="try(each.value.${module_var}, var.defaults.${module_var}, {})"
363+
elif [[ $var_default == \<\<* ]]; then
364+
# Heredoc style default values produce HCL parsing error:
365+
# 'Unterminated template string; No closing marker was found for the string.'
366+
# Because closing marker must be alone on it's own line:
367+
# https://developer.hashicorp.com/terraform/language/expressions/strings#heredoc-strings
368+
var_value="try(each.value.${module_var}, var.defaults.${module_var}, $var_default
369+
)"
363370
else
364371
var_value="try(each.value.${module_var}, var.defaults.${module_var}, $var_default)"
365372
fi

0 commit comments

Comments
 (0)