mirror of
https://github.com/tofuutils/pre-commit-opentofu.git
synced 2025-10-15 17:38:54 +02:00
feat: Skip legacy modules (with provider block) in terraform_wrapper_module_for_each hook (#560)
This commit is contained in:
parent
0e2b15175d
commit
456cc7616a
1 changed files with 11 additions and 2 deletions
|
|
@ -291,8 +291,6 @@ EOF
|
|||
# Wrappers will be stored in "wrappers/{module_name}"
|
||||
output_dir="${root_dir}/${wrapper_dir}/${module_name}"
|
||||
|
||||
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
|
||||
|
||||
# Calculate relative depth for module source by number of slashes
|
||||
module_depth="${module_dir//[^\/]/}"
|
||||
|
||||
|
|
@ -329,6 +327,14 @@ EOF
|
|||
# shellcheck disable=SC2207
|
||||
module_outputs=($(echo "$all_tf_content" | hcledit block list | { grep output. | cut -d'.' -f 2 || true; }))
|
||||
|
||||
# Get names of module providers in all terraform files
|
||||
module_providers=$(echo "$all_tf_content" | hcledit block list | { grep provider. || true; })
|
||||
|
||||
if [[ $module_providers ]]; then
|
||||
common::colorify "yellow" "Skipping ${full_module_dir} because it is a legacy module which contains its own local provider configurations and so calls to it may not use the for_each argument."
|
||||
break
|
||||
fi
|
||||
|
||||
# Looking for sensitive output
|
||||
local wrapper_output_sensitive="# sensitive = false # No sensitive module output found"
|
||||
for module_output in "${module_outputs[@]}"; do
|
||||
|
|
@ -381,6 +387,9 @@ EOF
|
|||
if [[ "$dry_run" == "false" ]]; then
|
||||
common::colorify "green" "Saving files into \"${output_dir}\""
|
||||
|
||||
# Create output dir
|
||||
[[ ! -d "$output_dir" ]] && mkdir -p "$output_dir"
|
||||
|
||||
mv "$tmp_file_tf" "${output_dir}/main.tf"
|
||||
|
||||
echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue