Skip to content

Commit 176263d

Browse files
actions: remove future action types
removing them for now, this gives us more flexibility in the future since the schema is not yet locked in
1 parent 4fadc32 commit 176263d

File tree

15 files changed

+1155
-3915
lines changed

15 files changed

+1155
-3915
lines changed

docs/plugin-protocol/tfplugin5.proto

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -146,47 +146,14 @@ message ResourceIdentityData {
146146

147147
// ActionSchema defines the schema for an action that can be invoked by Terraform.
148148
message ActionSchema {
149-
message LinkedResource {
150-
string type_name = 1;
151-
// description is a human-readable description of the role of the linked resource.
152-
// For lifecycle actions this is most likely just the resource being acted upon.
153-
// For linked actions where multiple resources are linked, this description should
154-
// help the user understand what the resource is used for.
155-
// We expect markdown formatting for the description.
156-
string description = 2;
157-
}
158-
159149
// An Unlinked action is an action that is not linked to any resources. It may contain
160150
// references to resources but it can not change the resource state of any resource.
161151
message Unlinked {}
162-
163-
// A Lifecycle action is an action that is linked to a resources lifecycle. It runs as part of
164-
// the lifecycle and may change the resource state of the resource it is linked to to a degree.
165-
// It can only affect computed attributes of the resource it is linked to.
166-
message Lifecycle {
167-
// ExecutionOrder defines if the action should be executed before or after the resource,
168-
// in whose lifecycle the action runs, applies
169-
enum ExecutionOrder {
170-
INVALID = 0;
171-
BEFORE = 1;
172-
AFTER = 2;
173-
}
174-
175-
ExecutionOrder executes = 1;
176-
LinkedResource linked_resource = 2;
177-
}
178-
179-
// A linked action can be linked to multiple resources and can change the resource state of those resources. It can not be run as part of plan and apply.
180-
message Linked {
181-
repeated LinkedResource linked_resources = 1;
182-
}
183152

184153
Schema schema = 1; // of the action itself
185154

186155
oneof type {
187156
Unlinked unlinked = 2;
188-
Lifecycle lifecycle = 3;
189-
Linked linked = 4;
190157
}
191158
}
192159

docs/plugin-protocol/tfplugin6.proto

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -146,46 +146,14 @@ message ResourceIdentityData {
146146

147147
// ActionSchema defines the schema for an action that can be invoked by Terraform.
148148
message ActionSchema {
149-
message LinkedResource {
150-
string type_name = 1;
151-
// description is a human-readable description of the role of the linked resource.
152-
// For lifecycle actions this is most likely just the resource being acted upon.
153-
// For linked actions where multiple resources are linked, this description should
154-
// help the user understand what the resource is used for.
155-
string description = 2;
156-
}
157-
158149
// An Unlinked action is an action that is not linked to any resources. It may contain
159150
// references to resources but it can not change the resource state of any resource.
160151
message Unlinked {}
161-
162-
// A Lifecycle action is an action that is linked to a resources lifecycle. It runs as part of
163-
// the lifecycle and may change the resource state of the resource it is linked to to a degree.
164-
// It can only affect computed attributes of the resource it is linked to.
165-
message Lifecycle {
166-
// ExecutionOrder defines if the action should be executed before or after the resource,
167-
// in whose lifecycle the action runs, applies
168-
enum ExecutionOrder {
169-
INVALID = 0;
170-
BEFORE = 1;
171-
AFTER = 2;
172-
}
173-
174-
ExecutionOrder executes = 1;
175-
LinkedResource linked_resource = 2;
176-
}
177-
178-
// A linked action can be linked to multiple resources and can change the resource state of those resources. It can not be run as part of plan and apply.
179-
message Linked {
180-
repeated LinkedResource linked_resources = 1;
181-
}
182152

183153
Schema schema = 1; // of the action itself
184154

185155
oneof type {
186156
Unlinked unlinked = 2;
187-
Lifecycle lifecycle = 3;
188-
Linked linked = 4;
189157
}
190158
}
191159

internal/command/jsonprovider/provider_test.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -252,38 +252,6 @@ func TestMarshalProvider(t *testing.T) {
252252
},
253253
Unlinked: &providers.UnlinkedAction{},
254254
},
255-
"test_linked_action": {
256-
ConfigSchema: &configschema.Block{
257-
Attributes: map[string]*configschema.Attribute{
258-
"opt_attr": {Type: cty.String, Optional: true},
259-
"req_attr": {Type: cty.List(cty.String), Required: true},
260-
},
261-
},
262-
Linked: &providers.LinkedAction{
263-
LinkedResources: []providers.LinkedResourceSchema{
264-
{
265-
TypeName: "test_resource_a",
266-
},
267-
{
268-
TypeName: "test_resource_b",
269-
},
270-
},
271-
},
272-
},
273-
"test_lifecycle_action": {
274-
ConfigSchema: &configschema.Block{
275-
Attributes: map[string]*configschema.Attribute{
276-
"opt_attr": {Type: cty.String, Optional: true},
277-
"req_attr": {Type: cty.List(cty.String), Required: true},
278-
},
279-
},
280-
Lifecycle: &providers.LifecycleAction{
281-
LinkedResource: providers.LinkedResourceSchema{
282-
TypeName: "test_resource_c",
283-
},
284-
Executes: providers.ExecutionOrderBefore,
285-
},
286-
},
287255
},
288256
},
289257
true,
@@ -332,56 +300,6 @@ func TestMarshalProvider(t *testing.T) {
332300
},
333301
Unlinked: &UnlinkedAction{},
334302
},
335-
"test_linked_action": {
336-
ConfigSchema: &Block{
337-
Attributes: map[string]*Attribute{
338-
"opt_attr": {
339-
AttributeType: json.RawMessage(`"string"`),
340-
Optional: true,
341-
DescriptionKind: "plain",
342-
},
343-
"req_attr": {
344-
AttributeType: json.RawMessage(`["list","string"]`),
345-
Required: true,
346-
DescriptionKind: "plain",
347-
},
348-
},
349-
DescriptionKind: "plain",
350-
},
351-
Linked: &LinkedAction{
352-
LinkedResources: []LinkedResourceSchema{
353-
{
354-
TypeName: "test_resource_a",
355-
},
356-
{
357-
TypeName: "test_resource_b",
358-
},
359-
},
360-
},
361-
},
362-
"test_lifecycle_action": {
363-
ConfigSchema: &Block{
364-
Attributes: map[string]*Attribute{
365-
"opt_attr": {
366-
AttributeType: json.RawMessage(`"string"`),
367-
Optional: true,
368-
DescriptionKind: "plain",
369-
},
370-
"req_attr": {
371-
AttributeType: json.RawMessage(`["list","string"]`),
372-
Required: true,
373-
DescriptionKind: "plain",
374-
},
375-
},
376-
DescriptionKind: "plain",
377-
},
378-
Lifecycle: &LifecycleAction{
379-
LinkedResource: LinkedResourceSchema{
380-
TypeName: "test_resource_c",
381-
},
382-
ExecutionOrder: "before",
383-
},
384-
},
385303
},
386304
},
387305
},

internal/command/jsonprovider/schema.go

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -72,24 +72,11 @@ func marshalIdentitySchemas(schemas map[string]providers.Schema) map[string]*Ide
7272
type ActionSchema struct {
7373
ConfigSchema *Block `json:"block,omitempty"`
7474

75-
// One of the following must be set
76-
Unlinked *UnlinkedAction `json:"unlinked,omitempty"`
77-
Linked *LinkedAction `json:"linked,omitempty"`
78-
Lifecycle *LifecycleAction `json:"lifecycle,omitempty"`
75+
// Only unlinked actions are supported.
76+
Unlinked *UnlinkedAction `json:"unlinked,omitempty"`
7977
}
8078

8179
type UnlinkedAction struct{}
82-
type LinkedAction struct {
83-
LinkedResources []LinkedResourceSchema `json:"linked_resources,omitempty"`
84-
}
85-
type LinkedResourceSchema struct {
86-
TypeName string `json:"type_name"`
87-
}
88-
89-
type LifecycleAction struct {
90-
LinkedResource LinkedResourceSchema `json:"linked_resource"`
91-
ExecutionOrder string `json:"execution_order"`
92-
}
9380

9481
func marshalActionSchemas(schemas map[string]providers.ActionSchema) map[string]*ActionSchema {
9582
ret := make(map[string]*ActionSchema, len(schemas))
@@ -106,23 +93,6 @@ func marshalActionSchema(schema providers.ActionSchema) *ActionSchema {
10693

10794
if schema.Unlinked != nil {
10895
ret.Unlinked = &UnlinkedAction{}
109-
} else if schema.Linked != nil {
110-
linkedResources := []LinkedResourceSchema{}
111-
for _, linkedResource := range schema.Linked.LinkedResources {
112-
linkedResources = append(linkedResources, LinkedResourceSchema{
113-
TypeName: linkedResource.TypeName,
114-
})
115-
}
116-
ret.Linked = &LinkedAction{
117-
LinkedResources: linkedResources,
118-
}
119-
} else if schema.Lifecycle != nil {
120-
ret.Lifecycle = &LifecycleAction{
121-
LinkedResource: LinkedResourceSchema{
122-
TypeName: schema.Lifecycle.LinkedResource.TypeName,
123-
},
124-
ExecutionOrder: string(schema.Lifecycle.Executes),
125-
}
12696
}
12797

12898
return ret

internal/grpcwrap/provider.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,20 +103,8 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
103103

104104
if act.Unlinked != nil {
105105
newAct.Type = &tfplugin5.ActionSchema_Unlinked_{}
106-
} else if act.Lifecycle != nil {
107-
newAct.Type = &tfplugin5.ActionSchema_Lifecycle_{
108-
Lifecycle: &tfplugin5.ActionSchema_Lifecycle{
109-
Executes: convert.ExecutionOrderToProto(act.Lifecycle.Executes),
110-
LinkedResource: convert.LinkedResourceToProto(act.Lifecycle.LinkedResource),
111-
},
112-
}
113-
} else if act.Linked != nil {
114-
newAct.Type = &tfplugin5.ActionSchema_Linked_{
115-
Linked: &tfplugin5.ActionSchema_Linked{
116-
LinkedResources: convert.LinkedResourcesToProto(act.Linked.LinkedResources),
117-
},
118-
}
119106
}
107+
120108
resp.ActionSchemas[typ] = &newAct
121109
}
122110

internal/grpcwrap/provider6.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -112,20 +112,8 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
112112

113113
if act.Unlinked != nil {
114114
newAct.Type = &tfplugin6.ActionSchema_Unlinked_{}
115-
} else if act.Lifecycle != nil {
116-
newAct.Type = &tfplugin6.ActionSchema_Lifecycle_{
117-
Lifecycle: &tfplugin6.ActionSchema_Lifecycle{
118-
Executes: convert.ExecutionOrderToProto(act.Lifecycle.Executes),
119-
LinkedResource: convert.LinkedResourceToProto(act.Lifecycle.LinkedResource),
120-
},
121-
}
122-
} else if act.Linked != nil {
123-
newAct.Type = &tfplugin6.ActionSchema_Linked_{
124-
Linked: &tfplugin6.ActionSchema_Linked{
125-
LinkedResources: convert.LinkedResourcesToProto(act.Linked.LinkedResources),
126-
},
127-
}
128115
}
116+
129117
resp.ActionSchemas[typ] = &newAct
130118
}
131119

internal/plugin/convert/schema.go

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -105,83 +105,16 @@ func ProtoToProviderSchema(s *proto.Schema, id *proto.ResourceIdentitySchema) pr
105105
return schema
106106
}
107107

108-
func ProtoToExecutionOrder(s proto.ActionSchema_Lifecycle_ExecutionOrder) providers.ExecutionOrder {
109-
switch s {
110-
case proto.ActionSchema_Lifecycle_INVALID:
111-
return providers.ExecutionOrderInvalid
112-
case proto.ActionSchema_Lifecycle_BEFORE:
113-
return providers.ExecutionOrderBefore
114-
case proto.ActionSchema_Lifecycle_AFTER:
115-
return providers.ExecutionOrderAfter
116-
default:
117-
panic("Unknown Execution Order, expected Invalid, Before, or After")
118-
}
119-
}
120-
121-
func ExecutionOrderToProto(s providers.ExecutionOrder) proto.ActionSchema_Lifecycle_ExecutionOrder {
122-
switch s {
123-
case providers.ExecutionOrderInvalid:
124-
return proto.ActionSchema_Lifecycle_INVALID
125-
case providers.ExecutionOrderBefore:
126-
return proto.ActionSchema_Lifecycle_BEFORE
127-
case providers.ExecutionOrderAfter:
128-
return proto.ActionSchema_Lifecycle_AFTER
129-
default:
130-
panic("Unknown Execution Order, expected Invalid, Before, or After")
131-
}
132-
}
133-
134-
func ProtoToLinkedResource(lr *proto.ActionSchema_LinkedResource) providers.LinkedResourceSchema {
135-
if lr == nil {
136-
return providers.LinkedResourceSchema{}
137-
}
138-
139-
return providers.LinkedResourceSchema{
140-
TypeName: lr.TypeName,
141-
}
142-
}
143-
144-
func LinkedResourceToProto(lr providers.LinkedResourceSchema) *proto.ActionSchema_LinkedResource {
145-
return &proto.ActionSchema_LinkedResource{
146-
TypeName: lr.TypeName,
147-
}
148-
}
149-
150-
func ProtoToLinkedResources(lrs []*proto.ActionSchema_LinkedResource) []providers.LinkedResourceSchema {
151-
linkedResources := make([]providers.LinkedResourceSchema, len(lrs))
152-
for i, lr := range lrs {
153-
linkedResources[i] = ProtoToLinkedResource(lr)
154-
}
155-
return linkedResources
156-
}
157-
158-
func LinkedResourcesToProto(lrs []providers.LinkedResourceSchema) []*proto.ActionSchema_LinkedResource {
159-
linkedResources := make([]*proto.ActionSchema_LinkedResource, len(lrs))
160-
for i, lr := range lrs {
161-
linkedResources[i] = LinkedResourceToProto(lr)
162-
}
163-
return linkedResources
164-
}
165-
166108
func ProtoToActionSchema(s *proto.ActionSchema) providers.ActionSchema {
167109
schema := providers.ActionSchema{
168110
ConfigSchema: ProtoToConfigSchema(s.Schema.Block),
169111
}
170112

171-
switch t := s.Type.(type) {
113+
switch s.Type.(type) {
172114
case *proto.ActionSchema_Unlinked_:
173115
schema.Unlinked = &providers.UnlinkedAction{}
174-
case *proto.ActionSchema_Lifecycle_:
175-
schema.Lifecycle = &providers.LifecycleAction{
176-
Executes: ProtoToExecutionOrder(t.Lifecycle.Executes),
177-
LinkedResource: ProtoToLinkedResource(t.Lifecycle.LinkedResource),
178-
}
179-
case *proto.ActionSchema_Linked_:
180-
schema.Linked = &providers.LinkedAction{
181-
LinkedResources: ProtoToLinkedResources(t.Linked.LinkedResources),
182-
}
183116
default:
184-
panic("Unknown Action Type, expected schema to contain either Unlinked, Liefecycle, or Linked")
117+
panic("Unknown Action Type, expected unlinked action")
185118
}
186119
return schema
187120
}

0 commit comments

Comments
 (0)