-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tfprotov5+tfprotov6: Update to protocol versions 5.4/6.4 with GetMeta…
…data RPC and GetProviderSchemaOptional server capability (#311) Reference: #310 Protocol upgrades that impose new RPCs will either require: - The `tfprotov5.ProviderServer`/`tfprotov6.ProviderServer` interface to require a new method - Or, new "optional" interfaces be implemented (let's make up `ProviderServerWithGetMetadata` in this case) terraform-plugin-go is a low level abstraction which is designed to _directly implement_ the protocol rather than introduce its own abstractions. Most provider developers will directly interface with higher level Go modules, such as terraform-plugin-sdk and terraform-plugin-framework. Except for advanced provider development using this Go module directly, this type of low level "breaking" change will be hidden by also upgrading those Go modules at the same time: - hashicorp/terraform-plugin-sdk#1235 - hashicorp/terraform-plugin-framework#829 - hashicorp/terraform-plugin-mux#186 Therefore the change is implemented on the existing interface.
- Loading branch information
Showing
42 changed files
with
3,101 additions
and
1,490 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: ENHANCEMENTS | ||
body: 'tfprotov5: Added `ServerCapabilities` type `GetProviderSchemaOptional` field, | ||
which when enabled can signal that the provider supports RPC operations without | ||
the `GetProviderSchema` RPC being called first' | ||
time: 2023-07-07T10:02:31.242394-04:00 | ||
custom: | ||
Issue: "310" |
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: ENHANCEMENTS | ||
body: 'tfprotov6: Added `ServerCapabilities` type `GetProviderSchemaOptional` field, | ||
which when enabled can signal that the provider supports RPC operations without | ||
the `GetProviderSchema` RPC being called first' | ||
time: 2023-07-07T10:03:39.802189-04:00 | ||
custom: | ||
Issue: "310" |
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,5 @@ | ||
kind: FEATURES | ||
body: 'tfprotov5: Upgraded protocol to 5.4 and implemented `GetMetadata` RPC' | ||
time: 2023-08-24T15:22:00.773731-04:00 | ||
custom: | ||
Issue: "310" |
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,5 @@ | ||
kind: FEATURES | ||
body: 'tfprotov6: Upgraded protocol to 6.4 and implemented `GetMetadata` RPC' | ||
time: 2023-08-24T15:22:20.285837-04:00 | ||
custom: | ||
Issue: "310" |
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: NOTES | ||
body: 'all: If using terraform-plugin-framework, terraform-plugin-mux, or terraform-plugin-sdk, | ||
only upgrade this Go module when upgrading those Go modules or you may receive | ||
a `missing GetMetadata method` error when compiling' | ||
time: 2023-08-24T15:39:56.697018-04:00 | ||
custom: | ||
Issue: "310" |
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
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,20 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package fromproto | ||
|
||
import ( | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" | ||
) | ||
|
||
func ServerCapabilities(in *tfplugin5.ServerCapabilities) *tfprotov5.ServerCapabilities { | ||
if in == nil { | ||
return nil | ||
} | ||
|
||
return &tfprotov5.ServerCapabilities{ | ||
GetProviderSchemaOptional: in.GetProviderSchemaOptional, | ||
PlanDestroy: in.PlanDestroy, | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
tfprotov5/internal/tf5serverlogging/server_capabilities.go
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,26 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tf5serverlogging | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/internal/logging" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
) | ||
|
||
// ServerCapabilities generates a TRACE "Announced server capabilities" log. | ||
func ServerCapabilities(ctx context.Context, capabilities *tfprotov5.ServerCapabilities) { | ||
responseFields := map[string]interface{}{ | ||
logging.KeyServerCapabilityGetProviderSchemaOptional: false, | ||
logging.KeyServerCapabilityPlanDestroy: false, | ||
} | ||
|
||
if capabilities != nil { | ||
responseFields[logging.KeyServerCapabilityGetProviderSchemaOptional] = capabilities.GetProviderSchemaOptional | ||
responseFields[logging.KeyServerCapabilityPlanDestroy] = capabilities.PlanDestroy | ||
} | ||
|
||
logging.ProtocolTrace(ctx, "Announced server capabilities", responseFields) | ||
} |
104 changes: 104 additions & 0 deletions
104
tfprotov5/internal/tf5serverlogging/server_capabilities_test.go
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,104 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package tf5serverlogging_test | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
"github.com/hashicorp/terraform-plugin-go/internal/logging" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tf5serverlogging" | ||
"github.com/hashicorp/terraform-plugin-log/tfsdklog" | ||
"github.com/hashicorp/terraform-plugin-log/tfsdklogtest" | ||
) | ||
|
||
func TestServerCapabilities(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := map[string]struct { | ||
capabilities *tfprotov5.ServerCapabilities | ||
expected []map[string]interface{} | ||
}{ | ||
"nil": { | ||
capabilities: nil, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"@level": "trace", | ||
"@message": "Announced server capabilities", | ||
"@module": "sdk.proto", | ||
"tf_server_capability_get_provider_schema_optional": false, | ||
"tf_server_capability_plan_destroy": false, | ||
}, | ||
}, | ||
}, | ||
"empty": { | ||
capabilities: &tfprotov5.ServerCapabilities{}, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"@level": "trace", | ||
"@message": "Announced server capabilities", | ||
"@module": "sdk.proto", | ||
"tf_server_capability_get_provider_schema_optional": false, | ||
"tf_server_capability_plan_destroy": false, | ||
}, | ||
}, | ||
}, | ||
"get_provider_schema_optional": { | ||
capabilities: &tfprotov5.ServerCapabilities{ | ||
GetProviderSchemaOptional: true, | ||
}, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"@level": "trace", | ||
"@message": "Announced server capabilities", | ||
"@module": "sdk.proto", | ||
"tf_server_capability_get_provider_schema_optional": true, | ||
"tf_server_capability_plan_destroy": false, | ||
}, | ||
}, | ||
}, | ||
"plan_destroy": { | ||
capabilities: &tfprotov5.ServerCapabilities{ | ||
PlanDestroy: true, | ||
}, | ||
expected: []map[string]interface{}{ | ||
{ | ||
"@level": "trace", | ||
"@message": "Announced server capabilities", | ||
"@module": "sdk.proto", | ||
"tf_server_capability_get_provider_schema_optional": false, | ||
"tf_server_capability_plan_destroy": true, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
for name, testCase := range testCases { | ||
name, testCase := name, testCase | ||
|
||
t.Run(name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
var output bytes.Buffer | ||
|
||
ctx := tfsdklogtest.RootLogger(context.Background(), &output) | ||
ctx = logging.ProtoSubsystemContext(ctx, tfsdklog.Options{}) | ||
|
||
tf5serverlogging.ServerCapabilities(ctx, testCase.capabilities) | ||
|
||
entries, err := tfsdklogtest.MultilineJSONDecode(&output) | ||
|
||
if err != nil { | ||
t.Fatalf("unable to read multiple line JSON: %s", err) | ||
} | ||
|
||
if diff := cmp.Diff(entries, testCase.expected); diff != "" { | ||
t.Errorf("unexpected difference: %s", diff) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.