From b127601a0b3d5af3dcc9f91a6d74e16f37d66a60 Mon Sep 17 00:00:00 2001 From: Nicholas Henry Date: Mon, 15 Apr 2024 12:35:03 -0600 Subject: [PATCH] feat: Hook terraform_wrapper_module_for_each should use versions.tf from the module if it exists (#657) Co-authored-by: Nick Henry --- 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"