Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
9ec6758
go mod
austinvalle Jul 9, 2025
5eeac4c
generate RPC methods
austinvalle Jul 9, 2025
bf10880
protov5 and fwserver impl
austinvalle Jul 9, 2025
3c21a45
protov6 copy
austinvalle Jul 9, 2025
61eadc9
add initial schema attributes and unlinked schema
austinvalle Jul 10, 2025
0e5df9c
implement unlinked schemas, some attributes, and the rpcs
austinvalle Jul 10, 2025
32b2083
the rest of the tests
austinvalle Jul 10, 2025
dcd6748
Merge branch 'main' into av/action-schema
austinvalle Jul 11, 2025
3a1048c
fix double import
austinvalle Jul 11, 2025
7e5fd9f
external interfaces for plan / configure
austinvalle Jul 11, 2025
95e7673
plan action impl and fwserver tests
austinvalle Jul 14, 2025
5d5960a
proto server tests
austinvalle Jul 14, 2025
7ec37c2
from/to plan tests
austinvalle Jul 14, 2025
e43f576
from invoke
austinvalle Jul 14, 2025
2f08b28
add invoke impl with just completed event
austinvalle Jul 14, 2025
261ef7d
fix map access in unit tests
austinvalle Jul 14, 2025
8fdf71d
Merge branch 'main' into av/unlinked-action-impl
austinvalle Jul 15, 2025
47f9631
implementation of sending progress events
austinvalle Jul 15, 2025
119f4c5
mention progress events
austinvalle Jul 15, 2025
98f7232
comments
austinvalle Jul 15, 2025
ea2deb8
all attributes (primitive, collection, nested)
austinvalle Jul 15, 2025
21ffee7
add blocks and docs
austinvalle Jul 15, 2025
1503be5
update all commented out custom type tests
austinvalle Jul 16, 2025
68a38e4
Merge branch 'main' into av/all-schemas-types
austinvalle Jul 16, 2025
43f5717
go mod
austinvalle Jul 17, 2025
2f341cb
external interface
austinvalle Jul 17, 2025
8361ea6
test provider
austinvalle Jul 17, 2025
3789aad
add validators to schemas
austinvalle Jul 17, 2025
6d3cff2
fwserver
austinvalle Jul 17, 2025
e4bcbbf
proto5 and proto6 impl
austinvalle Jul 17, 2025
8dd8241
Merge branch 'main' into av/action-validation-rpc
austinvalle Jul 17, 2025
dcde327
Merge branch 'main' into av/action-validation-rpc
austinvalle Jul 28, 2025
f90b4f1
update config validator comments
austinvalle Jul 28, 2025
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
30 changes: 30 additions & 0 deletions action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,33 @@ type ActionWithModifyPlan interface {
// diagnostics to practitioners, such as validation errors.
ModifyPlan(context.Context, ModifyPlanRequest, *ModifyPlanResponse)
}

// ActionWithConfigValidators is an interface type that extends Action to include declarative validations.
//
// Declaring validation using this methodology simplifies implementation of
// reusable functionality. These also include descriptions, which can be used
// for automating documentation.
//
// Validation will include ConfigValidators and ValidateConfig, if both are
// implemented, in addition to any Attribute or Type validation.
type ActionWithConfigValidators interface {
Action

// ConfigValidators returns a list of functions which will all be performed during validation.
ConfigValidators(context.Context) []ConfigValidator
}

// ActionWithValidateConfig is an interface type that extends Action to include imperative validation.
//
// Declaring validation using this methodology simplifies one-off
// functionality that typically applies to a single action. Any documentation
// of this functionality must be manually added into schema descriptions.
//
// Validation will include ConfigValidators and ValidateConfig, if both are
// implemented, in addition to any Attribute or Type validation.
type ActionWithValidateConfig interface {
Action

// ValidateConfig performs the validation.
ValidateConfig(context.Context, ValidateConfigRequest, *ValidateConfigResponse)
}
27 changes: 27 additions & 0 deletions action/config_validator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0

package action

import "context"

// ConfigValidator describes reusable Action configuration validation functionality.
type ConfigValidator interface {
// Description describes the validation in plain text formatting.
//
// This information may be automatically added to action plain text
// descriptions by external tooling.
Description(context.Context) string

// MarkdownDescription describes the validation in Markdown formatting.
//
// This information may be automatically added to action Markdown
// descriptions by external tooling.
MarkdownDescription(context.Context) string

// ValidateAction performs the validation.
//
// This method name is separate from ConfigValidators in resource and other packages in
// order to allow generic validators.
ValidateAction(context.Context, ValidateConfigRequest, *ValidateConfigResponse)
}
22 changes: 21 additions & 1 deletion action/schema/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// Ensure the implementation satisfies the desired interfaces.
var (
_ Attribute = BoolAttribute{}
_ Attribute = BoolAttribute{}
_ fwxschema.AttributeWithBoolValidators = BoolAttribute{}
)

// BoolAttribute represents a schema attribute that is a boolean. When
Expand Down Expand Up @@ -89,6 +92,18 @@ type BoolAttribute struct {
// - https://github.com/hashicorp/terraform/issues/7569
//
DeprecationMessage string

// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Bool
}

// ApplyTerraform5AttributePathStep always returns an error as it is not
Expand Down Expand Up @@ -167,3 +182,8 @@ func (a BoolAttribute) IsRequiredForImport() bool {
func (a BoolAttribute) IsOptionalForImport() bool {
return false
}

// BoolValidators returns the Validators field value.
func (a BoolAttribute) BoolValidators() []validator.Bool {
return a.Validators
}
33 changes: 33 additions & 0 deletions action/schema/bool_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -435,3 +436,35 @@ func TestBoolAttributeIsOptionalForImport(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.BoolAttribute
expected []validator.Bool
}{
"no-validators": {
attribute: schema.BoolAttribute{},
expected: nil,
},
"validators": {
attribute: schema.BoolAttribute{
Validators: []validator.Bool{},
},
expected: []validator.Bool{},
},
}

for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.BoolValidators()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}
22 changes: 21 additions & 1 deletion action/schema/dynamic_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// Ensure the implementation satisifies the desired interfaces.
var (
_ Attribute = DynamicAttribute{}
_ Attribute = DynamicAttribute{}
_ fwxschema.AttributeWithDynamicValidators = DynamicAttribute{}
)

// DynamicAttribute represents a schema attribute that is a dynamic, rather
Expand Down Expand Up @@ -90,6 +93,18 @@ type DynamicAttribute struct {
// - https://github.com/hashicorp/terraform/issues/7569
//
DeprecationMessage string

// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Dynamic
}

// ApplyTerraform5AttributePathStep always returns an error as it is not
Expand Down Expand Up @@ -168,3 +183,8 @@ func (a DynamicAttribute) IsRequiredForImport() bool {
func (a DynamicAttribute) IsOptionalForImport() bool {
return false
}

// DynamicValidators returns the Validators field value.
func (a DynamicAttribute) DynamicValidators() []validator.Dynamic {
return a.Validators
}
33 changes: 33 additions & 0 deletions action/schema/dynamic_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
Expand Down Expand Up @@ -434,3 +435,35 @@ func TestDynamicAttributeIsOptionalForImport(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.DynamicAttribute
expected []validator.Dynamic
}{
"no-validators": {
attribute: schema.DynamicAttribute{},
expected: nil,
},
"validators": {
attribute: schema.DynamicAttribute{
Validators: []validator.Dynamic{},
},
expected: []validator.Dynamic{},
},
}

for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.DynamicValidators()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}
22 changes: 21 additions & 1 deletion action/schema/float32_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// Ensure the implementation satisifies the desired interfaces.
var (
_ Attribute = Float32Attribute{}
_ Attribute = Float32Attribute{}
_ fwxschema.AttributeWithFloat32Validators = Float32Attribute{}
)

// Float32Attribute represents a schema attribute that is a 32-bit floating
Expand Down Expand Up @@ -92,6 +95,18 @@ type Float32Attribute struct {
// - https://github.com/hashicorp/terraform/issues/7569
//
DeprecationMessage string

// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Float32
}

// ApplyTerraform5AttributePathStep always returns an error as it is not
Expand Down Expand Up @@ -170,3 +185,8 @@ func (a Float32Attribute) IsRequiredForImport() bool {
func (a Float32Attribute) IsOptionalForImport() bool {
return false
}

// Float32Validators returns the Validators field value.
func (a Float32Attribute) Float32Validators() []validator.Float32 {
return a.Validators
}
33 changes: 33 additions & 0 deletions action/schema/float32_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -435,3 +436,35 @@ func TestFloat32AttributeIsOptionalForImport(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.Float32Attribute
expected []validator.Float32
}{
"no-validators": {
attribute: schema.Float32Attribute{},
expected: nil,
},
"validators": {
attribute: schema.Float32Attribute{
Validators: []validator.Float32{},
},
expected: []validator.Float32{},
},
}

for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.Float32Validators()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}
22 changes: 21 additions & 1 deletion action/schema/float64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ import (

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema/fwxschema"
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

// Ensure the implementation satisifies the desired interfaces.
var (
_ Attribute = Float64Attribute{}
_ Attribute = Float64Attribute{}
_ fwxschema.AttributeWithFloat64Validators = Float64Attribute{}
)

// Float64Attribute represents a schema attribute that is a 64-bit floating
Expand Down Expand Up @@ -92,6 +95,18 @@ type Float64Attribute struct {
// - https://github.com/hashicorp/terraform/issues/7569
//
DeprecationMessage string

// Validators define value validation functionality for the attribute. All
// elements of the slice of AttributeValidator are run, regardless of any
// previous error diagnostics.
//
// Many common use case validators can be found in the
// github.com/hashicorp/terraform-plugin-framework-validators Go module.
//
// If the Type field points to a custom type that implements the
// xattr.TypeWithValidate interface, the validators defined in this field
// are run in addition to the validation defined by the type.
Validators []validator.Float64
}

// ApplyTerraform5AttributePathStep always returns an error as it is not
Expand Down Expand Up @@ -170,3 +185,8 @@ func (a Float64Attribute) IsRequiredForImport() bool {
func (a Float64Attribute) IsOptionalForImport() bool {
return false
}

// Float64Validators returns the Validators field value.
func (a Float64Attribute) Float64Validators() []validator.Float64 {
return a.Validators
}
Loading
Loading