Skip to content

Commit

Permalink
deps: Update terraform-plugin-go@fb1d856be38c4fccc56fb61bcf6559aefb3a…
Browse files Browse the repository at this point in the history
…1460
  • Loading branch information
bflad committed Dec 12, 2023
1 parent 209df98 commit 1eeb326
Show file tree
Hide file tree
Showing 16 changed files with 327 additions and 33 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
github.com/google/go-cmp v0.6.0
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231212192300-fb1d856be38c
github.com/hashicorp/terraform-plugin-log v0.9.0
google.golang.org/grpc v1.59.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ github.com/hashicorp/go-plugin v1.6.0 h1:wgd4KxHJTVGGqWBq4QPB1i5BZNEx9BR8+OFmHDm
github.com/hashicorp/go-plugin v1.6.0/go.mod h1:lBS5MtSSBZk0SHc66KACcjjlU6WzEVP/8pwz68aMkCI=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4 h1:Q3xOtc6IB248qD76gKYD6FEPD0eFYKKr9n18Zh5o5I0=
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231211173412-2017fc8cadb4/go.mod h1:dYHQT4x4qtYsGsD0ZmWo0JJz9rIxSv/ETdK8p+1qlhI=
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231212192300-fb1d856be38c h1:+/OS6VVVQZ3mdF1H2KbMYxKp329S61MDbNLQs4L1eCg=
github.com/hashicorp/terraform-plugin-go v0.19.2-0.20231212192300-fb1d856be38c/go.mod h1:dYHQT4x4qtYsGsD0ZmWo0JJz9rIxSv/ETdK8p+1qlhI=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
Expand Down
23 changes: 22 additions & 1 deletion tf5muxserver/mux_server_CallFunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,28 @@ func (s *muxServer) CallFunction(ctx context.Context, req *tfprotov5.CallFunctio
}

ctx = logging.Tfprotov5ProviderServerContext(ctx, server)

// Remove and call server.CallFunction below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := server.(tfprotov5.FunctionServer)

if !ok {
resp := &tfprotov5.CallFunctionResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Provider Functions Not Implemented",
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
"Either upgrade the provider to a version that implements provider-defined functions or this is a bug in Terraform that should be reported to the Terraform maintainers.",
},
},
}

return resp, nil
}

logging.MuxTrace(ctx, "calling downstream server")

return server.CallFunction(ctx, req)
// return server.CallFunction(ctx, req)
return functionServer.CallFunction(ctx, req)
}
13 changes: 11 additions & 2 deletions tf5muxserver/mux_server_CallFunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ func TestMuxServerCallFunction(t *testing.T) {
t.Fatalf("unexpected error setting up factory: %s", err)
}

_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
_, err = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function1",
})

Expand All @@ -55,7 +63,8 @@ func TestMuxServerCallFunction(t *testing.T) {
t.Errorf("unexpected test_function1 CallFunction called on server2")
}

_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
_, err = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function2",
})

Expand Down
12 changes: 11 additions & 1 deletion tf5muxserver/mux_server_GetFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ func (s *muxServer) GetFunctions(ctx context.Context, req *tfprotov5.GetFunction

for _, server := range s.servers {
ctx := logging.Tfprotov5ProviderServerContext(ctx, server)

// Remove and call server.GetFunctions below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := server.(tfprotov5.FunctionServer)

if !ok {
continue
}

logging.MuxTrace(ctx, "calling downstream server")

serverResp, err := server.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})
// serverResp, err := server.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})
serverResp, err := functionServer.GetFunctions(ctx, &tfprotov5.GetFunctionsRequest{})

if err != nil {
return resp, fmt.Errorf("error calling GetFunctions for %T: %w", server, err)
Expand Down
10 changes: 9 additions & 1 deletion tf5muxserver/mux_server_GetFunctions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,15 @@ func TestMuxServerGetFunctions(t *testing.T) {
t.Fatalf("unexpected error: %s", err)
}

resp, err := muxServer.ProviderServer().GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// resp, err := muxServer.ProviderServer().GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})
resp, err := functionServer.GetFunctions(context.Background(), &tfprotov5.GetFunctionsRequest{})

if err != nil {
t.Fatalf("unexpected error: %s", err)
Expand Down
60 changes: 54 additions & 6 deletions tf5muxserver/mux_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,15 @@ func TestMuxServerGetFunctionServer_GetProviderSchema(t *testing.T) {
terraformOp := func() {
defer wg.Done()

_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function1",
})
}
Expand Down Expand Up @@ -498,7 +506,15 @@ func TestMuxServerGetFunctionServer_GetProviderSchema_Duplicate(t *testing.T) {
terraformOp := func() {
defer wg.Done()

resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function",
})

Expand Down Expand Up @@ -562,7 +578,15 @@ func TestMuxServerGetFunctionServer_GetMetadata(t *testing.T) {
terraformOp := func() {
defer wg.Done()

_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function1",
})
}
Expand Down Expand Up @@ -629,7 +653,15 @@ func TestMuxServerGetFunctionServer_GetMetadata_Duplicate(t *testing.T) {
terraformOp := func() {
defer wg.Done()

resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function",
})

Expand Down Expand Up @@ -691,7 +723,15 @@ func TestMuxServerGetFunctionServer_GetMetadata_Partial(t *testing.T) {
terraformOp := func() {
defer wg.Done()

_, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// _, _ = muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
_, _ = functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function1",
})
}
Expand Down Expand Up @@ -757,7 +797,15 @@ func TestMuxServerGetFunctionServer_Missing(t *testing.T) {
terraformOp := func() {
defer wg.Done()

resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov5.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov5.FunctionServer")
}

// resp, _ := muxServer.ProviderServer().CallFunction(ctx, &tfprotov5.CallFunctionRequest{
resp, _ := functionServer.CallFunction(ctx, &tfprotov5.CallFunctionRequest{
Name: "test_function_nonexistent",
})

Expand Down
39 changes: 37 additions & 2 deletions tf5to6server/tf5to6server.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,29 @@ func (s v5tov6Server) ApplyResourceChange(ctx context.Context, req *tfprotov6.Ap
}

func (s v5tov6Server) CallFunction(ctx context.Context, req *tfprotov6.CallFunctionRequest) (*tfprotov6.CallFunctionResponse, error) {
// Remove and call s.v5Server.CallFunction below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := s.v5Server.(tfprotov5.FunctionServer)

if !ok {
v6Resp := &tfprotov6.CallFunctionResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Provider Functions Not Implemented",
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
"Either upgrade the provider to a version that implements provider-defined functions or this is a bug in Terraform that should be reported to the Terraform maintainers.",
},
},
}

return v6Resp, nil
}

v5Req := tfprotov6tov5.CallFunctionRequest(req)
v5Resp, err := s.v5Server.CallFunction(ctx, v5Req)
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
// v5Resp, err := s.v5Server.CallFunction(ctx, v5Req)
v5Resp, err := functionServer.CallFunction(ctx, v5Req)

if err != nil {
return nil, err
Expand All @@ -66,8 +87,22 @@ func (s v5tov6Server) ConfigureProvider(ctx context.Context, req *tfprotov6.Conf
}

func (s v5tov6Server) GetFunctions(ctx context.Context, req *tfprotov6.GetFunctionsRequest) (*tfprotov6.GetFunctionsResponse, error) {
// Remove and call s.v5Server.GetFunctions below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := s.v5Server.(tfprotov5.FunctionServer)

if !ok {
v6Resp := &tfprotov6.GetFunctionsResponse{
Functions: map[string]*tfprotov6.Function{},
}

return v6Resp, nil
}

v5Req := tfprotov6tov5.GetFunctionsRequest(req)
v5Resp, err := s.v5Server.GetFunctions(ctx, v5Req)
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
// v5Resp, err := s.v5Server.GetFunctions(ctx, v5Req)
v5Resp, err := functionServer.GetFunctions(ctx, v5Req)

if err != nil {
return nil, err
Expand Down
20 changes: 18 additions & 2 deletions tf5to6server/tf5to6server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,15 @@ func TestV6ToV5ServerCallFunction(t *testing.T) {
t.Fatalf("unexpected error upgrading server: %s", err)
}

_, err = v6server.CallFunction(ctx, &tfprotov6.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := v6server.(tfprotov6.FunctionServer)

if !ok {
t.Fatal("v6server should implement tfprotov6.FunctionServer")
}

//_, err = v6server.CallFunction(ctx, &tfprotov6.CallFunctionRequest{
_, err = functionServer.CallFunction(ctx, &tfprotov6.CallFunctionRequest{
Name: "test_function",
})

Expand Down Expand Up @@ -238,7 +246,15 @@ func TestV6ToV5ServerGetFunctions(t *testing.T) {
t.Fatalf("unexpected error upgrading server: %s", err)
}

_, err = v6server.GetFunctions(ctx, &tfprotov6.GetFunctionsRequest{})
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := v6server.(tfprotov6.FunctionServer)

if !ok {
t.Fatal("v6server should implement tfprotov6.FunctionServer")
}

//_, err = v6server.GetFunction(ctx, &tfprotov6.GetFunctionRequest{})
_, err = functionServer.GetFunctions(ctx, &tfprotov6.GetFunctionsRequest{})

if err != nil {
t.Fatalf("unexpected error: %s", err)
Expand Down
23 changes: 22 additions & 1 deletion tf6muxserver/mux_server_CallFunction.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,28 @@ func (s *muxServer) CallFunction(ctx context.Context, req *tfprotov6.CallFunctio
}

ctx = logging.Tfprotov6ProviderServerContext(ctx, server)

// Remove and call server.CallFunction below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := server.(tfprotov6.FunctionServer)

if !ok {
resp := &tfprotov6.CallFunctionResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Provider Functions Not Implemented",
Detail: "A provider-defined function call was received by the provider, however the provider does not implement functions. " +
"Either upgrade the provider to a version that implements provider-defined functions or this is a bug in Terraform that should be reported to the Terraform maintainers.",
},
},
}

return resp, nil
}

logging.MuxTrace(ctx, "calling downstream server")

return server.CallFunction(ctx, req)
// return server.CallFunction(ctx, req)
return functionServer.CallFunction(ctx, req)
}
13 changes: 11 additions & 2 deletions tf6muxserver/mux_server_CallFunction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ func TestMuxServerCallFunction(t *testing.T) {
t.Fatalf("unexpected error setting up factory: %s", err)
}

_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov6.CallFunctionRequest{
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := muxServer.ProviderServer().(tfprotov6.FunctionServer)

if !ok {
t.Fatal("muxServer should implement tfprotov6.FunctionServer")
}

// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov6.CallFunctionRequest{
_, err = functionServer.CallFunction(ctx, &tfprotov6.CallFunctionRequest{
Name: "test_function1",
})

Expand All @@ -55,7 +63,8 @@ func TestMuxServerCallFunction(t *testing.T) {
t.Errorf("unexpected test_function1 CallFunction called on server2")
}

_, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov6.CallFunctionRequest{
// _, err = muxServer.ProviderServer().CallFunction(ctx, &tfprotov6.CallFunctionRequest{
_, err = functionServer.CallFunction(ctx, &tfprotov6.CallFunctionRequest{
Name: "test_function2",
})

Expand Down
12 changes: 11 additions & 1 deletion tf6muxserver/mux_server_GetFunctions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ func (s *muxServer) GetFunctions(ctx context.Context, req *tfprotov6.GetFunction

for _, server := range s.servers {
ctx := logging.Tfprotov6ProviderServerContext(ctx, server)

// Remove and call server.GetFunctions below directly.
// Reference: https://github.com/hashicorp/terraform-plugin-mux/issues/210
functionServer, ok := server.(tfprotov6.FunctionServer)

if !ok {
continue
}

logging.MuxTrace(ctx, "calling downstream server")

serverResp, err := server.GetFunctions(ctx, &tfprotov6.GetFunctionsRequest{})
// serverResp, err := server.GetFunctions(ctx, &tfprotov6.GetFunctionsRequest{})
serverResp, err := functionServer.GetFunctions(ctx, &tfprotov6.GetFunctionsRequest{})

if err != nil {
return resp, fmt.Errorf("error calling GetFunctions for %T: %w", server, err)
Expand Down
Loading

0 comments on commit 1eeb326

Please sign in to comment.