Skip to content

Commit

Permalink
feat: Skip legacy modules (with provider block) in terraform_wrapper_…
Browse files Browse the repository at this point in the history
…module_for_each hook (#560)
  • Loading branch information
ajax-ryzhyi-r committed Aug 25, 2023
1 parent 0e2b151 commit 456cc76
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions hooks/terraform_wrapper_module_for_each.sh
Expand Up @@ -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//[^\/]/}"

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 456cc76

Please sign in to comment.