Skip to content

Commit 7710871

Browse files
authored
feat(terraform_wrapper_module_for_each): Strip provider_meta blocks from versions.tf (#967)
The hook copies the source module's `versions.tf` into the generated wrapper verbatim. When the source carries a `provider_meta` block (used by terraform-aws-modules to tag the provider user-agent), the wrapper ends up declaring it too, so every provider call from a wrappered module sends the same user-agent fragment twice. Filter `provider_meta` blocks out while copying. `required_version` and `required_providers` are preserved. --------- Signed-off-by: pen-pal <unameme@proton.me>
1 parent c838f02 commit 7710871

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

hooks/terraform_wrapper_module_for_each.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,14 @@ EOF
394394

395395
echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf"
396396

397-
# If the root module has a versions.tf, use that; otherwise, create it
397+
# If the root module has a versions.tf, use that; otherwise, create it.
398398
if [[ -f "${full_module_dir}/versions.tf" ]]; then
399399
cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf"
400+
# Don't propagate redundant `provider_meta` attributes
401+
# AWS-provider specific
402+
hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" -f "${output_dir}/versions.tf" -u
403+
# GCP-provider specific
404+
hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" -f "${output_dir}/versions.tf" -u
400405
else
401406
echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf"
402407
fi

0 commit comments

Comments
 (0)