Skip to content

Commit 71a1984

Browse files
authored
Add protobuf support for resource identity messages and rpcs (#472)
* Add protobuf support for resource identity messages and rpcs * add more identity procotol changes made by core * implement core change to rename prior_identity to planned_identity for ApplyResourceChange.Request
1 parent 8799237 commit 71a1984

File tree

8 files changed

+4133
-2461
lines changed

8 files changed

+4133
-2461
lines changed

tfprotov5/internal/tfplugin5/tfplugin5.pb.go

Lines changed: 1981 additions & 1289 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: 70 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) HashiCorp, Inc.
22
// SPDX-License-Identifier: MPL-2.0
33

4-
// Terraform Plugin RPC protocol version 5.8
4+
// Terraform Plugin RPC protocol version 5.9
55
//
6-
// This file defines version 5.8 of the RPC protocol. To implement a plugin
6+
// This file defines version 5.9 of the RPC protocol. To implement a plugin
77
// against this protocol, copy this definition into your own codebase and
88
// use protoc to generate stubs for your target language.
99
//
@@ -142,6 +142,32 @@ message Schema {
142142
Block block = 2;
143143
}
144144

145+
// ResourceIdentitySchema is the identity schema for a Resource.
146+
message ResourceIdentitySchema {
147+
// IdentityAttribute represents one value of data within resource identity.
148+
// These are always used in resource identity comparisons.
149+
message IdentityAttribute {
150+
string name = 1;
151+
bytes type = 2;
152+
bool required_for_import = 3;
153+
bool optional_for_import = 4;
154+
string description = 5;
155+
}
156+
157+
// The version of the schema
158+
int64 identity_version = 1;
159+
160+
// The list of attributes that make up the identity of the resource
161+
repeated IdentityAttribute identity_attributes = 2;
162+
}
163+
164+
// ResourceIdentityData is a separate message for better extensibility
165+
message ResourceIdentityData {
166+
// identity_data is the resource identity data for the given definition.
167+
// It should be decoded using the identity schema.
168+
DynamicValue identity_data = 1;
169+
}
170+
145171
// ServerCapabilities allows providers to communicate extra information
146172
// regarding supported protocol features. This is used to indicate
147173
// availability of certain forward-compatible changes which may be optional
@@ -263,10 +289,12 @@ service Provider {
263289
// GetSchema returns schema information for the provider, data resources,
264290
// and managed resources.
265291
rpc GetSchema(GetProviderSchema.Request) returns (GetProviderSchema.Response);
292+
rpc GetResourceIdentitySchemas(GetResourceIdentitySchemas.Request) returns (GetResourceIdentitySchemas.Response);
266293
rpc PrepareProviderConfig(PrepareProviderConfig.Request) returns (PrepareProviderConfig.Response);
267294
rpc ValidateResourceTypeConfig(ValidateResourceTypeConfig.Request) returns (ValidateResourceTypeConfig.Response);
268295
rpc ValidateDataSourceConfig(ValidateDataSourceConfig.Request) returns (ValidateDataSourceConfig.Response);
269296
rpc UpgradeResourceState(UpgradeResourceState.Request) returns (UpgradeResourceState.Response);
297+
rpc UpgradeResourceIdentity(UpgradeResourceIdentity.Request) returns (UpgradeResourceIdentity.Response);
270298

271299
//////// One-time initialization, called before other functions below
272300
rpc Configure(Configure.Request) returns (Configure.Response);
@@ -441,6 +469,7 @@ message ReadResource {
441469
bytes private = 3;
442470
DynamicValue provider_meta = 4;
443471
ClientCapabilities client_capabilities = 5;
472+
ResourceIdentityData current_identity = 6;
444473
}
445474
message Response {
446475
DynamicValue new_state = 1;
@@ -449,6 +478,7 @@ message ReadResource {
449478
// deferred is set if the provider is deferring the change. If set the caller
450479
// needs to handle the deferral.
451480
Deferred deferred = 4;
481+
ResourceIdentityData new_identity = 5;
452482
}
453483
}
454484

@@ -461,6 +491,7 @@ message PlanResourceChange {
461491
bytes prior_private = 5;
462492
DynamicValue provider_meta = 6;
463493
ClientCapabilities client_capabilities = 7;
494+
ResourceIdentityData prior_identity = 8;
464495
}
465496

466497
message Response {
@@ -485,6 +516,7 @@ message PlanResourceChange {
485516
// deferred is set if the provider is deferring the change. If set the caller
486517
// needs to handle the deferral.
487518
Deferred deferred = 6;
519+
ResourceIdentityData planned_identity = 7;
488520
}
489521
}
490522

@@ -496,6 +528,7 @@ message ApplyResourceChange {
496528
DynamicValue config = 4;
497529
bytes planned_private = 5;
498530
DynamicValue provider_meta = 6;
531+
ResourceIdentityData planned_identity = 7;
499532
}
500533
message Response {
501534
DynamicValue new_state = 1;
@@ -514,6 +547,7 @@ message ApplyResourceChange {
514547
// ==== THIS MUST BE LEFT UNSET IN ALL OTHER SDKS ====
515548
// ==== DO NOT USE THIS ====
516549
bool legacy_type_system = 4;
550+
ResourceIdentityData new_identity = 5;
517551
}
518552
}
519553

@@ -522,12 +556,14 @@ message ImportResourceState {
522556
string type_name = 1;
523557
string id = 2;
524558
ClientCapabilities client_capabilities = 3;
559+
ResourceIdentityData identity = 4;
525560
}
526561

527562
message ImportedResource {
528563
string type_name = 1;
529564
DynamicValue state = 2;
530565
bytes private = 3;
566+
ResourceIdentityData identity = 4;
531567
}
532568

533569
message Response {
@@ -561,6 +597,8 @@ message MoveResourceState {
561597

562598
// The private state of the resource being moved.
563599
bytes source_private = 6;
600+
601+
ResourceIdentityData source_identity = 7;
564602
}
565603

566604
message Response {
@@ -572,6 +610,8 @@ message MoveResourceState {
572610

573611
// The private state of the resource after it has been moved.
574612
bytes target_private = 3;
613+
614+
ResourceIdentityData target_identity = 4;
575615
}
576616
}
577617

@@ -704,4 +744,31 @@ message CloseEphemeralResource {
704744
message Response {
705745
repeated Diagnostic diagnostics = 1;
706746
}
707-
}
747+
}
748+
749+
// Returns resource identity schemas for all resources
750+
message GetResourceIdentitySchemas {
751+
message Request {
752+
}
753+
message Response {
754+
map<string, ResourceIdentitySchema> identity_schemas = 1;
755+
repeated Diagnostic diagnostics = 2;
756+
}
757+
}
758+
759+
message UpgradeResourceIdentity {
760+
message Request {
761+
string type_name = 1;
762+
763+
// version is the identity_schema_version number recorded in
764+
// the state file
765+
int64 version = 2;
766+
767+
// raw_identity is the stored identity from the state in json
768+
bytes raw_identity = 3;
769+
}
770+
message Response {
771+
ResourceIdentityData upgraded_identity = 1;
772+
repeated Diagnostic diagnostics = 2;
773+
}
774+
}

tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go

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

tfprotov5/tf5server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const (
4949
//
5050
// In the future, it may be possible to include this information directly
5151
// in the protocol buffers rather than recreating a constant here.
52-
protocolVersionMinor uint = 8
52+
protocolVersionMinor uint = 9
5353
)
5454

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

0 commit comments

Comments
 (0)