Skip to content

Commit 09b68f4

Browse files
authored
Partially unknown provider functions arguments fixed (opentofu#2127) (opentofu#2133) (opentofu#2134)
Signed-off-by: Christian Mesh <[email protected]>
1 parent 93d0beb commit 09b68f4

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1-
## 1.7.5 (unreleased)
1+
## 1.7.6 (unreleased)
2+
3+
## 1.7.5
4+
5+
BUG FIXES:
6+
* Provider functions will now handle partially unknown arguments per the tfplugin spec ([#2127](https://github.com/opentofu/opentofu/pull/2127))
27

38
## 1.7.4
49

510
ENHANCEMENTS:
611
* Made `tofu plan` with `generate-config-out` flag replace JSON strings with `jsonencode` functions calls. ([#1595](https://github.com/opentofu/opentofu/pull/1595))
712

813
BUG FIXES:
9-
1014
* `tofu init` will no longer return a supurious "Backend configuration changed" error when re-initializing a working directory with identical settings, backend configuration contains references to variables or local values, and when the `-backend-config` command line option is used. That combination previously caused OpenTofu to incorrectly treat the backend configuration as invalid. ([#2055](https://github.com/opentofu/opentofu/pull/2055))
1115
* configuration generation should no longer fail when generating sensitive properties
1216
* Provider defined functions are now supported better in child modules

internal/plugin/grpc_provider.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,9 +766,22 @@ func (p *GRPCProvider) CallFunction(r providers.CallFunctionRequest) (resp provi
766766
} else {
767767
// This should be unreachable
768768
resp.Error = fmt.Errorf("invalid CallFunctionRequest: too many arguments passed to non-variadic function %s", r.Name)
769+
return resp
769770
}
770771
}
771772

773+
if !paramSpec.AllowUnknownValues && !arg.IsWhollyKnown() {
774+
// Unlike the standard in cty, AllowUnknownValues == false does not just apply to
775+
// the root of the value (IsKnown) and instead also applies to values inside collections
776+
// and structures (IsWhollyKnown).
777+
// This is documented in the tfplugin proto file comments.
778+
//
779+
// The standard cty logic can be found in:
780+
// https://github.com/zclconf/go-cty/blob/ea922e7a95ba2be57897697117f318670e066d22/cty/function/function.go#L288-L290
781+
resp.Result = cty.UnknownVal(spec.Return)
782+
return resp
783+
}
784+
772785
if arg.IsNull() {
773786
if paramSpec.AllowNullValue {
774787
continue

internal/plugin6/grpc_provider.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,9 +755,22 @@ func (p *GRPCProvider) CallFunction(r providers.CallFunctionRequest) (resp provi
755755
} else {
756756
// This should be unreachable
757757
resp.Error = fmt.Errorf("invalid CallFunctionRequest: too many arguments passed to non-variadic function %s", r.Name)
758+
return resp
758759
}
759760
}
760761

762+
if !paramSpec.AllowUnknownValues && !arg.IsWhollyKnown() {
763+
// Unlike the standard in cty, AllowUnknownValues == false does not just apply to
764+
// the root of the value (IsKnown) and instead also applies to values inside collections
765+
// and structures (IsWhollyKnown).
766+
// This is documented in the tfplugin proto file comments.
767+
//
768+
// The standard cty logic can be found in:
769+
// https://github.com/zclconf/go-cty/blob/ea922e7a95ba2be57897697117f318670e066d22/cty/function/function.go#L288-L290
770+
resp.Result = cty.UnknownVal(spec.Return)
771+
return resp
772+
}
773+
761774
if arg.IsNull() {
762775
if paramSpec.AllowNullValue {
763776
continue

internal/providers/provider.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ type FunctionParameterSpec struct {
170170
// Null values alowed for the parameter
171171
AllowNullValue bool
172172
// Unknown Values allowed for the parameter
173-
// Implies the Return type of the function is also Unknown
173+
// Individual provider implementations may interpret this as a
174+
// check using IsWhollyKnown instead cty's default of IsKnown.
175+
// If the input is not wholly known, the result should be
176+
// cty.UnknownVal(spec.returnType)
174177
AllowUnknownValues bool
175178
// Human-readable documentation for the parameter
176179
Description string

0 commit comments

Comments
 (0)