Skip to content

Allow calling provider-defined functions with variadic arguments #2340

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

Merged
merged 1 commit into from
Jul 12, 2025

Conversation

wata727
Copy link
Member

@wata727 wata727 commented Jul 8, 2025

Fixes #2339
Follow up of #2030

Because TFLint cannot statically infer the behavior of provider-defined functions, we took the approach of inferring the function interface from function calls when parsing the HCL and generating mock functions.

As part of this, mocks were generated as fixed-length functions based on the number of arguments, which caused errors when calling provider-defined functions that accepted variadic argument, such as provider::deepmerge::merge, with a different number of arguments from the second time onwards.

This change fixes this issue by generating mock functions as always accepting variadic arguments.

Because TFLint cannot statically infer the behavior of provider-defined
functions, we took the approach of inferring the function interface
from function calls when parsing the HCL and generating mock functions.

As part of this, mocks were generated as fixed-length functions
based on the number of arguments, which caused errors when calling
provider-defined functions that accepted variadic argument,
such as `provider::deepmerge::merge`, with a different number of
arguments from the second time onwards.

This change fixes this issue by generating mock functions as always
accepting variadic arguments.
@wata727 wata727 merged commit 827dd96 into master Jul 12, 2025
19 checks passed
@wata727 wata727 deleted the variadic_arguments_function_mocks branch July 12, 2025 08:18
tmeijn pushed a commit to tmeijn/dotfiles that referenced this pull request Jul 28, 2025
This MR contains the following updates:

| Package | Update | Change |
|---|---|---|
| [tflint](https://github.com/terraform-linters/tflint) | patch | `0.58.0` -> `0.58.1` |

MR created with the help of [el-capitano/tools/renovate-bot](https://gitlab.com/el-capitano/tools/renovate-bot).

**Proposed changes to behavior should be submitted there as MRs.**

---

### Release Notes

<details>
<summary>terraform-linters/tflint (tflint)</summary>

### [`v0.58.1`](https://github.com/terraform-linters/tflint/releases/tag/v0.58.1)

[Compare Source](terraform-linters/tflint@v0.58.0...v0.58.1)

#### What's Changed

##### Bug Fixes

- Allow calling provider-defined functions with variadic arguments by [@&#8203;wata727](https://github.com/wata727) in terraform-linters/tflint#2340

##### Chores

- build(deps): Bump google.golang.org/grpc from 1.72.1 to 1.72.2 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2322
- build(deps): Bump mislav/bump-homebrew-formula-action from 3.2 to 3.3 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2324
- build(deps): Bump docker/build-push-action from 6.17.0 to 6.18.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2326
- build(deps): Bump alpine from 3.21 to 3.22 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2325
- build(deps): Bump mislav/bump-homebrew-formula-action from 3.3 to 3.4 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2327
- build(deps): Bump the go-x group with 3 updates by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2328
- build(deps): Bump google.golang.org/grpc from 1.72.2 to 1.73.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2329
- build(deps): Bump actions/attest-build-provenance from 2.3.0 to 2.4.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2332
- build(deps): Bump docker/setup-buildx-action from 3.10.0 to 3.11.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2333
- build(deps): Bump docker/setup-buildx-action from 3.11.0 to 3.11.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2335
- build(deps): Bump sigstore/cosign-installer from 3.8.2 to 3.9.1 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2336
- build(deps): Bump github.com/go-viper/mapstructure/v2 from 2.2.1 to 2.3.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2337
- build(deps): Bump github.com/hashicorp/hcl/v2 from 2.23.1-0.20250203194505-ba0759438da2 to 2.24.0 by [@&#8203;dependabot](https://github.com/dependabot)\[bot] in terraform-linters/tflint#2338
- Bump GoReleaser to v2.11.0 by [@&#8203;wata727](https://github.com/wata727) in terraform-linters/tflint#2342

**Full Changelog**: terraform-linters/tflint@v0.58.0...v0.58.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0MC42Mi4xIiwidXBkYXRlZEluVmVyIjoiNDAuNjIuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOlsiUmVub3ZhdGUgQm90Il19-->
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.

TFLint fails with not enough function arguments for nested modules with provider functions
1 participant