Skip to content

Commit 2f527e3

Browse files
committed
all: Initial provider defined functions implementation
Reference: hashicorp/terraform-plugin-go#351 Reference: https://developer.hashicorp.com/terraform/plugin/framework/migrating The next versions of the plugin protocol (5.5/6.5) include support for provider defined functions. The terraform-plugin-sdk Go module will not be receiving this feature, however this Go module must be updated to handle the new RPCs with errors. Provider developers can still implement provider defined functions in their terraform-plugin-sdk based providers by following the framework migration documentation to introduce terraform-plugin-mux, which then will enable terraform-plugin-framework based provider function implementations.
1 parent b48765e commit 2f527e3

File tree

3 files changed

+41
-9
lines changed

3 files changed

+41
-9
lines changed

go.mod

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ require (
66
github.com/google/go-cmp v0.6.0
77
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
88
github.com/hashicorp/go-hclog v1.5.0
9-
github.com/hashicorp/go-plugin v1.5.2
9+
github.com/hashicorp/go-plugin v1.6.0
1010
github.com/hashicorp/go-uuid v1.0.3
1111
github.com/hashicorp/go-version v1.6.0
1212
github.com/hashicorp/hc-install v0.6.2
1313
github.com/hashicorp/hcl/v2 v2.19.1
1414
github.com/hashicorp/logutils v1.0.0
1515
github.com/hashicorp/terraform-exec v0.19.0
1616
github.com/hashicorp/terraform-json v0.18.0
17-
github.com/hashicorp/terraform-plugin-go v0.19.1
17+
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4
1818
github.com/hashicorp/terraform-plugin-log v0.9.0
1919
github.com/mitchellh/copystructure v1.2.0
2020
github.com/mitchellh/go-testing-interface v1.14.1
@@ -37,7 +37,7 @@ require (
3737
github.com/hashicorp/go-multierror v1.1.1 // indirect
3838
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
3939
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
40-
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect
40+
github.com/hashicorp/yamux v0.1.1 // indirect
4141
github.com/kylelemons/godebug v1.1.0 // indirect
4242
github.com/mattn/go-colorable v0.1.12 // indirect
4343
github.com/mattn/go-isatty v0.0.14 // indirect

go.sum

+6-6
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/hashicorp/go-hclog v1.5.0 h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+
4545
github.com/hashicorp/go-hclog v1.5.0/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
4646
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
4747
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
48-
github.com/hashicorp/go-plugin v1.5.2 h1:aWv8eimFqWlsEiMrYZdPYl+FdHaBJSN4AWwGWfT1G2Y=
49-
github.com/hashicorp/go-plugin v1.5.2/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
48+
github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDmTk8A=
49+
github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI=
5050
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
5151
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
5252
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
@@ -62,16 +62,16 @@ github.com/hashicorp/terraform-exec v0.19.0 h1:FpqZ6n50Tk95mItTSS9BjeOVUb4eg81Sp
6262
github.com/hashicorp/terraform-exec v0.19.0/go.mod h1:tbxUpe3JKruE9Cuf65mycSIT8KiNPZ0FkuTE3H4urQg=
6363
github.com/hashicorp/terraform-json v0.18.0 h1:pCjgJEqqDESv4y0Tzdqfxr/edOIGkjs8keY42xfNBwU=
6464
github.com/hashicorp/terraform-json v0.18.0/go.mod h1:qdeBs11ovMzo5puhrRibdD6d2Dq6TyE/28JiU4tIQxk=
65-
github.com/hashicorp/terraform-plugin-go v0.19.1 h1:lf/jTGTeELcz5IIbn/94mJdmnTjRYm6S6ct/JqCSr50=
66-
github.com/hashicorp/terraform-plugin-go v0.19.1/go.mod h1:5NMIS+DXkfacX6o5HCpswda5yjkSYfKzn1Nfl9l+qRs=
65+
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4 h1:Q3xOtc6IB248qD76gKYD6FEPD0eFYKKr9n18Zh5o5I0=
66+
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4/go.mod h1:dYHQT4x4qtYsGsD0ZmWo0JJz9rIxSv/ETdK8p+1qlhI=
6767
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
6868
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
6969
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
7070
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
7171
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
7272
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
73-
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d h1:kJCB4vdITiW1eC1vq2e6IsrXKrZit1bv/TDYFGMp4BQ=
74-
github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM=
73+
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
74+
github.com/hashicorp/yamux v0.1.1/go.mod h1:CtWFDAQgb7dxtzFs4tWbplKIe2jSi3+5vKbgIO0SLnQ=
7575
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A=
7676
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
7777
github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4=

helper/schema/grpc_provider.go

+32
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ func (s *GRPCProviderServer) GetMetadata(ctx context.Context, req *tfprotov5.Get
8080

8181
resp := &tfprotov5.GetMetadataResponse{
8282
DataSources: make([]tfprotov5.DataSourceMetadata, 0, len(s.provider.DataSourcesMap)),
83+
Functions: make([]tfprotov5.FunctionMetadata, 0),
8384
Resources: make([]tfprotov5.ResourceMetadata, 0, len(s.provider.ResourcesMap)),
8485
ServerCapabilities: s.serverCapabilities(),
8586
}
@@ -106,6 +107,7 @@ func (s *GRPCProviderServer) GetProviderSchema(ctx context.Context, req *tfproto
106107

107108
resp := &tfprotov5.GetProviderSchemaResponse{
108109
DataSourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.DataSourcesMap)),
110+
Functions: make(map[string]*tfprotov5.Function, 0),
109111
ResourceSchemas: make(map[string]*tfprotov5.Schema, len(s.provider.ResourcesMap)),
110112
ServerCapabilities: s.serverCapabilities(),
111113
}
@@ -1271,6 +1273,36 @@ func (s *GRPCProviderServer) ReadDataSource(ctx context.Context, req *tfprotov5.
12711273
return resp, nil
12721274
}
12731275

1276+
func (s *GRPCProviderServer) CallFunction(ctx context.Context, req *tfprotov5.CallFunctionRequest) (*tfprotov5.CallFunctionResponse, error) {
1277+
ctx = logging.InitContext(ctx)
1278+
1279+
logging.HelperSchemaTrace(ctx, "Returning error for provider function call")
1280+
1281+
resp := &tfprotov5.CallFunctionResponse{
1282+
Diagnostics: []*tfprotov5.Diagnostic{
1283+
{
1284+
Severity: tfprotov5.DiagnosticSeverityError,
1285+
Summary: "Function Not Found",
1286+
Detail: fmt.Sprintf("No function named %q was found in the provider.", req.Name),
1287+
},
1288+
},
1289+
}
1290+
1291+
return resp, nil
1292+
}
1293+
1294+
func (s *GRPCProviderServer) GetFunctions(ctx context.Context, req *tfprotov5.GetFunctionsRequest) (*tfprotov5.GetFunctionsResponse, error) {
1295+
ctx = logging.InitContext(ctx)
1296+
1297+
logging.HelperSchemaTrace(ctx, "Getting provider functions")
1298+
1299+
resp := &tfprotov5.GetFunctionsResponse{
1300+
Functions: make(map[string]*tfprotov5.Function, 0),
1301+
}
1302+
1303+
return resp, nil
1304+
}
1305+
12741306
func pathToAttributePath(path cty.Path) *tftypes.AttributePath {
12751307
var steps []tftypes.AttributePathStep
12761308

0 commit comments

Comments
 (0)