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

Support provider-defined functions #214

Merged
merged 1 commit into from
Sep 27, 2024

Conversation

bgpat
Copy link
Contributor

@bgpat bgpat commented Sep 26, 2024

Fixes #213

This PR addresses an issue with the terraform_unused_required_providers rule, which does not currently support provider-defined functions introduced in Terraform 1.8. As a result, valid configurations using these functions were incorrectly flagged as unused providers.

Changes:

  • Updated the GetProviderRefs function to correctly recognize provider references in provider-defined functions by walking through expressions and identifying function calls with the provider:: prefix.
  • Added logic to extract provider names from these function calls and include them in the set of used providers, preventing false positives in the terraform_unused_required_providers rule.
  • Additionally, since GetProviderRefs is also utilized by the terraform_required_providers rule, this update enables the correct detection of provider-defined functions in this rule as well.

@bendrucker bendrucker self-requested a review September 26, 2024 21:33
Copy link
Member

@bendrucker bendrucker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! For reference here is Terraform adding the provider functions:

https://github.com/hashicorp/terraform/blob/b676aeb6941b234a6dd58bb2fb59d2cfd3e5abe2/internal/lang/functions.go#L231

And a case where it parses them for improved error diags:

https://github.com/hashicorp/terraform/blob/b676aeb6941b234a6dd58bb2fb59d2cfd3e5abe2/internal/lang/eval.go#L500-L582

Which helps confirm that :: as a function namespace is a Terraform construct. And we can safely parse just by splitting.

@bendrucker bendrucker merged commit 34423f6 into terraform-linters:main Sep 27, 2024
2 checks passed
@bgpat bgpat deleted the provider-defined-functions branch September 27, 2024 06:34
wata727 added a commit that referenced this pull request Oct 16, 2024
wata727 added a commit that referenced this pull request Nov 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

terraform_unused_required_providers does not support provider-defined functions
2 participants