Skip to content

Commit d8073a4

Browse files
committed
tfprotov5+tfprotov6: Implement GetMetadata RPC
1 parent 88d4ba1 commit d8073a4

32 files changed

+2764
-1504
lines changed
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"

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,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package fromproto
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
8+
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
9+
)
10+
11+
func ServerCapabilities(in *tfplugin5.ServerCapabilities) *tfprotov5.ServerCapabilities {
12+
if in == nil {
13+
return nil
14+
}
15+
16+
return &tfprotov5.ServerCapabilities{
17+
GetProviderSchemaOptional: in.GetProviderSchemaOptional,
18+
PlanDestroy: in.PlanDestroy,
19+
}
20+
}

0 commit comments

Comments
 (0)