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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ toolchain go1.23.7

require (
github.com/google/go-cmp v0.7.0
github.com/hashicorp/terraform-plugin-go v0.28.1-0.20250616135123-a19df43120ea
github.com/hashicorp/terraform-plugin-go v0.29.0-alpha.1.0.20250709165734-a8477a15f806
github.com/hashicorp/terraform-plugin-log v0.9.0
google.golang.org/grpc v1.73.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/hashicorp/go-plugin v1.6.3 h1:xgHB+ZUSYeuJi96WtxEjzi23uh7YQpznjGh0U0U
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-go v0.28.1-0.20250616135123-a19df43120ea h1:U9EAAeQtszGlR7mDS7rY77B/a4/XiMDB8HfAtqLAuAQ=
github.com/hashicorp/terraform-plugin-go v0.28.1-0.20250616135123-a19df43120ea/go.mod h1:hL//wLEfYo0YVt0TC/VLzia/ADQQto3HEm4/jX2gkdY=
github.com/hashicorp/terraform-plugin-go v0.29.0-alpha.1.0.20250709165734-a8477a15f806 h1:i3kA1sT/Fk8Ex+VVKdjf9sFOPwS7w3Q73pfbnxKwdjg=
github.com/hashicorp/terraform-plugin-go v0.29.0-alpha.1.0.20250709165734-a8477a15f806/go.mod h1:hL//wLEfYo0YVt0TC/VLzia/ADQQto3HEm4/jX2gkdY=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/hashicorp/terraform-registry-address v0.3.0 h1:HMpK3nqaGFPS9VmgRXrJL/dzHNdheGVKk5k7VlFxzCo=
Expand Down
22 changes: 22 additions & 0 deletions internal/tf5testserver/tf5testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type TestServer struct {
ValidateListResourceConfigCalled map[string]bool

ListResourceCalled map[string]bool

PlanActionCalled map[string]bool

InvokeActionCalled map[string]bool
}

func (s *TestServer) ProviderServer() tfprotov5.ProviderServer {
Expand Down Expand Up @@ -295,3 +299,21 @@ func (s *TestServer) ListResource(_ context.Context, req *tfprotov5.ListResource
s.ListResourceCalled[req.TypeName] = true
return nil, nil
}

func (s *TestServer) PlanAction(ctx context.Context, req *tfprotov5.PlanActionRequest) (*tfprotov5.PlanActionResponse, error) {
if s.PlanActionCalled == nil {
s.PlanActionCalled = make(map[string]bool)
}

s.PlanActionCalled[req.ActionType] = true
return nil, nil
}

func (s *TestServer) InvokeAction(ctx context.Context, req *tfprotov5.InvokeActionRequest) (*tfprotov5.InvokeActionServerStream, error) {
if s.InvokeActionCalled == nil {
s.InvokeActionCalled = make(map[string]bool)
}

s.InvokeActionCalled[req.ActionType] = true
return nil, nil
}
22 changes: 22 additions & 0 deletions internal/tf6testserver/tf6testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ type TestServer struct {
ValidateListResourceConfigCalled map[string]bool

ListResourceCalled map[string]bool

PlanActionCalled map[string]bool

InvokeActionCalled map[string]bool
}

func (s *TestServer) ProviderServer() tfprotov6.ProviderServer {
Expand Down Expand Up @@ -295,3 +299,21 @@ func (s *TestServer) ListResource(_ context.Context, req *tfprotov6.ListResource
s.ListResourceCalled[req.TypeName] = true
return nil, nil
}

func (s *TestServer) PlanAction(ctx context.Context, req *tfprotov6.PlanActionRequest) (*tfprotov6.PlanActionResponse, error) {
if s.PlanActionCalled == nil {
s.PlanActionCalled = make(map[string]bool)
}

s.PlanActionCalled[req.ActionType] = true
return nil, nil
}

func (s *TestServer) InvokeAction(ctx context.Context, req *tfprotov6.InvokeActionRequest) (*tfprotov6.InvokeActionServerStream, error) {
if s.InvokeActionCalled == nil {
s.InvokeActionCalled = make(map[string]bool)
}

s.InvokeActionCalled[req.ActionType] = true
return nil, nil
}
255 changes: 255 additions & 0 deletions internal/tfprotov5tov6/tfprotov5tov6.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package tfprotov5tov6

import (
"fmt"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
)
Expand Down Expand Up @@ -301,6 +303,7 @@ func GetMetadataResponse(in *tfprotov5.GetMetadataResponse) *tfprotov6.GetMetada
}

resp := &tfprotov6.GetMetadataResponse{
Actions: make([]tfprotov6.ActionMetadata, 0, len(in.Actions)),
DataSources: make([]tfprotov6.DataSourceMetadata, 0, len(in.DataSources)),
Diagnostics: Diagnostics(in.Diagnostics),
EphemeralResources: make([]tfprotov6.EphemeralResourceMetadata, 0, len(in.Resources)),
Expand Down Expand Up @@ -330,6 +333,10 @@ func GetMetadataResponse(in *tfprotov5.GetMetadataResponse) *tfprotov6.GetMetada
resp.Resources = append(resp.Resources, ResourceMetadata(resource))
}

for _, action := range in.Actions {
resp.Actions = append(resp.Actions, ActionMetadata(action))
}

return resp
}

Expand Down Expand Up @@ -376,7 +383,14 @@ func GetProviderSchemaResponse(in *tfprotov5.GetProviderSchemaResponse) *tfproto
resourceSchemas[k] = Schema(v)
}

actionSchemas := make(map[string]*tfprotov6.ActionSchema, len(in.ActionSchemas))

for k, v := range in.ActionSchemas {
actionSchemas[k] = ActionSchema(v)
}

return &tfprotov6.GetProviderSchemaResponse{
ActionSchemas: actionSchemas,
DataSourceSchemas: dataSourceSchemas,
Diagnostics: Diagnostics(in.Diagnostics),
EphemeralResourceSchemas: ephemeralResourceSchemas,
Expand Down Expand Up @@ -1052,3 +1066,244 @@ func ListResourceResult(in tfprotov5.ListResourceResult) tfprotov6.ListResourceR
Diagnostics: Diagnostics(in.Diagnostics),
}
}

func ActionMetadata(in tfprotov5.ActionMetadata) tfprotov6.ActionMetadata {
return tfprotov6.ActionMetadata{
TypeName: in.TypeName,
}
}

func ActionSchema(in *tfprotov5.ActionSchema) *tfprotov6.ActionSchema {
if in == nil {
return nil
}

actionSchema := &tfprotov6.ActionSchema{
Schema: Schema(in.Schema),
}

switch actionSchemaType := in.Type.(type) {
case tfprotov5.UnlinkedActionSchemaType:
actionSchema.Type = tfprotov6.UnlinkedActionSchemaType{}
case tfprotov5.LifecycleActionSchemaType:
actionSchema.Type = tfprotov6.LifecycleActionSchemaType{
Executes: tfprotov6.LifecycleExecutionOrder(actionSchemaType.Executes),
LinkedResource: LinkedResourceSchema(actionSchemaType.LinkedResource),
}
case tfprotov5.LinkedActionSchemaType:
actionSchema.Type = tfprotov6.LinkedActionSchemaType{
LinkedResources: LinkedResourceSchemas(actionSchemaType.LinkedResources),
}
default:
// It is not currently possible to create tfprotov5.ActionSchemaType
// implementations outside the terraform-plugin-go module. If this panic was reached,
// it implies that a new event type was introduced and needs to be implemented
// as a new case above.
panic(fmt.Sprintf("unimplemented tfprotov5.ActionSchemaType type: %T", in.Type))
}

return actionSchema
}

func LinkedResourceSchemas(in []*tfprotov5.LinkedResourceSchema) []*tfprotov6.LinkedResourceSchema {
schemas := make([]*tfprotov6.LinkedResourceSchema, 0, len(in))

for _, schema := range in {
schemas = append(schemas, LinkedResourceSchema(schema))
}

return schemas
}

func LinkedResourceSchema(in *tfprotov5.LinkedResourceSchema) *tfprotov6.LinkedResourceSchema {
if in == nil {
return nil
}

return &tfprotov6.LinkedResourceSchema{
TypeName: in.TypeName,
Description: in.Description,
}
}

func PlanActionRequest(in *tfprotov5.PlanActionRequest) *tfprotov6.PlanActionRequest {
if in == nil {
return nil
}

return &tfprotov6.PlanActionRequest{
ActionType: in.ActionType,
LinkedResources: ProposedLinkedResources(in.LinkedResources),
Config: DynamicValue(in.Config),
ClientCapabilities: PlanActionClientCapabilities(in.ClientCapabilities),
}
}

func ProposedLinkedResources(in []*tfprotov5.ProposedLinkedResource) []*tfprotov6.ProposedLinkedResource {
if in == nil {
return nil
}

linkedResources := make([]*tfprotov6.ProposedLinkedResource, 0, len(in))

for _, inLinkedResource := range in {
if inLinkedResource == nil {
linkedResources = append(linkedResources, nil)
continue
}

linkedResources = append(linkedResources, &tfprotov6.ProposedLinkedResource{
PriorState: DynamicValue(inLinkedResource.PriorState),
PlannedState: DynamicValue(inLinkedResource.PlannedState),
Config: DynamicValue(inLinkedResource.Config),
PriorIdentity: ResourceIdentityData(inLinkedResource.PriorIdentity),
})
}

return linkedResources
}

func PlanActionClientCapabilities(in *tfprotov5.PlanActionClientCapabilities) *tfprotov6.PlanActionClientCapabilities {
if in == nil {
return nil
}

resp := &tfprotov6.PlanActionClientCapabilities{
DeferralAllowed: in.DeferralAllowed,
}

return resp
}

func PlanActionResponse(in *tfprotov5.PlanActionResponse) *tfprotov6.PlanActionResponse {
if in == nil {
return nil
}

return &tfprotov6.PlanActionResponse{
LinkedResources: PlannedLinkedResources(in.LinkedResources),
Diagnostics: Diagnostics(in.Diagnostics),
Deferred: Deferred(in.Deferred),
}
}

func PlannedLinkedResources(in []*tfprotov5.PlannedLinkedResource) []*tfprotov6.PlannedLinkedResource {
if in == nil {
return nil
}

linkedResources := make([]*tfprotov6.PlannedLinkedResource, 0, len(in))

for _, inLinkedResource := range in {
if inLinkedResource == nil {
linkedResources = append(linkedResources, nil)
continue
}

linkedResources = append(linkedResources, &tfprotov6.PlannedLinkedResource{
PlannedState: DynamicValue(inLinkedResource.PlannedState),
PlannedIdentity: ResourceIdentityData(inLinkedResource.PlannedIdentity),
})
}

return linkedResources
}

func InvokeActionRequest(in *tfprotov5.InvokeActionRequest) *tfprotov6.InvokeActionRequest {
if in == nil {
return nil
}

return &tfprotov6.InvokeActionRequest{
ActionType: in.ActionType,
LinkedResources: InvokeLinkedResources(in.LinkedResources),
Config: DynamicValue(in.Config),
}
}

func InvokeLinkedResources(in []*tfprotov5.InvokeLinkedResource) []*tfprotov6.InvokeLinkedResource {
if in == nil {
return nil
}

linkedResources := make([]*tfprotov6.InvokeLinkedResource, 0, len(in))

for _, inLinkedResource := range in {
if inLinkedResource == nil {
linkedResources = append(linkedResources, nil)
continue
}

linkedResources = append(linkedResources, &tfprotov6.InvokeLinkedResource{
PriorState: DynamicValue(inLinkedResource.PriorState),
PlannedState: DynamicValue(inLinkedResource.PlannedState),
Config: DynamicValue(inLinkedResource.Config),
PlannedIdentity: ResourceIdentityData(inLinkedResource.PlannedIdentity),
})
}

return linkedResources
}

func InvokeActionServerStream(in *tfprotov5.InvokeActionServerStream) *tfprotov6.InvokeActionServerStream {
if in == nil {
return nil
}

return &tfprotov6.InvokeActionServerStream{
Events: func(yield func(tfprotov6.InvokeActionEvent) bool) {
for res := range in.Events {
if !yield(InvokeActionEvent(res)) {
break
}
}
},
}
}

func InvokeActionEvent(in tfprotov5.InvokeActionEvent) tfprotov6.InvokeActionEvent {
switch event := (in.Type).(type) {
case tfprotov5.ProgressInvokeActionEventType:
return tfprotov6.InvokeActionEvent{
Type: tfprotov6.ProgressInvokeActionEventType{
Message: event.Message,
},
}
case tfprotov5.CompletedInvokeActionEventType:
return tfprotov6.InvokeActionEvent{
Type: tfprotov6.CompletedInvokeActionEventType{
LinkedResources: NewLinkedResources(event.LinkedResources),
Diagnostics: Diagnostics(event.Diagnostics),
},
}
}

// It is not currently possible to create tfprotov5.InvokeActionEventType
// implementations outside the terraform-plugin-go module. If this panic was reached,
// it implies that a new event type was introduced and needs to be implemented
// as a new case above.
panic(fmt.Sprintf("unimplemented tfprotov5.InvokeActionEventType type: %T", in.Type))
}

func NewLinkedResources(in []*tfprotov5.NewLinkedResource) []*tfprotov6.NewLinkedResource {
if in == nil {
return nil
}

linkedResources := make([]*tfprotov6.NewLinkedResource, 0, len(in))

for _, inLinkedResource := range in {
if inLinkedResource == nil {
linkedResources = append(linkedResources, nil)
continue
}

linkedResources = append(linkedResources, &tfprotov6.NewLinkedResource{
NewState: DynamicValue(inLinkedResource.NewState),
NewIdentity: ResourceIdentityData(inLinkedResource.NewIdentity),
RequiresReplace: inLinkedResource.RequiresReplace,
})
}

return linkedResources
}
Loading