-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
providerserver: Update to protocol versions 5.4/6.4 and enable `GetPr…
- Loading branch information
Showing
35 changed files
with
1,978 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
kind: FEATURES | ||
body: 'providerserver: Upgrade to protocol versions 5.4 and 6.4, which can | ||
significantly reduce memory usage with Terraform 1.6 and later when a | ||
configuration includes multiple instances of the same provider' | ||
time: 2023-08-25T11:58:48.820178-04:00 | ||
custom: | ||
Issue: "828" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto5 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
) | ||
|
||
// GetMetadataRequest returns the *fwserver.GetMetadataRequest | ||
// equivalent of a *tfprotov5.GetMetadataRequest. | ||
func GetMetadataRequest(ctx context.Context, proto5 *tfprotov5.GetMetadataRequest) *fwserver.GetMetadataRequest { | ||
if proto5 == nil { | ||
return nil | ||
} | ||
|
||
fw := &fwserver.GetMetadataRequest{} | ||
|
||
return fw | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto5_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5" | ||
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
) | ||
|
||
func TestGetMetadataRequest(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
input *tfprotov5.GetMetadataRequest | ||
expected *fwserver.GetMetadataRequest | ||
}{ | ||
"nil": { | ||
input: nil, | ||
expected: nil, | ||
}, | ||
"empty": { | ||
input: &tfprotov5.GetMetadataRequest{}, | ||
expected: &fwserver.GetMetadataRequest{}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got := fromproto5.GetMetadataRequest(context.Background(), testCase.input) | ||
|
||
if diff := cmp.Diff(got, testCase.expected); diff != "" { | ||
t.Errorf("unexpected difference: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto6 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
// GetMetadataRequest returns the *fwserver.GetMetadataRequest | ||
// equivalent of a *tfprotov6.GetMetadataRequest. | ||
func GetMetadataRequest(ctx context.Context, proto6 *tfprotov6.GetMetadataRequest) *fwserver.GetMetadataRequest { | ||
if proto6 == nil { | ||
return nil | ||
} | ||
|
||
fw := &fwserver.GetMetadataRequest{} | ||
|
||
return fw | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto6_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto6" | ||
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
) | ||
|
||
func TestGetMetadataRequest(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
input *tfprotov6.GetMetadataRequest | ||
expected *fwserver.GetMetadataRequest | ||
}{ | ||
"nil": { | ||
input: nil, | ||
expected: nil, | ||
}, | ||
"empty": { | ||
input: &tfprotov6.GetMetadataRequest{}, | ||
expected: &fwserver.GetMetadataRequest{}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
got := fromproto6.GetMetadataRequest(context.Background(), testCase.input) | ||
|
||
if diff := cmp.Diff(got, testCase.expected); diff != "" { | ||
t.Errorf("unexpected difference: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fwserver | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-framework/diag" | ||
"github.com/hashicorp/terraform-plugin-framework/internal/logging" | ||
"github.com/hashicorp/terraform-plugin-framework/provider" | ||
) | ||
|
||
// GetMetadataRequest is the framework server request for the | ||
// GetMetadata RPC. | ||
type GetMetadataRequest struct{} | ||
|
||
// GetMetadataResponse is the framework server response for the | ||
// GetMetadata RPC. | ||
type GetMetadataResponse struct { | ||
DataSources []DataSourceMetadata | ||
Diagnostics diag.Diagnostics | ||
Resources []ResourceMetadata | ||
ServerCapabilities *ServerCapabilities | ||
} | ||
|
||
// DataSourceMetadata is the framework server equivalent of the | ||
// tfprotov5.DataSourceMetadata and tfprotov6.DataSourceMetadata types. | ||
type DataSourceMetadata struct { | ||
// TypeName is the name of the data resource. | ||
TypeName string | ||
} | ||
|
||
// ResourceMetadata is the framework server equivalent of the | ||
// tfprotov5.ResourceMetadata and tfprotov6.ResourceMetadata types. | ||
type ResourceMetadata struct { | ||
// TypeName is the name of the managed resource. | ||
TypeName string | ||
} | ||
|
||
// GetMetadata implements the framework server GetMetadata RPC. | ||
func (s *Server) GetMetadata(ctx context.Context, req *GetMetadataRequest, resp *GetMetadataResponse) { | ||
resp.DataSources = []DataSourceMetadata{} | ||
resp.Resources = []ResourceMetadata{} | ||
resp.ServerCapabilities = s.ServerCapabilities() | ||
|
||
metadataReq := provider.MetadataRequest{} | ||
metadataResp := provider.MetadataResponse{} | ||
|
||
logging.FrameworkTrace(ctx, "Calling provider defined Provider Metadata") | ||
s.Provider.Metadata(ctx, metadataReq, &metadataResp) | ||
logging.FrameworkTrace(ctx, "Called provider defined Provider Metadata") | ||
|
||
s.providerTypeName = metadataResp.TypeName | ||
|
||
datasourceMetadatas, diags := s.DataSourceMetadatas(ctx) | ||
|
||
resp.Diagnostics.Append(diags...) | ||
|
||
resourceMetadatas, diags := s.ResourceMetadatas(ctx) | ||
|
||
resp.Diagnostics.Append(diags...) | ||
|
||
if resp.Diagnostics.HasError() { | ||
return | ||
} | ||
|
||
resp.DataSources = datasourceMetadatas | ||
resp.Resources = resourceMetadatas | ||
} |
Oops, something went wrong.