Skip to content

Commit 4c19f06

Browse files
authored
Update action proto v5/v6 definitions to match TF core (#554)
* remove schema types + adjust protocol * add linked resource config to validate * adjust go version back
1 parent f90fa5d commit 4c19f06

File tree

18 files changed

+1404
-2109
lines changed

18 files changed

+1404
-2109
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
module github.com/hashicorp/terraform-plugin-go
22

3-
go 1.24
3+
go 1.23.0
44

5-
toolchain go1.24.1
5+
toolchain go1.23.7
66

77
require (
88
github.com/google/go-cmp v0.7.0
99
github.com/hashicorp/go-hclog v1.6.3
10-
github.com/hashicorp/go-plugin v1.7.0
10+
github.com/hashicorp/go-plugin v1.6.3
1111
github.com/hashicorp/go-uuid v1.0.3
1212
github.com/hashicorp/terraform-plugin-log v0.9.0
1313
github.com/hashicorp/terraform-registry-address v0.4.0

go.sum

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
2-
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
1+
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
2+
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
33
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
44
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
55
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
@@ -17,8 +17,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1717
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
1818
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
1919
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
20-
github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshfk+mA=
21-
github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8=
20+
github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg=
21+
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
2222
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
2323
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
2424
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
@@ -29,8 +29,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S
2929
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
3030
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
3131
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
32-
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
33-
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
32+
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
33+
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
3434
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
3535
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
3636
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
@@ -45,8 +45,9 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV
4545
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
4646
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
4747
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
48-
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
4948
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
49+
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
50+
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
5051
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
5152
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
5253
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=

tfprotov5/action.go

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,30 @@ type ValidateActionConfigRequest struct {
5757
// from knowing the value at request time. Any attributes not directly
5858
// set in the configuration will be null.
5959
Config *DynamicValue
60+
61+
// LinkedResources contains the configuration data of the managed resource types that are linked to this action.
62+
//
63+
// - If the action schema type is Unlinked, this field will be empty.
64+
LinkedResources []*LinkedResourceConfig
65+
}
66+
67+
// LinkedResourceConfig represents linked resource config data used in the ValidateActionConfig RPC.
68+
type LinkedResourceConfig struct {
69+
// TypeName is the type of linked resource Terraform is validating.
70+
TypeName string
71+
72+
// Config is the configuration the user supplied for the linked resource. See
73+
// the documentation on `DynamicValue` for more information about
74+
// safely accessing the configuration.
75+
//
76+
// The configuration is represented as a tftypes.Object, with each
77+
// attribute and nested block getting its own key and value.
78+
//
79+
// This configuration may contain unknown values if a user uses
80+
// interpolation or other functionality that would prevent Terraform
81+
// from knowing the value at request time. Any attributes not directly
82+
// set in the configuration will be null.
83+
Config *DynamicValue
6084
}
6185

6286
// ValidateActionConfigResponse is the response from the provider about
@@ -77,13 +101,6 @@ type PlanActionRequest struct {
77101
// LinkedResources contains the data of the managed resource types that are linked to this action.
78102
//
79103
// - If the action schema type is Unlinked, this field will be empty.
80-
// - If the action schema type is Lifecycle, this field will contain a single linked resource.
81-
// - If the action schema type is Linked, this field will be one or more linked resources, which
82-
// will be in the same order as the linked resource schemas are defined in the action schema.
83-
//
84-
// For Lifecycle actions, the provider may only change computed-only attributes.
85-
//
86-
// For Linked actions, the provider may change any attributes as long as it adheres to the resource schema.
87104
LinkedResources []*ProposedLinkedResource
88105

89106
// Config is the configuration the user supplied for the action. See
@@ -128,9 +145,7 @@ type ProposedLinkedResource struct {
128145
type PlanActionResponse struct {
129146
// LinkedResources contains the provider modified data of the managed resource types that are linked to this action.
130147
//
131-
// For Lifecycle actions, the provider may only change computed-only attributes.
132-
//
133-
// For Linked actions, the provider may change any attributes as long as it adheres to the resource schema.
148+
// This field is not currently in-use, but future action schema types will use this field to plan modifications of state data for linked resources.
134149
LinkedResources []*PlannedLinkedResource
135150

136151
// Diagnostics report errors or warnings related to plannning the action and calculating
@@ -165,13 +180,6 @@ type InvokeActionRequest struct {
165180
// LinkedResources contains the data of the managed resource types that are linked to this action.
166181
//
167182
// - If the action schema type is Unlinked, this field will be empty.
168-
// - If the action schema type is Lifecycle, this field will contain a single linked resource.
169-
// - If the action schema type is Linked, this field will be one or more linked resources, which
170-
// will be in the same order as the linked resource schemas are defined in the action schema.
171-
//
172-
// For Lifecycle actions, the provider may only change computed-only attributes.
173-
//
174-
// For Linked actions, the provider may change any attributes as long as it adheres to the resource schema.
175183
LinkedResources []*InvokeLinkedResource
176184

177185
// Config is the configuration the user supplied for the action. See
@@ -252,9 +260,7 @@ func (a ProgressInvokeActionEventType) isInvokeActionEventType() {}
252260
type CompletedInvokeActionEventType struct {
253261
// LinkedResources contains the provider modified data of the managed resource types that are linked to this action.
254262
//
255-
// For Lifecycle actions, the provider may only change computed-only attributes.
256-
//
257-
// For Linked actions, the provider may change any attributes as long as it adheres to the resource schema.
263+
// This field is not currently in-use, but future action schema types will use this field to modify state data for linked resources.
258264
LinkedResources []*NewLinkedResource
259265

260266
// Diagnostics report errors or warnings related to invoking an action.

tfprotov5/action_schema.go

Lines changed: 3 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -10,97 +10,26 @@ type ActionSchema struct {
1010
Schema *Schema
1111

1212
// Type defines how a practitioner can trigger an action, as well as what effect the action can have on the state
13-
// of the linked managed resources. There are currently three different types of actions:
13+
// of the linked managed resources. There is currently only one type of action supported:
1414
// - Unlinked actions are actions that cannot cause changes to resource states.
15-
// - Lifecycle actions are actions that can cause changes to exactly one resource state.
16-
// - Linked actions are actions that can cause changes to one or more resource states.
1715
Type ActionSchemaType
1816
}
1917

2018
// ActionSchemaType is an intentionally unimplementable interface that
2119
// functions as an enum, allowing us to use different strongly-typed action schema types
2220
// that contain additional, but different data, as a generic "action" type.
2321
//
24-
// An action can only be one type (Unlinked, Lifecycle, or Linked), which are all statically defined in the protocol.
22+
// An action can currently only be one type (Unlinked), which is statically defined in the protocol. Future action types
23+
// will be added to the protocol first, then implemented in this package.
2524
type ActionSchemaType interface {
2625
isActionSchemaType()
2726
}
2827

2928
var (
3029
_ ActionSchemaType = UnlinkedActionSchemaType{}
31-
_ ActionSchemaType = LifecycleActionSchemaType{}
32-
_ ActionSchemaType = LinkedActionSchemaType{}
3330
)
3431

3532
// UnlinkedActionSchemaType represents an unlinked action, which cannot cause changes to resource states.
3633
type UnlinkedActionSchemaType struct{}
3734

3835
func (a UnlinkedActionSchemaType) isActionSchemaType() {}
39-
40-
// LifecycleActionSchemaType represents a lifecycle action, which can cause changes to exactly one resource state,
41-
// which is the linked resource.
42-
type LifecycleActionSchemaType struct {
43-
// Executes defines when the lifecycle action must be executed in relation to the linked resource, either before
44-
// or after the linked resource's plan/apply.
45-
Executes LifecycleExecutionOrder
46-
47-
// LinkedResource is the managed resource type that this action can make state changes to.
48-
// This linked resource is currently restricted to be defined in the same provider as the action is defined.
49-
LinkedResource *LinkedResourceSchema
50-
}
51-
52-
func (a LifecycleActionSchemaType) isActionSchemaType() {}
53-
54-
const (
55-
// LifecycleExecutionOrderInvalid is used to indicate an invalid `LifecycleExecutionOrder`.
56-
// Provider developers should not use it.
57-
LifecycleExecutionOrderInvalid LifecycleExecutionOrder = 0
58-
59-
// LifecycleExecutionOrderBefore is used to indicate that the action must be invoked before it's
60-
// linked resource's plan/apply.
61-
LifecycleExecutionOrderBefore LifecycleExecutionOrder = 1
62-
63-
// LifecycleExecutionOrderAfter is used to indicate that the action must be invoked after it's
64-
// linked resource's plan/apply.
65-
LifecycleExecutionOrderAfter LifecycleExecutionOrder = 2
66-
)
67-
68-
// LifecycleExecutionOrder is an enum that represents when an action is invoked relative to it's linked resource.
69-
type LifecycleExecutionOrder int32
70-
71-
func (l LifecycleExecutionOrder) String() string {
72-
switch l {
73-
case 0:
74-
return "INVALID"
75-
case 1:
76-
return "BEFORE"
77-
case 2:
78-
return "AFTER"
79-
case 3:
80-
}
81-
return "UNKNOWN"
82-
}
83-
84-
// LinkedResourceSchema represents information about the schema of a linked resource, which is used by an action schema to describe to Terraform the
85-
// resource types that an action is allowed to change the state of. Linked resources are currently restricted to be defined in the same provider
86-
// as the action is defined.
87-
//
88-
// LinkedResourceSchema does not contain the entire schema definition of the linked resource, which must be obtained by the provider in order to
89-
// decode the linked resource plan/state/identity protocol data during PlanAction and InvokeAction.
90-
type LinkedResourceSchema struct {
91-
// TypeName is the name of the managed resource which can have it's resource state changed by the action. The name should be prefixed with
92-
// the provider shortname and an underscore.
93-
TypeName string
94-
95-
// Description is a human-readable description of the linked resource.
96-
Description string
97-
}
98-
99-
// LinkedActionSchemaType represents a linked action, which can cause changes to one or more resource states.
100-
type LinkedActionSchemaType struct {
101-
// LinkedResources are the managed resource types that this action can make state changes to.
102-
// These linked resources are currently restricted to be defined in the same provider as the action is defined.
103-
LinkedResources []*LinkedResourceSchema
104-
}
105-
106-
func (a LinkedActionSchemaType) isActionSchemaType() {}

tfprotov5/internal/fromproto/action.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,23 @@ func ValidateActionConfigRequest(in *tfplugin5.ValidateActionConfig_Request) *tf
1414
}
1515

1616
return &tfprotov5.ValidateActionConfigRequest{
17-
ActionType: in.ActionType,
18-
Config: DynamicValue(in.Config),
17+
ActionType: in.ActionType,
18+
Config: DynamicValue(in.Config),
19+
LinkedResources: LinkedResourceConfigs(in.LinkedResources),
20+
}
21+
}
22+
23+
func LinkedResourceConfigs(in []*tfplugin5.LinkedResourceConfig) []*tfprotov5.LinkedResourceConfig {
24+
resp := make([]*tfprotov5.LinkedResourceConfig, 0, len(in))
25+
26+
for _, inLinkedResource := range in {
27+
resp = append(resp, &tfprotov5.LinkedResourceConfig{
28+
TypeName: inLinkedResource.TypeName,
29+
Config: DynamicValue(inLinkedResource.Config),
30+
})
1931
}
32+
33+
return resp
2034
}
2135

2236
func PlanActionRequest(in *tfplugin5.PlanAction_Request) *tfprotov5.PlanActionRequest {

tfprotov5/internal/fromproto/actions_test.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,45 @@ func TestValidateActionConfigRequest(t *testing.T) {
2424
expected: nil,
2525
},
2626
"zero": {
27-
in: &tfplugin5.ValidateActionConfig_Request{},
28-
expected: &tfprotov5.ValidateActionConfigRequest{},
27+
in: &tfplugin5.ValidateActionConfig_Request{},
28+
expected: &tfprotov5.ValidateActionConfigRequest{
29+
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
30+
},
2931
},
3032
"Config": {
3133
in: &tfplugin5.ValidateActionConfig_Request{
3234
Config: testTfplugin5DynamicValue(),
3335
},
3436
expected: &tfprotov5.ValidateActionConfigRequest{
35-
Config: testTfprotov5DynamicValue(),
37+
Config: testTfprotov5DynamicValue(),
38+
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
3639
},
3740
},
3841
"ActionType": {
3942
in: &tfplugin5.ValidateActionConfig_Request{
4043
ActionType: "test",
4144
},
4245
expected: &tfprotov5.ValidateActionConfigRequest{
43-
ActionType: "test",
46+
ActionType: "test",
47+
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
48+
},
49+
},
50+
"LinkedResources": {
51+
in: &tfplugin5.ValidateActionConfig_Request{
52+
LinkedResources: []*tfplugin5.LinkedResourceConfig{
53+
{
54+
TypeName: "test_linked",
55+
Config: testTfplugin5DynamicValue(),
56+
},
57+
},
58+
},
59+
expected: &tfprotov5.ValidateActionConfigRequest{
60+
LinkedResources: []*tfprotov5.LinkedResourceConfig{
61+
{
62+
TypeName: "test_linked",
63+
Config: testTfprotov5DynamicValue(),
64+
},
65+
},
4466
},
4567
},
4668
}

0 commit comments

Comments
 (0)