feat(terraform_wrapper_module_for_each): Strip provider_meta blocks from versions.tf#967
Conversation
…s 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 antonbabenko#954 Signed-off-by: pen-pal <unameme@proton.me>
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe wrapper now copies a module's ChangesProvider Meta Filtering in Terraform Wrapper
Sequence Diagram(s)sequenceDiagram
participant Wrapper
participant SourceModule
participant OutputDir
Wrapper->>SourceModule: read versions.tf
Wrapper->>Wrapper: strip terraform.provider_meta.<provider>.user_agent and .module_name
Wrapper->>OutputDir: write filtered versions.tf
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
terraform_wrapper_module_for_each): strip provider_meta block…provider_meta blocks from wrapper versions.tf
|
@pen-pal Thanks for the contribution.
What's wrong with such duplication? Does it impact/break something? What's the drawback of leaving Also given that Apart from that, I guess it's best to strip the Also (and it's probably my main concern) if by any reason the AWS provider's > cat ~/tmp/versions.tf
terraform {
provider_meta "aws" {
user_agent = [
"github.com/terraform-aws-modules/terraform-aws-s3-bucket"
]
hypthetical_nested_block {
key = "value"
}
}
}
> cat ~/tmp/versions.tf | awk '/^[[:space:]]*provider_meta[[:space:]]+"[^"]+"[[:space:]]*\{[[:space:]]*$/ { in_block = 1; next }; in_block && /^[[:space:]]*\}[[:space:]]*$/ { in_block = 0; next }; !in_block { print }'
terraform {
}
}To avoid such — though still hypothetical — confusion, we're better off scaffolding some other solution I reckon.
|
…of `awk` to strip `provider_meta` attrs Address antonbabenko#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 <unameme@proton.me>
@yermulnik made some updates based on suggestion. |
Thank you. |
yermulnik
left a comment
There was a problem hiding this comment.
LGTM
@MaxymVlasov Could you please take a look too? Thanks
Signed-off-by: penpal <unameme@proton.me>
provider_meta blocks from wrapper versions.tfterraform_wrapper_module_for_each): Strip provider_meta blocks from versions.tf
# [1.106.0](v1.105.0...v1.106.0) (2026-05-30) ### Features * **`terraform_wrapper_module_for_each`:** Strip `provider_meta` blocks from `versions.tf` ([#967](#967)) ([7710871](7710871))
|
This PR is included in version 1.106.0 🎉 |
Description of your changes
The hook copies the source module's
versions.tfinto the wrapper verbatim. If the source declares aprovider_metablock (used by terraform-aws-modules to tag the provider's user-agent), the wrapper inherits it. The wrapper makes no provider calls itself, so that propagation is redundant and skews module-usage telemetry.Uses
hcledit(already a hook dependency, seecheck_dependenciesathooks/terraform_wrapper_module_for_each.sh:430) to removeuser_agentandmodule_namefor the provider configured via--module-repo-provider. The edit is structural:provider_metaare untouched.provider_metablocks are untouched.provider_meta(e.g. if the AWS provider extends the schema) is preserved.Cosmetic caveat: the (possibly now-empty)
provider_metablock itself remains, becausehcleditcannot remove nested blocks. Functionally harmless — no attributes ⇒ no user-agent contribution.Fixes #954
How can we test changes
Run the hook against a module whose
versions.tfhas aprovider_metablock (e.g. anyterraform-aws-modulesrepo):Tested against hypothetical value:
input
after the hook
user_agent cleanly removed, nested block intact.