From e1017e1bfbf1369e9cde8ebbdbdb1290c448a08b Mon Sep 17 00:00:00 2001 From: penpal Date: Mon, 25 May 2026 14:53:24 +0545 Subject: [PATCH 1/5] fix(`terraform_wrapper_module_for_each`): strip `provider_meta` blocks from wrapper `versions.tf` 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. Fixes #954 Signed-off-by: pen-pal --- hooks/terraform_wrapper_module_for_each.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index 24a3a465b..e657342e5 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -394,9 +394,15 @@ EOF echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf" - # If the root module has a versions.tf, use that; otherwise, create it + # If the root module has a versions.tf, use that; otherwise, create it. + # Strip `provider_meta` blocks so wrappers don't duplicate the module's + # user-agent tag on every provider call (see #954). if [[ -f "${full_module_dir}/versions.tf" ]]; then - cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" + awk ' + /^[[:space:]]*provider_meta[[:space:]]+"[^"]+"[[:space:]]*\{[[:space:]]*$/ { in_block = 1; next } + in_block && /^[[:space:]]*\}[[:space:]]*$/ { in_block = 0; next } + !in_block { print } + ' "${full_module_dir}/versions.tf" > "${output_dir}/versions.tf" else echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" fi From a41d24cb68776d1af352bd6035438a9db1075fc5 Mon Sep 17 00:00:00 2001 From: penpal Date: Tue, 26 May 2026 12:17:51 +0545 Subject: [PATCH 2/5] refactor(`terraform_wrapper_module_for_each`): use `hcledit` instead of `awk` to strip `provider_meta` attrs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Address #967 review: - `hcledit` is already a hard dep of this hook, so no new tooling. - Structural edit survives a hypothetical nested block inside `provider_meta` (where the `awk` filter would mangle the closing brace). - Target only the configured provider via `${module_repo_provider}`, so unrelated `provider_meta` blocks (e.g. for non-AWS providers) are preserved. - Strip both `user_agent` and legacy `module_name` keys. The (possibly now-empty) `provider_meta` block itself remains since `hcledit` cannot remove nested blocks — it is functionally harmless. Signed-off-by: penpal --- hooks/terraform_wrapper_module_for_each.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index e657342e5..af135638c 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -395,14 +395,13 @@ EOF echo "$CONTENT_VARIABLES_TF" > "${output_dir}/variables.tf" # If the root module has a versions.tf, use that; otherwise, create it. - # Strip `provider_meta` blocks so wrappers don't duplicate the module's - # user-agent tag on every provider call (see #954). if [[ -f "${full_module_dir}/versions.tf" ]]; then - awk ' - /^[[:space:]]*provider_meta[[:space:]]+"[^"]+"[[:space:]]*\{[[:space:]]*$/ { in_block = 1; next } - in_block && /^[[:space:]]*\}[[:space:]]*$/ { in_block = 0; next } - !in_block { print } - ' "${full_module_dir}/versions.tf" > "${output_dir}/versions.tf" + cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" + # Don't propagate redundant `provider_meta` user-agent attrs (#954). + hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" \ + -f "${output_dir}/versions.tf" -u + hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" \ + -f "${output_dir}/versions.tf" -u else echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" fi From 9ef469ab74afb2d2bc02b3bad83748393f80ecc3 Mon Sep 17 00:00:00 2001 From: penpal Date: Fri, 29 May 2026 09:39:19 +0545 Subject: [PATCH 3/5] add comment of associate cloud with hcledit Signed-off-by: penpal --- hooks/terraform_wrapper_module_for_each.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index af135638c..5413a948a 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -398,10 +398,10 @@ EOF if [[ -f "${full_module_dir}/versions.tf" ]]; then cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" # Don't propagate redundant `provider_meta` user-agent attrs (#954). - hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" \ - -f "${output_dir}/versions.tf" -u - hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" \ - -f "${output_dir}/versions.tf" -u + # sepcific to aws cloud only + hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" -f "${output_dir}/versions.tf" -u + # specific to gcp cloud only + hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" -f "${output_dir}/versions.tf" -u else echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" fi From 3cede7adcf192ce7b87257e568d1eb68a7b0920c Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Sat, 30 May 2026 02:56:59 +0300 Subject: [PATCH 4/5] Update hooks/terraform_wrapper_module_for_each.sh --- hooks/terraform_wrapper_module_for_each.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index 5413a948a..9cf5a5bd4 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -397,10 +397,10 @@ EOF # If the root module has a versions.tf, use that; otherwise, create it. if [[ -f "${full_module_dir}/versions.tf" ]]; then cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" - # Don't propagate redundant `provider_meta` user-agent attrs (#954). - # sepcific to aws cloud only + # Don't propagate redundant `provider_meta` attributes + # AWS specific hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" -f "${output_dir}/versions.tf" -u - # specific to gcp cloud only + # GCP specific hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" -f "${output_dir}/versions.tf" -u else echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf" From 364281f923bc5abaf96f70f0c68c9da909d94ad5 Mon Sep 17 00:00:00 2001 From: Maksym Vlasov Date: Sat, 30 May 2026 02:58:26 +0300 Subject: [PATCH 5/5] Update hooks/terraform_wrapper_module_for_each.sh --- hooks/terraform_wrapper_module_for_each.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hooks/terraform_wrapper_module_for_each.sh b/hooks/terraform_wrapper_module_for_each.sh index 9cf5a5bd4..9d47cf599 100755 --- a/hooks/terraform_wrapper_module_for_each.sh +++ b/hooks/terraform_wrapper_module_for_each.sh @@ -398,9 +398,9 @@ EOF if [[ -f "${full_module_dir}/versions.tf" ]]; then cp "${full_module_dir}/versions.tf" "${output_dir}/versions.tf" # Don't propagate redundant `provider_meta` attributes - # AWS specific + # AWS-provider specific hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.user_agent" -f "${output_dir}/versions.tf" -u - # GCP specific + # GCP-provider specific hcledit attribute rm "terraform.provider_meta.${module_repo_provider}.module_name" -f "${output_dir}/versions.tf" -u else echo "$CONTENT_VERSIONS_TF" > "${output_dir}/versions.tf"