From 92085dcdf971e97b12d1a88190ff6272537fbf63 Mon Sep 17 00:00:00 2001 From: Nick Henry Date: Wed, 10 Apr 2024 15:06:03 -0600 Subject: [PATCH] fix: Use root module versions.tf if it exists --- hooks/terraform_wrapper_module_for_each.sh | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index b01fe4601..e9a98e2a3 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -393,7 +393,13 @@ EOF mv "$tmp_file_tf" "${output_dir}/main.tf" echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf" - echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" + + # If the root module has a versions.tf, use that; otherwise, create it + if [[ -f "${full_module_dir}/versions.tf" ]]; then + cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" + else + echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" + fi echo "$CONTENT_OUTPUTS_TF" > "${output_dir}/outputs.tf" sed -i.bak "s|WRAPPER_OUTPUT_SENSITIVE|${wrapper_output_sensitive}|g" "${output_dir}/outputs.tf"