Skip to content

Commit

Permalink
tfprotov5+tfprotov6: Support for Protocol Version 5.3 and 6.3 (#205)
Browse files Browse the repository at this point in the history
Reference: #204
  • Loading branch information
bflad committed Jul 8, 2022
1 parent 2d80909 commit a494582
Show file tree
Hide file tree
Showing 15 changed files with 1,278 additions and 995 deletions.
11 changes: 11 additions & 0 deletions .changelog/205.txt
@@ -0,0 +1,11 @@
```release-note:feature
Added support for protocol version 5.3 and 6.3, which allows providers to opt into the `PlanResourceChange` RPC for resource destruction
```

```release-note:enhancement
tfprotov5: Added `ServerCapabilities` type and `ServerCapabilities` field to `GetProviderSchemaResponse`
```

```release-note:enhancement
tfprotov6: Added `ServerCapabilities` type and `ServerCapabilities` field to `GetProviderSchemaResponse`
```
1,152 changes: 618 additions & 534 deletions tfprotov5/internal/tfplugin5/tfplugin5.pb.go

Large diffs are not rendered by default.

30 changes: 21 additions & 9 deletions tfprotov5/internal/tfplugin5/tfplugin5.proto
@@ -1,6 +1,6 @@
// Terraform Plugin RPC protocol version 5.2
// Terraform Plugin RPC protocol version 5.3
//
// This file defines version 5.2 of the RPC protocol. To implement a plugin
// This file defines version 5.3 of the RPC protocol. To implement a plugin
// against this protocol, copy this definition into your own codebase and
// use protoc to generate stubs for your target language.
//
Expand All @@ -13,7 +13,7 @@
// official protocol releases. Proto files taken from other commits may include
// incomplete changes or features that did not make it into a final release.
// In all reasonable cases, plugin developers should take the proto file from
// the tag of the most recent release of Terraform, and not from the master
// the tag of the most recent release of Terraform, and not from the main
// branch or any other development branch.
//
syntax = "proto3";
Expand Down Expand Up @@ -118,7 +118,7 @@ message Schema {

// The version of the schema.
// Schemas are versioned, so that providers can upgrade a saved resource
// state when the schema is changed.
// state when the schema is changed.
int64 version = 1;

// Block is the top level configuration block for this schema.
Expand Down Expand Up @@ -157,6 +157,18 @@ message GetProviderSchema {
map<string, Schema> data_source_schemas = 3;
repeated Diagnostic diagnostics = 4;
Schema provider_meta = 5;
ServerCapabilities server_capabilities = 6;
}


// ServerCapabilities allows providers to communicate extra information
// regarding supported protocol features. This is used to indicate
// availability of certain forward-compatible changes which may be optional
// in a major protocol version, but cannot be tested for directly.
message ServerCapabilities {
// The plan_destroy capability signals that a provider expects a call
// to PlanResourceChange when a resource is going to be destroyed.
bool plan_destroy = 1;
}
}

Expand Down Expand Up @@ -247,14 +259,14 @@ message PlanResourceChange {
DynamicValue prior_state = 2;
DynamicValue proposed_new_state = 3;
DynamicValue config = 4;
bytes prior_private = 5;
bytes prior_private = 5;
DynamicValue provider_meta = 6;
}

message Response {
DynamicValue planned_state = 1;
repeated AttributePath requires_replace = 2;
bytes planned_private = 3;
bytes planned_private = 3;
repeated Diagnostic diagnostics = 4;


Expand All @@ -279,12 +291,12 @@ message ApplyResourceChange {
DynamicValue prior_state = 2;
DynamicValue planned_state = 3;
DynamicValue config = 4;
bytes planned_private = 5;
bytes planned_private = 5;
DynamicValue provider_meta = 6;
}
message Response {
DynamicValue new_state = 1;
bytes private = 2;
bytes private = 2;
repeated Diagnostic diagnostics = 3;

// This may be set only by the helper/schema "SDK" in the main Terraform
Expand Down Expand Up @@ -365,5 +377,5 @@ message ProvisionResource {
message Response {
string output = 1;
repeated Diagnostic diagnostics = 2;
}
}
}
7 changes: 6 additions & 1 deletion tfprotov5/internal/toproto/provider.go
Expand Up @@ -12,7 +12,12 @@ func GetProviderSchema_Request(in *tfprotov5.GetProviderSchemaRequest) (*tfplugi
}

func GetProviderSchema_Response(in *tfprotov5.GetProviderSchemaResponse) (*tfplugin5.GetProviderSchema_Response, error) {
var resp tfplugin5.GetProviderSchema_Response
if in == nil {
return nil, nil
}
resp := tfplugin5.GetProviderSchema_Response{
ServerCapabilities: GetProviderSchema_ServerCapabilities(in.ServerCapabilities),
}
if in.Provider != nil {
schema, err := Schema(in.Provider)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions tfprotov5/internal/toproto/server_capabilities.go
@@ -0,0 +1,16 @@
package toproto

import (
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5"
)

func GetProviderSchema_ServerCapabilities(in *tfprotov5.ServerCapabilities) *tfplugin5.GetProviderSchema_ServerCapabilities {
if in == nil {
return nil
}

return &tfplugin5.GetProviderSchema_ServerCapabilities{
PlanDestroy: in.PlanDestroy,
}
}
4 changes: 4 additions & 0 deletions tfprotov5/provider.go
Expand Up @@ -46,6 +46,10 @@ type GetProviderSchemaRequest struct{}
// GetProviderSchemaResponse represents a Terraform RPC response containing the
// provider's schemas.
type GetProviderSchemaResponse struct {
// ServerCapabilities defines optionally supported protocol features,
// such as forward-compatible Terraform behavior changes.
ServerCapabilities *ServerCapabilities

// Provider defines the schema for the provider configuration, which
// will be specified in the provider block of the user's configuration.
Provider *Schema
Expand Down
14 changes: 14 additions & 0 deletions tfprotov5/server_capabilities.go
@@ -0,0 +1,14 @@
package tfprotov5

// ServerCapabilities allows providers to communicate optionally supported
// protocol features, such as forward-compatible Terraform behavior changes.
//
// This information is used in GetProviderSchemaResponse as capabilities are
// static features which must be known upfront in the provider server.
type ServerCapabilities struct {
// PlanDestroy signals that a provider expects a call to
// PlanResourceChange when a resource is going to be destroyed. This is
// opt-in to prevent unexpected errors or panics since the
// ProposedNewState in PlanResourceChangeRequest will be a null value.
PlanDestroy bool
}
2 changes: 1 addition & 1 deletion tfprotov5/tf5server/server.go
Expand Up @@ -45,7 +45,7 @@ const (
//
// In the future, it may be possible to include this information directly
// in the protocol buffers rather than recreating a constant here.
protocolVersionMinor uint = 2
protocolVersionMinor uint = 3
)

// protocolVersion represents the combined major and minor version numbers of
Expand Down

0 comments on commit a494582

Please sign in to comment.