Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
module github.com/hashicorp/terraform-plugin-go

go 1.24
go 1.23.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the Go module was inadvertently bumped by [email protected], I'm reverting that change for the moment, so we can come back and bump the version along with the CI -> https://github.com/hashicorp/terraform-providers-devex-internal/issues/189


toolchain go1.24.1
toolchain go1.23.7

require (
github.com/google/go-cmp v0.7.0
github.com/hashicorp/go-hclog v1.6.3
github.com/hashicorp/go-plugin v1.7.0
github.com/hashicorp/go-plugin v1.6.3
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/hashicorp/terraform-registry-address v0.4.0
Expand Down
15 changes: 8 additions & 7 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/bufbuild/protocompile v0.14.1 h1:iA73zAf/fyljNjQKwYzUHD6AD4R8KMasmwa/FBatYVw=
github.com/bufbuild/protocompile v0.14.1/go.mod h1:ppVdAIhbr2H8asPk6k4pY7t9zB1OU5DoEw9xY/FUi1c=
github.com/bufbuild/protocompile v0.4.0 h1:LbFKd2XowZvQ/kajzguUp2DC9UEIQhIq77fZZlaQsNA=
github.com/bufbuild/protocompile v0.4.0/go.mod h1:3v93+mbWn/v3xzN+31nwkJfrEpAUwp+BagBSZWx+TP8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -17,8 +17,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
github.com/hashicorp/go-plugin v1.7.0 h1:YghfQH/0QmPNc/AZMTFE3ac8fipZyZECHdDPshfk+mA=
github.com/hashicorp/go-plugin v1.7.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8=
github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0UUrwg=
github.com/hashicorp/go-plugin v1.6.3/go.mod h1:MRobyh+Wc/nYy1V4KAXUiYfzxoYhs7V1mlH1Z7iY2h0=
github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
Expand All @@ -29,8 +29,8 @@ github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8=
github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns=
github.com/jhump/protoreflect v1.17.0 h1:qOEr613fac2lOuTgWN4tPAtLL7fUSbuJL5X5XumQh94=
github.com/jhump/protoreflect v1.17.0/go.mod h1:h9+vUUL38jiBzck8ck+6G/aeMX8Z4QUY/NiJPwPNi+8=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-colorable v0.1.12 h1:jF+Du6AlPIjs2BiUiQlKOX0rt3SujHxPnksPKZbaA40=
github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
Expand All @@ -45,8 +45,9 @@ github.com/oklog/run v1.1.0/go.mod h1:sVPdnTZT1zYwAJeCMu2Th4T21pA3FPOQRfWjQlk7DV
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.2 h1:4jaiDzPyXQvSd7D0EjG45355tLlV3VOECpq10pLC+8s=
github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY=
github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
Expand Down
46 changes: 26 additions & 20 deletions tfprotov5/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ type ValidateActionConfigRequest struct {
// from knowing the value at request time. Any attributes not directly
// set in the configuration will be null.
Config *DynamicValue

// LinkedResources contains the configuration data of the managed resource types that are linked to this action.
//
// - If the action schema type is Unlinked, this field will be empty.
LinkedResources []*LinkedResourceConfig
}

// LinkedResourceConfig represents linked resource config data used in the ValidateActionConfig RPC.
type LinkedResourceConfig struct {
// TypeName is the type of linked resource Terraform is validating.
TypeName string

// Config is the configuration the user supplied for the linked resource. See
// the documentation on `DynamicValue` for more information about
// safely accessing the configuration.
//
// The configuration is represented as a tftypes.Object, with each
// attribute and nested block getting its own key and value.
//
// This configuration may contain unknown values if a user uses
// interpolation or other functionality that would prevent Terraform
// from knowing the value at request time. Any attributes not directly
// set in the configuration will be null.
Config *DynamicValue
}

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

// Config is the configuration the user supplied for the action. See
Expand Down Expand Up @@ -128,9 +145,7 @@ type ProposedLinkedResource struct {
type PlanActionResponse struct {
// LinkedResources contains the provider modified data of the managed resource types that are linked to this action.
//
// For Lifecycle actions, the provider may only change computed-only attributes.
//
// For Linked actions, the provider may change any attributes as long as it adheres to the resource schema.
// 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.
LinkedResources []*PlannedLinkedResource

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

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

// Diagnostics report errors or warnings related to invoking an action.
Expand Down
77 changes: 3 additions & 74 deletions tfprotov5/action_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,97 +10,26 @@ type ActionSchema struct {
Schema *Schema

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

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

var (
_ ActionSchemaType = UnlinkedActionSchemaType{}
_ ActionSchemaType = LifecycleActionSchemaType{}
_ ActionSchemaType = LinkedActionSchemaType{}
)

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

func (a UnlinkedActionSchemaType) isActionSchemaType() {}

// LifecycleActionSchemaType represents a lifecycle action, which can cause changes to exactly one resource state,
// which is the linked resource.
type LifecycleActionSchemaType struct {
// Executes defines when the lifecycle action must be executed in relation to the linked resource, either before
// or after the linked resource's plan/apply.
Executes LifecycleExecutionOrder

// LinkedResource is the managed resource type that this action can make state changes to.
// This linked resource is currently restricted to be defined in the same provider as the action is defined.
LinkedResource *LinkedResourceSchema
}

func (a LifecycleActionSchemaType) isActionSchemaType() {}

const (
// LifecycleExecutionOrderInvalid is used to indicate an invalid `LifecycleExecutionOrder`.
// Provider developers should not use it.
LifecycleExecutionOrderInvalid LifecycleExecutionOrder = 0

// LifecycleExecutionOrderBefore is used to indicate that the action must be invoked before it's
// linked resource's plan/apply.
LifecycleExecutionOrderBefore LifecycleExecutionOrder = 1

// LifecycleExecutionOrderAfter is used to indicate that the action must be invoked after it's
// linked resource's plan/apply.
LifecycleExecutionOrderAfter LifecycleExecutionOrder = 2
)

// LifecycleExecutionOrder is an enum that represents when an action is invoked relative to it's linked resource.
type LifecycleExecutionOrder int32

func (l LifecycleExecutionOrder) String() string {
switch l {
case 0:
return "INVALID"
case 1:
return "BEFORE"
case 2:
return "AFTER"
case 3:
}
return "UNKNOWN"
}

// LinkedResourceSchema represents information about the schema of a linked resource, which is used by an action schema to describe to Terraform the
// resource types that an action is allowed to change the state of. Linked resources are currently restricted to be defined in the same provider
// as the action is defined.
//
// LinkedResourceSchema does not contain the entire schema definition of the linked resource, which must be obtained by the provider in order to
// decode the linked resource plan/state/identity protocol data during PlanAction and InvokeAction.
type LinkedResourceSchema struct {
// 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
// the provider shortname and an underscore.
TypeName string

// Description is a human-readable description of the linked resource.
Description string
}

// LinkedActionSchemaType represents a linked action, which can cause changes to one or more resource states.
type LinkedActionSchemaType struct {
// LinkedResources are the managed resource types that this action can make state changes to.
// These linked resources are currently restricted to be defined in the same provider as the action is defined.
LinkedResources []*LinkedResourceSchema
}

func (a LinkedActionSchemaType) isActionSchemaType() {}
18 changes: 16 additions & 2 deletions tfprotov5/internal/fromproto/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,23 @@ func ValidateActionConfigRequest(in *tfplugin5.ValidateActionConfig_Request) *tf
}

return &tfprotov5.ValidateActionConfigRequest{
ActionType: in.ActionType,
Config: DynamicValue(in.Config),
ActionType: in.ActionType,
Config: DynamicValue(in.Config),
LinkedResources: LinkedResourceConfigs(in.LinkedResources),
}
}

func LinkedResourceConfigs(in []*tfplugin5.LinkedResourceConfig) []*tfprotov5.LinkedResourceConfig {
resp := make([]*tfprotov5.LinkedResourceConfig, 0, len(in))

for _, inLinkedResource := range in {
resp = append(resp, &tfprotov5.LinkedResourceConfig{
TypeName: inLinkedResource.TypeName,
Config: DynamicValue(inLinkedResource.Config),
})
}

return resp
}

func PlanActionRequest(in *tfplugin5.PlanAction_Request) *tfprotov5.PlanActionRequest {
Expand Down
30 changes: 26 additions & 4 deletions tfprotov5/internal/fromproto/actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,45 @@ func TestValidateActionConfigRequest(t *testing.T) {
expected: nil,
},
"zero": {
in: &tfplugin5.ValidateActionConfig_Request{},
expected: &tfprotov5.ValidateActionConfigRequest{},
in: &tfplugin5.ValidateActionConfig_Request{},
expected: &tfprotov5.ValidateActionConfigRequest{
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
},
},
"Config": {
in: &tfplugin5.ValidateActionConfig_Request{
Config: testTfplugin5DynamicValue(),
},
expected: &tfprotov5.ValidateActionConfigRequest{
Config: testTfprotov5DynamicValue(),
Config: testTfprotov5DynamicValue(),
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
},
},
"ActionType": {
in: &tfplugin5.ValidateActionConfig_Request{
ActionType: "test",
},
expected: &tfprotov5.ValidateActionConfigRequest{
ActionType: "test",
ActionType: "test",
LinkedResources: []*tfprotov5.LinkedResourceConfig{},
},
},
"LinkedResources": {
in: &tfplugin5.ValidateActionConfig_Request{
LinkedResources: []*tfplugin5.LinkedResourceConfig{
{
TypeName: "test_linked",
Config: testTfplugin5DynamicValue(),
},
},
},
expected: &tfprotov5.ValidateActionConfigRequest{
LinkedResources: []*tfprotov5.LinkedResourceConfig{
{
TypeName: "test_linked",
Config: testTfprotov5DynamicValue(),
},
},
},
},
}
Expand Down
Loading
Loading