rpcproviders: Enough to call provider-defined functions

OpenTofu wants to configure a provider before calling functions on it
during the plan and apply phases, so we need ValidateProviderConfig,
ConfigureProvider, and CallFunction to all work in order to deal with
a configuration that only calls provider-defined functions.

Most of the new functionality here is coming from the upstream library, but
with upstream now implemented it exposed some bugs in the existing code
here which are also fixed at the same time.

Signed-off-by: Martin Atkins <mart@degeneration.co.uk>
This commit is contained in:
Martin Atkins
2025-07-24 13:42:06 -07:00
parent 0ccf731bc4
commit 5ccba528ce
4 changed files with 9 additions and 8 deletions

2
go.mod
View File

@@ -21,7 +21,7 @@ require (
github.com/apparentlymart/go-shquot v0.0.1
github.com/apparentlymart/go-userdirs v0.0.0-20200915174352-b0c018a67c13
github.com/apparentlymart/go-versions v1.0.2
github.com/apparentlymart/opentofu-providers v0.0.0-20250724194801-5f262d220d38
github.com/apparentlymart/opentofu-providers v0.0.0-20250724234429-1ac1eb53eced
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2
github.com/aws/aws-sdk-go-v2 v1.36.0
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.27

6
go.sum
View File

@@ -311,8 +311,10 @@ github.com/apparentlymart/go-userdirs v0.0.0-20200915174352-b0c018a67c13 h1:Jtue
github.com/apparentlymart/go-userdirs v0.0.0-20200915174352-b0c018a67c13/go.mod h1:7kfpUbyCdGJ9fDRCp3fopPQi5+cKNHgTE4ZuNrO71Cw=
github.com/apparentlymart/go-versions v1.0.2 h1:n5Gg9YvSLK8Zzpy743J7abh2jt7z7ammOQ0oTd/5oA4=
github.com/apparentlymart/go-versions v1.0.2/go.mod h1:YF5j7IQtrOAOnsGkniupEA5bfCjzd7i14yu0shZavyM=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724194801-5f262d220d38 h1:eGpfa8TkI3CWDFDFzU8S6VDwiCaFiCdGj5RbSv0pZGU=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724194801-5f262d220d38/go.mod h1:AXZ5WfhMTJ83qdvrDv7I/+zZk0roD7jpOdPG6wFgYsM=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724204017-f9b33adc59b7 h1:SPsqQp6emj5uO7xp+u9SlFTOsOMxXUd0VGgHCevSVXA=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724204017-f9b33adc59b7/go.mod h1:AXZ5WfhMTJ83qdvrDv7I/+zZk0roD7jpOdPG6wFgYsM=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724234429-1ac1eb53eced h1:Scb+W3LAQ7ZFCTv4hV7Jpvpt6CHZXBZNPXKEKb7IX9M=
github.com/apparentlymart/opentofu-providers v0.0.0-20250724234429-1ac1eb53eced/go.mod h1:AXZ5WfhMTJ83qdvrDv7I/+zZk0roD7jpOdPG6wFgYsM=
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2 h1:7Ip0wMmLHLRJdrloDxZfhMm0xrLXZS8+COSu2bXmEQs=
github.com/armon/circbuf v0.0.0-20190214190532-5111143e8da2/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=

View File

@@ -51,13 +51,13 @@ func (r rpcProvider) CallFunction(ctx context.Context, req providers.CallFunctio
}
}
if !spec.VariadicParameter.AllowUnknownValues {
if !param.AllowUnknownValues {
if !arg.IsWhollyKnown() {
resp.Result = cty.UnknownVal(spec.Return)
return resp
}
}
if !spec.VariadicParameter.AllowNullValue {
if !param.AllowNullValue {
if arg.IsNull() {
resp.Error = function.NewArgErrorf(i, "must not be null")
return resp

View File

@@ -109,9 +109,8 @@ func (r rpcProvider) ValidateProviderConfig(ctx context.Context, req providers.V
return resp
}
clientResp, err := r.client.ConfigureProvider(ctx, &providerops.ConfigureProviderRequest{
Config: providerschema.NewDynamicValue(req.Config, schema.Block.ImpliedType()),
ClientCapabilities: clientCapabilities,
clientResp, err := r.client.ValidateProviderConfig(ctx, &providerops.ValidateProviderConfigRequest{
Config: providerschema.NewDynamicValue(req.Config, schema.Block.ImpliedType()),
})
resp.Diagnostics = appendDiags(resp.Diagnostics, clientResp, err)
return resp