Skip to content

Commit 28f4804

Browse files
authored
resource/schema/planmodifier: New type-specific plan modifiers package (#557)
Reference: #132 As part of upcoming effort to split schema functionality into the `datasource`, `provider`, and `resource` packages, there are some improvements that will land in the new implementations rather than breaking the existing `tfsdk` package schema functionality. One area which has caused developer burden is that "attribute" plan modifiers, currently implementations of the `tfsdk.AttributePlanModifier` interface, receive generic `attr.Value` as the configuration, plan, and state values to perform modification logic. This means that implementors must currently handle validating and converting the value into the concrete type they expect. The upcoming split schemas handling will introduce separate attribute/block types that will enable to framework to strongly type validators and other future schema enhancements. This change prepares the exported interfaces and internal validation logic for those enhancements. Plan modifiers are only available for resources, so this package is explicitly placed under that structure to further reduce usage confusion.
1 parent 1dfcd30 commit 28f4804

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+15432
-516
lines changed

.changelog/557.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:feature
2+
resource/schema/planmodifier: New package which contains type-specific schema plan modifier interfaces
3+
```

internal/fwschema/fwxschema/attribute_plan_modification.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fwxschema
22

33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
56
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
67
)
78

@@ -17,3 +18,84 @@ type AttributeWithPlanModifiers interface {
1718
// the tfsdk.Attribute field name.
1819
GetPlanModifiers() tfsdk.AttributePlanModifiers
1920
}
21+
22+
// AttributeWithBoolPlanModifiers is an optional interface on Attribute which
23+
// enables Bool plan modifier support.
24+
type AttributeWithBoolPlanModifiers interface {
25+
fwschema.Attribute
26+
27+
// BoolPlanModifiers should return a list of Bool plan modifiers.
28+
BoolPlanModifiers() []planmodifier.Bool
29+
}
30+
31+
// AttributeWithFloat64PlanModifiers is an optional interface on Attribute which
32+
// enables Float64 plan modifier support.
33+
type AttributeWithFloat64PlanModifiers interface {
34+
fwschema.Attribute
35+
36+
// Float64PlanModifiers should return a list of Float64 plan modifiers.
37+
Float64PlanModifiers() []planmodifier.Float64
38+
}
39+
40+
// AttributeWithInt64PlanModifiers is an optional interface on Attribute which
41+
// enables Int64 plan modifier support.
42+
type AttributeWithInt64PlanModifiers interface {
43+
fwschema.Attribute
44+
45+
// Int64PlanModifiers should return a list of Int64 plan modifiers.
46+
Int64PlanModifiers() []planmodifier.Int64
47+
}
48+
49+
// AttributeWithListPlanModifiers is an optional interface on Attribute which
50+
// enables List plan modifier support.
51+
type AttributeWithListPlanModifiers interface {
52+
fwschema.Attribute
53+
54+
// ListPlanModifiers should return a list of List plan modifiers.
55+
ListPlanModifiers() []planmodifier.List
56+
}
57+
58+
// AttributeWithMapPlanModifiers is an optional interface on Attribute which
59+
// enables Map plan modifier support.
60+
type AttributeWithMapPlanModifiers interface {
61+
fwschema.Attribute
62+
63+
// MapPlanModifiers should return a list of Map plan modifiers.
64+
MapPlanModifiers() []planmodifier.Map
65+
}
66+
67+
// AttributeWithNumberPlanModifiers is an optional interface on Attribute which
68+
// enables Number plan modifier support.
69+
type AttributeWithNumberPlanModifiers interface {
70+
fwschema.Attribute
71+
72+
// NumberPlanModifiers should return a list of Number plan modifiers.
73+
NumberPlanModifiers() []planmodifier.Number
74+
}
75+
76+
// AttributeWithObjectPlanModifiers is an optional interface on Attribute which
77+
// enables Object plan modifier support.
78+
type AttributeWithObjectPlanModifiers interface {
79+
fwschema.Attribute
80+
81+
// ObjectPlanModifiers should return a list of Object plan modifiers.
82+
ObjectPlanModifiers() []planmodifier.Object
83+
}
84+
85+
// AttributeWithSetPlanModifiers is an optional interface on Attribute which
86+
// enables Set plan modifier support.
87+
type AttributeWithSetPlanModifiers interface {
88+
fwschema.Attribute
89+
90+
// SetPlanModifiers should return a list of Set plan modifiers.
91+
SetPlanModifiers() []planmodifier.Set
92+
}
93+
94+
// AttributeWithStringPlanModifiers is an optional interface on Attribute which
95+
// enables String plan modifier support.
96+
type AttributeWithStringPlanModifiers interface {
97+
fwschema.Attribute
98+
99+
// StringPlanModifiers should return a list of String plan modifiers.
100+
StringPlanModifiers() []planmodifier.String
101+
}

internal/fwschema/fwxschema/block_plan_modification.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fwxschema
22

33
import (
44
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
56
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
67
)
78

@@ -17,3 +18,30 @@ type BlockWithPlanModifiers interface {
1718
// the tfsdk.Block field name.
1819
GetPlanModifiers() tfsdk.AttributePlanModifiers
1920
}
21+
22+
// BlockWithListPlanModifiers is an optional interface on Block which
23+
// enables List plan modifier support.
24+
type BlockWithListPlanModifiers interface {
25+
fwschema.Block
26+
27+
// ListPlanModifiers should return a list of List plan modifiers.
28+
ListPlanModifiers() []planmodifier.List
29+
}
30+
31+
// BlockWithObjectPlanModifiers is an optional interface on Block which
32+
// enables Object plan modifier support.
33+
type BlockWithObjectPlanModifiers interface {
34+
fwschema.Block
35+
36+
// ObjectPlanModifiers should return a list of Object plan modifiers.
37+
ObjectPlanModifiers() []planmodifier.Object
38+
}
39+
40+
// BlockWithSetPlanModifiers is an optional interface on Block which
41+
// enables Set plan modifier support.
42+
type BlockWithSetPlanModifiers interface {
43+
fwschema.Block
44+
45+
// SetPlanModifiers should return a list of Set plan modifiers.
46+
SetPlanModifiers() []planmodifier.Set
47+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fwxschema
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
6+
)
7+
8+
// NestedAttributeObjectWithPlanModifiers is an optional interface on
9+
// NestedAttributeObject which enables Object plan modification support.
10+
type NestedAttributeObjectWithPlanModifiers interface {
11+
fwschema.NestedAttributeObject
12+
13+
// ObjectPlanModifiers should return a list of Object plan modifiers.
14+
ObjectPlanModifiers() []planmodifier.Object
15+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package fwxschema
2+
3+
import (
4+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
5+
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
6+
)
7+
8+
// NestedBlockObjectWithPlanModifiers is an optional interface on
9+
// NestedBlockObject which enables Object plan modification support.
10+
type NestedBlockObjectWithPlanModifiers interface {
11+
fwschema.NestedBlockObject
12+
13+
// ObjectPlanModifiers should return a list of Object plan modifiers.
14+
ObjectPlanModifiers() []planmodifier.Object
15+
}

0 commit comments

Comments
 (0)