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.29.0-alpha.1.0.20250709165734-a8477a15f806
github.com/hashicorp/terraform-plugin-go v0.29.0-alpha.1.0.20250717133739-e33a5336fb19
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.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-go v0.29.0-alpha.1.0.20250717133739-e33a5336fb19 h1:P/ZVGEGXt9xSiLz+CrP/JzV2V8rtlE7994AX4jzcGB8=
github.com/hashicorp/terraform-plugin-go v0.29.0-alpha.1.0.20250717133739-e33a5336fb19/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
11 changes: 11 additions & 0 deletions internal/tf5testserver/tf5testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type TestServer struct {

ListResourceCalled map[string]bool

ValidateActionConfigCalled map[string]bool

PlanActionCalled map[string]bool

InvokeActionCalled map[string]bool
Expand Down Expand Up @@ -300,6 +302,15 @@ func (s *TestServer) ListResource(_ context.Context, req *tfprotov5.ListResource
return nil, nil
}

func (s *TestServer) ValidateActionConfig(_ context.Context, req *tfprotov5.ValidateActionConfigRequest) (*tfprotov5.ValidateActionConfigResponse, error) {
if s.ValidateActionConfigCalled == nil {
s.ValidateActionConfigCalled = make(map[string]bool)
}

s.ValidateActionConfigCalled[req.ActionType] = 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)
Expand Down
11 changes: 11 additions & 0 deletions internal/tf6testserver/tf6testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ type TestServer struct {

ListResourceCalled map[string]bool

ValidateActionConfigCalled map[string]bool

PlanActionCalled map[string]bool

InvokeActionCalled map[string]bool
Expand Down Expand Up @@ -300,6 +302,15 @@ func (s *TestServer) ListResource(_ context.Context, req *tfprotov6.ListResource
return nil, nil
}

func (s *TestServer) ValidateActionConfig(_ context.Context, req *tfprotov6.ValidateActionConfigRequest) (*tfprotov6.ValidateActionConfigResponse, error) {
if s.ValidateActionConfigCalled == nil {
s.ValidateActionConfigCalled = make(map[string]bool)
}

s.ValidateActionConfigCalled[req.ActionType] = 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)
Expand Down
21 changes: 21 additions & 0 deletions internal/tfprotov5tov6/tfprotov5tov6.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,27 @@ func LinkedResourceSchema(in *tfprotov5.LinkedResourceSchema) *tfprotov6.LinkedR
}
}

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

return &tfprotov6.ValidateActionConfigRequest{
Config: DynamicValue(in.Config),
ActionType: in.ActionType,
}
}

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

return &tfprotov6.ValidateActionConfigResponse{
Diagnostics: Diagnostics(in.Diagnostics),
}
}

func PlanActionRequest(in *tfprotov5.PlanActionRequest) *tfprotov6.PlanActionRequest {
if in == nil {
return nil
Expand Down
72 changes: 72 additions & 0 deletions internal/tfprotov5tov6/tfprotov5tov6_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3243,6 +3243,78 @@ func TestActionSchema(t *testing.T) {
}
}

func TestValidateActionConfigRequest(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
in *tfprotov5.ValidateActionConfigRequest
expected *tfprotov6.ValidateActionConfigRequest
}{
"nil": {
in: nil,
expected: nil,
},
"all-valid-fields": {
in: &tfprotov5.ValidateActionConfigRequest{
Config: &testTfprotov5DynamicValue,
ActionType: "test_action",
},
expected: &tfprotov6.ValidateActionConfigRequest{
Config: &testTfprotov6DynamicValue,
ActionType: "test_action",
},
},
}

for name, testCase := range testCases {

t.Run(name, func(t *testing.T) {
t.Parallel()

got := tfprotov5tov6.ValidateActionConfigRequest(testCase.in)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestValidateActionConfigResponse(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
in *tfprotov5.ValidateActionConfigResponse
expected *tfprotov6.ValidateActionConfigResponse
}{
"nil": {
in: nil,
expected: nil,
},
"all-valid-fields": {
in: &tfprotov5.ValidateActionConfigResponse{
Diagnostics: testTfprotov5Diagnostics,
},
expected: &tfprotov6.ValidateActionConfigResponse{
Diagnostics: testTfprotov6Diagnostics,
},
},
}

for name, testCase := range testCases {

t.Run(name, func(t *testing.T) {
t.Parallel()

got := tfprotov5tov6.ValidateActionConfigResponse(testCase.in)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestPlanActionRequest(t *testing.T) {
t.Parallel()

Expand Down
21 changes: 21 additions & 0 deletions internal/tfprotov6tov5/tfprotov6tov5.go
Original file line number Diff line number Diff line change
Expand Up @@ -1202,6 +1202,27 @@ func LinkedResourceSchema(in *tfprotov6.LinkedResourceSchema) *tfprotov5.LinkedR
}
}

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

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

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

return &tfprotov5.ValidateActionConfigResponse{
Diagnostics: Diagnostics(in.Diagnostics),
}
}

func PlanActionRequest(in *tfprotov6.PlanActionRequest) *tfprotov5.PlanActionRequest {
if in == nil {
return nil
Expand Down
72 changes: 72 additions & 0 deletions internal/tfprotov6tov5/tfprotov6tov5_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3613,6 +3613,78 @@ func TestActionSchema(t *testing.T) {
}
}

func TestValidateActionConfigRequest(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
in *tfprotov6.ValidateActionConfigRequest
expected *tfprotov5.ValidateActionConfigRequest
}{
"nil": {
in: nil,
expected: nil,
},
"all-valid-fields": {
in: &tfprotov6.ValidateActionConfigRequest{
Config: &testTfprotov6DynamicValue,
ActionType: "test_action",
},
expected: &tfprotov5.ValidateActionConfigRequest{
Config: &testTfprotov5DynamicValue,
ActionType: "test_action",
},
},
}

for name, testCase := range testCases {

t.Run(name, func(t *testing.T) {
t.Parallel()

got := tfprotov6tov5.ValidateActionConfigRequest(testCase.in)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestValidateActionConfigResponse(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
in *tfprotov6.ValidateActionConfigResponse
expected *tfprotov5.ValidateActionConfigResponse
}{
"nil": {
in: nil,
expected: nil,
},
"all-valid-fields": {
in: &tfprotov6.ValidateActionConfigResponse{
Diagnostics: testTfprotov6Diagnostics,
},
expected: &tfprotov5.ValidateActionConfigResponse{
Diagnostics: testTfprotov5Diagnostics,
},
},
}

for name, testCase := range testCases {

t.Run(name, func(t *testing.T) {
t.Parallel()

got := tfprotov6tov5.ValidateActionConfigResponse(testCase.in)

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestPlanActionRequest(t *testing.T) {
t.Parallel()

Expand Down
52 changes: 52 additions & 0 deletions tf5muxserver/mux_server_ValidateActionConfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package tf5muxserver

import (
"context"

"github.com/hashicorp/terraform-plugin-go/tfprotov5"

"github.com/hashicorp/terraform-plugin-mux/internal/logging"
)

func (s *muxServer) ValidateActionConfig(ctx context.Context, req *tfprotov5.ValidateActionConfigRequest) (*tfprotov5.ValidateActionConfigResponse, error) {
rpc := "ValidateActionTypeConfig"
ctx = logging.InitContext(ctx)
ctx = logging.RpcContext(ctx, rpc)

server, diags, err := s.getActionServer(ctx, req.ActionType)

if err != nil {
return nil, err
}

if diagnosticsHasError(diags) {
return &tfprotov5.ValidateActionConfigResponse{
Diagnostics: diags,
}, nil
}

// TODO: Remove and call server.ValidateActionConfig below directly once interface becomes required.
actionServer, ok := server.(tfprotov5.ActionServer)
if !ok {
resp := &tfprotov5.ValidateActionConfigResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "ValidateActionConfig Not Implemented",
Detail: "A ValidateActionConfig call was received by the provider, however the provider does not implement ValidateActionConfig. " +
"Either upgrade the provider to a version that implements ValidateActionConfig or this is a bug in Terraform that should be reported to the Terraform maintainers.",
},
},
}

return resp, nil
}

ctx = logging.Tfprotov5ProviderServerContext(ctx, server)
logging.MuxTrace(ctx, "calling downstream server")

return actionServer.ValidateActionConfig(ctx, req)
}
Loading