Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Skip legacy modules (with provider block) in terraform_wrapper_module_for_each hook #560

Merged
merged 1 commit into from
Aug 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions hooks/terraform_wrapper_module_for_each.sh
Original file line number Diff line number Diff line change
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