Skip to content

Commit b127601

Browse files
nshenry03Nick Henry
andauthored
feat: Hook terraform_wrapper_module_for_each should use versions.tf from the module if it exists (antonbabenko#657)
Co-authored-by: Nick Henry <[email protected]>
1 parent 42919f3 commit b127601

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

hooks/terraform_wrapper_module_for_each.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,13 @@ EOF
393393
mv "$tmp_file_tf" "${output_dir}/main.tf"
394394

395395
echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf"
396-
echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf"
396+
397+
# If the root module has a versions.tf, use that; otherwise, create it
398+
if [[ -f "${full_module_dir}/versions.tf" ]]; then
399+
cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf"
400+
else
401+
echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf"
402+
fi
397403

398404
echo "$CONTENT_OUTPUTS_TF" > "${output_dir}/outputs.tf"
399405
sed -i.bak "s|WRAPPER_OUTPUT_SENSITIVE|${wrapper_output_sensitive}|g" "${output_dir}/outputs.tf"

0 commit comments

Comments
 (0)