Skip to content

Commit 24e6961

Browse files
authored
tfprotov5+tfprotov6: Update to protocol versions 5.4/6.4 with GetMetadata 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.
1 parent 94c7a39 commit 24e6961

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3101
-1490
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: ENHANCEMENTS
2+
body: 'tfprotov5: Added `ServerCapabilities` type `GetProviderSchemaOptional` field,
3+
which when enabled can signal that the provider supports RPC operations without
4+
the `GetProviderSchema` RPC being called first'
5+
time: 2023-07-07T10:02:31.242394-04:00
6+
custom:
7+
Issue: "310"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: ENHANCEMENTS
2+
body: 'tfprotov6: Added `ServerCapabilities` type `GetProviderSchemaOptional` field,
3+
which when enabled can signal that the provider supports RPC operations without
4+
the `GetProviderSchema` RPC being called first'
5+
time: 2023-07-07T10:03:39.802189-04:00
6+
custom:
7+
Issue: "310"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'tfprotov5: Upgraded protocol to 5.4 and implemented `GetMetadata` RPC'
3+
time: 2023-08-24T15:22:00.773731-04:00
4+
custom:
5+
Issue: "310"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: FEATURES
2+
body: 'tfprotov6: Upgraded protocol to 6.4 and implemented `GetMetadata` RPC'
3+
time: 2023-08-24T15:22:20.285837-04:00
4+
custom:
5+
Issue: "310"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
kind: NOTES
2+
body: 'all: If using terraform-plugin-framework, terraform-plugin-mux, or terraform-plugin-sdk,
3+
only upgrade this Go module when upgrading those Go modules or you may receive
4+
a `missing GetMetadata method` error when compiling'
5+
time: 2023-08-24T15:39:56.697018-04:00
6+
custom:
7+
Issue: "310"

internal/logging/keys.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ const (
5353

5454
// The protocol version being used, as a string, such as "6"
5555
KeyProtocolVersion = "tf_proto_version"
56+
57+
// Whether the GetProviderSchemaOptional server capability is enabled
58+
KeyServerCapabilityGetProviderSchemaOptional = "tf_server_capability_get_provider_schema_optional"
59+
60+
// Whether the PlanDestroy server capability is enabled
61+
KeyServerCapabilityPlanDestroy = "tf_server_capability_plan_destroy"
5662
)

tfprotov5/data_source.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ import (
77
"context"
88
)
99

10+
// DataSourceMetadata describes metadata for a data resource in the GetMetadata
11+
// RPC.
12+
type DataSourceMetadata struct {
13+
// TypeName is the name of the data resource.
14+
TypeName string
15+
}
16+
1017
// DataSourceServer is an interface containing the methods a data source
1118
// implementation needs to fill.
1219
type DataSourceServer interface {

tfprotov5/internal/fromproto/data_source.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ import (
88
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
99
)
1010

11+
func DataSourceMetadata(in *tfplugin5.GetMetadata_DataSourceMetadata) *tfprotov5.DataSourceMetadata {
12+
if in == nil {
13+
return nil
14+
}
15+
16+
return &tfprotov5.DataSourceMetadata{
17+
TypeName: in.TypeName,
18+
}
19+
}
20+
1121
func ValidateDataSourceConfigRequest(in *tfplugin5.ValidateDataSourceConfig_Request) (*tfprotov5.ValidateDataSourceConfigRequest, error) {
1222
resp := &tfprotov5.ValidateDataSourceConfigRequest{
1323
TypeName: in.TypeName,

tfprotov5/internal/fromproto/provider.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,40 @@ import (
88
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
99
)
1010

11+
func GetMetadataRequest(in *tfplugin5.GetMetadata_Request) (*tfprotov5.GetMetadataRequest, error) {
12+
return &tfprotov5.GetMetadataRequest{}, nil
13+
}
14+
15+
func GetMetadataResponse(in *tfplugin5.GetMetadata_Response) (*tfprotov5.GetMetadataResponse, error) {
16+
if in == nil {
17+
return nil, nil
18+
}
19+
20+
resp := &tfprotov5.GetMetadataResponse{
21+
DataSources: make([]tfprotov5.DataSourceMetadata, 0, len(in.DataSources)),
22+
Resources: make([]tfprotov5.ResourceMetadata, 0, len(in.Resources)),
23+
ServerCapabilities: ServerCapabilities(in.ServerCapabilities),
24+
}
25+
26+
for _, datasource := range in.DataSources {
27+
resp.DataSources = append(resp.DataSources, *DataSourceMetadata(datasource))
28+
}
29+
30+
for _, resource := range in.Resources {
31+
resp.Resources = append(resp.Resources, *ResourceMetadata(resource))
32+
}
33+
34+
diags, err := Diagnostics(in.Diagnostics)
35+
36+
if err != nil {
37+
return resp, err
38+
}
39+
40+
resp.Diagnostics = diags
41+
42+
return resp, nil
43+
}
44+
1145
func GetProviderSchemaRequest(in *tfplugin5.GetProviderSchema_Request) (*tfprotov5.GetProviderSchemaRequest, error) {
1246
return &tfprotov5.GetProviderSchemaRequest{}, nil
1347
}

tfprotov5/internal/fromproto/resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ import (
1010
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
1111
)
1212

13+
func ResourceMetadata(in *tfplugin5.GetMetadata_ResourceMetadata) *tfprotov5.ResourceMetadata {
14+
if in == nil {
15+
return nil
16+
}
17+
18+
return &tfprotov5.ResourceMetadata{
19+
TypeName: in.TypeName,
20+
}
21+
}
22+
1323
func ValidateResourceTypeConfigRequest(in *tfplugin5.ValidateResourceTypeConfig_Request) (*tfprotov5.ValidateResourceTypeConfigRequest, error) {
1424
resp := &tfprotov5.ValidateResourceTypeConfigRequest{
1525
TypeName: in.TypeName,

0 commit comments

Comments
 (0)