Skip to content

Commit a494582

Browse files
authored
tfprotov5+tfprotov6: Support for Protocol Version 5.3 and 6.3 (#205)
Reference: #204
1 parent 2d80909 commit a494582

File tree

15 files changed

+1278
-995
lines changed

15 files changed

+1278
-995
lines changed

.changelog/205.txt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
```release-note:feature
2+
Added support for protocol version 5.3 and 6.3, which allows providers to opt into the `PlanResourceChange` RPC for resource destruction
3+
```
4+
5+
```release-note:enhancement
6+
tfprotov5: Added `ServerCapabilities` type and `ServerCapabilities` field to `GetProviderSchemaResponse`
7+
```
8+
9+
```release-note:enhancement
10+
tfprotov6: Added `ServerCapabilities` type and `ServerCapabilities` field to `GetProviderSchemaResponse`
11+
```

tfprotov5/internal/tfplugin5/tfplugin5.pb.go

Lines changed: 618 additions & 534 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tfprotov5/internal/tfplugin5/tfplugin5.proto

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Terraform Plugin RPC protocol version 5.2
1+
// Terraform Plugin RPC protocol version 5.3
22
//
3-
// This file defines version 5.2 of the RPC protocol. To implement a plugin
3+
// This file defines version 5.3 of the RPC protocol. To implement a plugin
44
// against this protocol, copy this definition into your own codebase and
55
// use protoc to generate stubs for your target language.
66
//
@@ -13,7 +13,7 @@
1313
// official protocol releases. Proto files taken from other commits may include
1414
// incomplete changes or features that did not make it into a final release.
1515
// In all reasonable cases, plugin developers should take the proto file from
16-
// the tag of the most recent release of Terraform, and not from the master
16+
// the tag of the most recent release of Terraform, and not from the main
1717
// branch or any other development branch.
1818
//
1919
syntax = "proto3";
@@ -118,7 +118,7 @@ message Schema {
118118

119119
// The version of the schema.
120120
// Schemas are versioned, so that providers can upgrade a saved resource
121-
// state when the schema is changed.
121+
// state when the schema is changed.
122122
int64 version = 1;
123123

124124
// Block is the top level configuration block for this schema.
@@ -157,6 +157,18 @@ message GetProviderSchema {
157157
map<string, Schema> data_source_schemas = 3;
158158
repeated Diagnostic diagnostics = 4;
159159
Schema provider_meta = 5;
160+
ServerCapabilities server_capabilities = 6;
161+
}
162+
163+
164+
// ServerCapabilities allows providers to communicate extra information
165+
// regarding supported protocol features. This is used to indicate
166+
// availability of certain forward-compatible changes which may be optional
167+
// in a major protocol version, but cannot be tested for directly.
168+
message ServerCapabilities {
169+
// The plan_destroy capability signals that a provider expects a call
170+
// to PlanResourceChange when a resource is going to be destroyed.
171+
bool plan_destroy = 1;
160172
}
161173
}
162174

@@ -247,14 +259,14 @@ message PlanResourceChange {
247259
DynamicValue prior_state = 2;
248260
DynamicValue proposed_new_state = 3;
249261
DynamicValue config = 4;
250-
bytes prior_private = 5;
262+
bytes prior_private = 5;
251263
DynamicValue provider_meta = 6;
252264
}
253265

254266
message Response {
255267
DynamicValue planned_state = 1;
256268
repeated AttributePath requires_replace = 2;
257-
bytes planned_private = 3;
269+
bytes planned_private = 3;
258270
repeated Diagnostic diagnostics = 4;
259271

260272

@@ -279,12 +291,12 @@ message ApplyResourceChange {
279291
DynamicValue prior_state = 2;
280292
DynamicValue planned_state = 3;
281293
DynamicValue config = 4;
282-
bytes planned_private = 5;
294+
bytes planned_private = 5;
283295
DynamicValue provider_meta = 6;
284296
}
285297
message Response {
286298
DynamicValue new_state = 1;
287-
bytes private = 2;
299+
bytes private = 2;
288300
repeated Diagnostic diagnostics = 3;
289301

290302
// This may be set only by the helper/schema "SDK" in the main Terraform
@@ -365,5 +377,5 @@ message ProvisionResource {
365377
message Response {
366378
string output = 1;
367379
repeated Diagnostic diagnostics = 2;
368-
}
380+
}
369381
}

tfprotov5/internal/toproto/provider.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ func GetProviderSchema_Request(in *tfprotov5.GetProviderSchemaRequest) (*tfplugi
1212
}
1313

1414
func GetProviderSchema_Response(in *tfprotov5.GetProviderSchemaResponse) (*tfplugin5.GetProviderSchema_Response, error) {
15-
var resp tfplugin5.GetProviderSchema_Response
15+
if in == nil {
16+
return nil, nil
17+
}
18+
resp := tfplugin5.GetProviderSchema_Response{
19+
ServerCapabilities: GetProviderSchema_ServerCapabilities(in.ServerCapabilities),
20+
}
1621
if in.Provider != nil {
1722
schema, err := Schema(in.Provider)
1823
if err != nil {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package toproto
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
5+
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
6+
)
7+
8+
func GetProviderSchema_ServerCapabilities(in *tfprotov5.ServerCapabilities) *tfplugin5.GetProviderSchema_ServerCapabilities {
9+
if in == nil {
10+
return nil
11+
}
12+
13+
return &tfplugin5.GetProviderSchema_ServerCapabilities{
14+
PlanDestroy: in.PlanDestroy,
15+
}
16+
}

tfprotov5/provider.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ type GetProviderSchemaRequest struct{}
4646
// GetProviderSchemaResponse represents a Terraform RPC response containing the
4747
// provider's schemas.
4848
type GetProviderSchemaResponse struct {
49+
// ServerCapabilities defines optionally supported protocol features,
50+
// such as forward-compatible Terraform behavior changes.
51+
ServerCapabilities *ServerCapabilities
52+
4953
// Provider defines the schema for the provider configuration, which
5054
// will be specified in the provider block of the user's configuration.
5155
Provider *Schema

tfprotov5/server_capabilities.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tfprotov5
2+
3+
// ServerCapabilities allows providers to communicate optionally supported
4+
// protocol features, such as forward-compatible Terraform behavior changes.
5+
//
6+
// This information is used in GetProviderSchemaResponse as capabilities are
7+
// static features which must be known upfront in the provider server.
8+
type ServerCapabilities struct {
9+
// PlanDestroy signals that a provider expects a call to
10+
// PlanResourceChange when a resource is going to be destroyed. This is
11+
// opt-in to prevent unexpected errors or panics since the
12+
// ProposedNewState in PlanResourceChangeRequest will be a null value.
13+
PlanDestroy bool
14+
}

tfprotov5/tf5server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
//
4646
// In the future, it may be possible to include this information directly
4747
// in the protocol buffers rather than recreating a constant here.
48-
protocolVersionMinor uint = 2
48+
protocolVersionMinor uint = 3
4949
)
5050

5151
// protocolVersion represents the combined major and minor version numbers of

0 commit comments

Comments
 (0)