Skip to content

Commit 3506d06

Browse files
authored
Merge branch 'main' into rk/list-resource-config
2 parents cdcb3c7 + 377d9e3 commit 3506d06

File tree

76 files changed

+9626
-2833
lines changed

Some content is hidden

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

76 files changed

+9626
-2833
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
kind: BUG FIXES
2+
body: 'all: Fixed bug with `UseStateForUnknown` where known null state values were not preserved during update plans.'
3+
time: 2025-06-12T11:54:11.818923-04:00
4+
custom:
5+
Issue: "1117"

action/schema.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
package action
55

66
import (
7+
"github.com/hashicorp/terraform-plugin-framework/action/schema"
78
"github.com/hashicorp/terraform-plugin-framework/diag"
8-
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
99
)
1010

1111
// SchemaRequest represents a request for the Action to return its schema.
@@ -17,10 +17,15 @@ type SchemaRequest struct{}
1717
// response struct is supplied as an argument to the Action type Schema
1818
// method.
1919
type SchemaResponse struct {
20-
// TODO:Actions: This will eventually be replaced by an interface defined in
21-
// an "actions/schema" package. Schema implementations that will fulfill this
22-
// interface will be unlinked, linked, or lifecycle. (also defined in the "actions/schema" package)
23-
Schema fwschema.Schema
20+
21+
// Schema is the schema of the action.
22+
//
23+
// There are three different types of actions, which define how a practitioner can trigger an action,
24+
// as well as what effect the action can have on the state.
25+
// - [schema.UnlinkedSchema] actions are actions that cannot cause changes to resource states.
26+
// - [schema.LifecycleSchema] actions are actions that can cause changes to exactly one resource state.
27+
// - [schema.LinkedSchema] actions are actions that can cause changes to one or more resource states.
28+
Schema schema.SchemaType
2429

2530
// Diagnostics report errors or warnings related to retrieving the action schema.
2631
// An empty slice indicates success, with no warnings or errors generated.

action/schema/attribute.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
8+
)
9+
10+
// TODO:Actions: Add all of the attribute and nested attribute types listed below
11+
//
12+
// Attribute define a value field inside an action type schema. Implementations in this
13+
// package include:
14+
// - BoolAttribute
15+
// - DynamicAttribute
16+
// - Float32Attribute
17+
// - Float64Attribute
18+
// - Int32Attribute
19+
// - Int64Attribute
20+
// - ListAttribute
21+
// - MapAttribute
22+
// - NumberAttribute
23+
// - ObjectAttribute
24+
// - SetAttribute
25+
// - StringAttribute
26+
//
27+
// Additionally, the NestedAttribute interface extends Attribute with nested
28+
// attributes. Only supported in protocol version 6. Implementations in this
29+
// package include:
30+
// - ListNestedAttribute
31+
// - MapNestedAttribute
32+
// - SetNestedAttribute
33+
// - SingleNestedAttribute
34+
//
35+
// In practitioner configurations, an equals sign (=) is required to set
36+
// the value. [Configuration Reference]
37+
//
38+
// [Configuration Reference]: https://developer.hashicorp.com/terraform/language/syntax/configuration
39+
type Attribute interface {
40+
fwschema.Attribute
41+
}
42+
43+
// schemaAttributes is an action attribute to fwschema type conversion function.
44+
func schemaAttributes(attributes map[string]Attribute) map[string]fwschema.Attribute {
45+
result := make(map[string]fwschema.Attribute, len(attributes))
46+
47+
for name, attribute := range attributes {
48+
result[name] = attribute
49+
}
50+
51+
return result
52+
}

action/schema/block.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
8+
)
9+
10+
// TODO:Actions: Add all of the block and nested block types listed below
11+
//
12+
// Block defines a structural field inside an action type schema. Implementations in this
13+
// package include:
14+
// - ListNestedBlock
15+
// - SetNestedBlock
16+
// - SingleNestedBlock
17+
//
18+
// In practitioner configurations, an equals sign (=) cannot be used to set the
19+
// value. Blocks are instead repeated as necessary, or require the use of
20+
// [Dynamic Block Expressions].
21+
//
22+
// Prefer NestedAttribute over Block. Blocks should typically be used for
23+
// configuration compatibility with previously existing schemas from an older
24+
// Terraform Plugin SDK. Efforts should be made to convert from Block to
25+
// NestedAttribute as a breaking change for practitioners.
26+
//
27+
// [Dynamic Block Expressions]: https://developer.hashicorp.com/terraform/language/expressions/dynamic-blocks
28+
//
29+
// [Configuration Reference]: https://developer.hashicorp.com/terraform/language/syntax/configuration
30+
type Block interface {
31+
fwschema.Block
32+
}
33+
34+
// schemaBlocks is an action block to fwschema type conversion function.
35+
func schemaBlocks(blocks map[string]Block) map[string]fwschema.Block {
36+
result := make(map[string]fwschema.Block, len(blocks))
37+
38+
for name, block := range blocks {
39+
result[name] = block
40+
}
41+
42+
return result
43+
}

action/schema/bool_attribute.go

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package schema
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tftypes"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
10+
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
11+
"github.com/hashicorp/terraform-plugin-framework/types"
12+
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
13+
)
14+
15+
// Ensure the implementation satisfies the desired interfaces.
16+
var (
17+
_ Attribute = BoolAttribute{}
18+
)
19+
20+
// BoolAttribute represents a schema attribute that is a boolean. When
21+
// retrieving the value for this attribute, use types.Bool as the value type
22+
// unless the CustomType field is set.
23+
//
24+
// Terraform configurations configure this attribute using expressions that
25+
// return a boolean or directly via the true/false keywords.
26+
//
27+
// example_attribute = true
28+
//
29+
// Terraform configurations reference this attribute using the attribute name.
30+
//
31+
// .example_attribute
32+
type BoolAttribute struct {
33+
// CustomType enables the use of a custom attribute type in place of the
34+
// default basetypes.BoolType. When retrieving data, the basetypes.BoolValuable
35+
// associated with this custom type must be used in place of types.Bool.
36+
CustomType basetypes.BoolTypable
37+
38+
// Required indicates whether the practitioner must enter a value for
39+
// this attribute or not. Required and Optional cannot both be true,
40+
// and Required and Computed cannot both be true.
41+
Required bool
42+
43+
// Optional indicates whether the practitioner can choose to enter a value
44+
// for this attribute or not. Optional and Required cannot both be true.
45+
Optional bool
46+
47+
// Description is used in various tooling, like the language server, to
48+
// give practitioners more information about what this attribute is,
49+
// what it's for, and how it should be used. It should be written as
50+
// plain text, with no special formatting.
51+
Description string
52+
53+
// MarkdownDescription is used in various tooling, like the
54+
// documentation generator, to give practitioners more information
55+
// about what this attribute is, what it's for, and how it should be
56+
// used. It should be formatted using Markdown.
57+
MarkdownDescription string
58+
59+
// DeprecationMessage defines warning diagnostic details to display when
60+
// practitioner configurations use this Attribute. The warning diagnostic
61+
// summary is automatically set to "Attribute Deprecated" along with
62+
// configuration source file and line information.
63+
//
64+
// Set this field to a practitioner actionable message such as:
65+
//
66+
// - "Configure other_attribute instead. This attribute will be removed
67+
// in the next major version of the provider."
68+
// - "Remove this attribute's configuration as it no longer is used and
69+
// the attribute will be removed in the next major version of the
70+
// provider."
71+
//
72+
// In Terraform 1.2.7 and later, this warning diagnostic is displayed any
73+
// time a practitioner attempts to configure a value for this attribute and
74+
// certain scenarios where this attribute is referenced.
75+
//
76+
// In Terraform 1.2.6 and earlier, this warning diagnostic is only
77+
// displayed when the Attribute is Required or Optional, and if the
78+
// practitioner configuration sets the value to a known or unknown value
79+
// (which may eventually be null).
80+
//
81+
// Across any Terraform version, there are no warnings raised for
82+
// practitioner configuration values set directly to null, as there is no
83+
// way for the framework to differentiate between an unset and null
84+
// configuration due to how Terraform sends configuration information
85+
// across the protocol.
86+
//
87+
// Additional information about deprecation enhancements for read-only
88+
// attributes can be found in:
89+
//
90+
// - https://github.com/hashicorp/terraform/issues/7569
91+
//
92+
DeprecationMessage string
93+
}
94+
95+
// ApplyTerraform5AttributePathStep always returns an error as it is not
96+
// possible to step further into a BoolAttribute.
97+
func (a BoolAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) (interface{}, error) {
98+
return a.GetType().ApplyTerraform5AttributePathStep(step)
99+
}
100+
101+
// Equal returns true if the given Attribute is a BoolAttribute
102+
// and all fields are equal.
103+
func (a BoolAttribute) Equal(o fwschema.Attribute) bool {
104+
if _, ok := o.(BoolAttribute); !ok {
105+
return false
106+
}
107+
108+
return fwschema.AttributesEqual(a, o)
109+
}
110+
111+
// GetDeprecationMessage returns the DeprecationMessage field value.
112+
func (a BoolAttribute) GetDeprecationMessage() string {
113+
return a.DeprecationMessage
114+
}
115+
116+
// GetDescription returns the Description field value.
117+
func (a BoolAttribute) GetDescription() string {
118+
return a.Description
119+
}
120+
121+
// GetMarkdownDescription returns the MarkdownDescription field value.
122+
func (a BoolAttribute) GetMarkdownDescription() string {
123+
return a.MarkdownDescription
124+
}
125+
126+
// GetType returns types.StringType or the CustomType field value if defined.
127+
func (a BoolAttribute) GetType() attr.Type {
128+
if a.CustomType != nil {
129+
return a.CustomType
130+
}
131+
132+
return types.BoolType
133+
}
134+
135+
// IsComputed always returns false as action schema attributes cannot be Computed.
136+
func (a BoolAttribute) IsComputed() bool {
137+
return false
138+
}
139+
140+
// IsOptional returns the Optional field value.
141+
func (a BoolAttribute) IsOptional() bool {
142+
return a.Optional
143+
}
144+
145+
// IsRequired returns the Required field value.
146+
func (a BoolAttribute) IsRequired() bool {
147+
return a.Required
148+
}
149+
150+
// IsSensitive always returns false as action schema attributes cannot be Sensitive.
151+
func (a BoolAttribute) IsSensitive() bool {
152+
return false
153+
}
154+
155+
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
156+
func (a BoolAttribute) IsWriteOnly() bool {
157+
return false
158+
}
159+
160+
// IsRequiredForImport returns false as this behavior is only relevant
161+
// for managed resource identity schema attributes.
162+
func (a BoolAttribute) IsRequiredForImport() bool {
163+
return false
164+
}
165+
166+
// IsOptionalForImport returns false as this behavior is only relevant
167+
// for managed resource identity schema attributes.
168+
func (a BoolAttribute) IsOptionalForImport() bool {
169+
return false
170+
}

0 commit comments

Comments
 (0)