Skip to content

Commit d4215ef

Browse files
committed
Add support for write-only attributes in action schema
1 parent 8855023 commit d4215ef

30 files changed

+365
-37
lines changed

action/schema/bool_attribute.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,16 @@ type BoolAttribute struct {
104104
// xattr.TypeWithValidate interface, the validators defined in this field
105105
// are run in addition to the validation defined by the type.
106106
Validators []validator.Bool
107+
108+
// WriteOnly indicates that Terraform will not store this attribute value
109+
// in the plan or state artifacts.
110+
// If WriteOnly is true, either Optional or Required must also be true.
111+
// WriteOnly cannot be set with Computed.
112+
//
113+
// This functionality is only supported in Terraform 1.11 and later.
114+
// Practitioners that choose a value for this attribute with older
115+
// versions of Terraform will receive an error.
116+
WriteOnly bool
107117
}
108118

109119
// ApplyTerraform5AttributePathStep always returns an error as it is not
@@ -166,9 +176,9 @@ func (a BoolAttribute) IsSensitive() bool {
166176
return false
167177
}
168178

169-
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
179+
// IsWriteOnly returns the WriteOnly field value.
170180
func (a BoolAttribute) IsWriteOnly() bool {
171-
return false
181+
return a.WriteOnly
172182
}
173183

174184
// IsRequiredForImport returns false as this behavior is only relevant

action/schema/bool_attribute_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ func TestBoolAttributeIsWriteOnly(t *testing.T) {
370370
attribute: schema.BoolAttribute{},
371371
expected: false,
372372
},
373+
"writeOnly": {
374+
attribute: schema.BoolAttribute{
375+
WriteOnly: true,
376+
},
377+
expected: true,
378+
},
373379
}
374380

375381
for name, testCase := range testCases {

action/schema/dynamic_attribute.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,16 @@ type DynamicAttribute struct {
105105
// xattr.TypeWithValidate interface, the validators defined in this field
106106
// are run in addition to the validation defined by the type.
107107
Validators []validator.Dynamic
108+
109+
// WriteOnly indicates that Terraform will not store this attribute value
110+
// in the plan or state artifacts.
111+
// If WriteOnly is true, either Optional or Required must also be true.
112+
// WriteOnly cannot be set with Computed.
113+
//
114+
// This functionality is only supported in Terraform 1.11 and later.
115+
// Practitioners that choose a value for this attribute with older
116+
// versions of Terraform will receive an error.
117+
WriteOnly bool
108118
}
109119

110120
// ApplyTerraform5AttributePathStep always returns an error as it is not
@@ -167,9 +177,9 @@ func (a DynamicAttribute) IsSensitive() bool {
167177
return false
168178
}
169179

170-
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
180+
// IsWriteOnly returns the WriteOnly field value.
171181
func (a DynamicAttribute) IsWriteOnly() bool {
172-
return false
182+
return a.WriteOnly
173183
}
174184

175185
// IsRequiredForImport returns false as this behavior is only relevant

action/schema/dynamic_attribute_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"testing"
1010

1111
"github.com/google/go-cmp/cmp"
12+
"github.com/hashicorp/terraform-plugin-go/tftypes"
13+
1214
"github.com/hashicorp/terraform-plugin-framework/action/schema"
1315
"github.com/hashicorp/terraform-plugin-framework/attr"
1416
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
1517
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
1618
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
1719
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1820
"github.com/hashicorp/terraform-plugin-framework/types"
19-
"github.com/hashicorp/terraform-plugin-go/tftypes"
2021
)
2122

2223
func TestDynamicAttributeApplyTerraform5AttributePathStep(t *testing.T) {
@@ -369,6 +370,12 @@ func TestDynamicAttributeIsWriteOnly(t *testing.T) {
369370
attribute: schema.DynamicAttribute{},
370371
expected: false,
371372
},
373+
"writeOnly": {
374+
attribute: schema.DynamicAttribute{
375+
WriteOnly: true,
376+
},
377+
expected: true,
378+
},
372379
}
373380

374381
for name, testCase := range testCases {

action/schema/float32_attribute.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ type Float32Attribute struct {
107107
// xattr.TypeWithValidate interface, the validators defined in this field
108108
// are run in addition to the validation defined by the type.
109109
Validators []validator.Float32
110+
111+
// WriteOnly indicates that Terraform will not store this attribute value
112+
// in the plan or state artifacts.
113+
// If WriteOnly is true, either Optional or Required must also be true.
114+
// WriteOnly cannot be set with Computed.
115+
//
116+
// This functionality is only supported in Terraform 1.11 and later.
117+
// Practitioners that choose a value for this attribute with older
118+
// versions of Terraform will receive an error.
119+
WriteOnly bool
110120
}
111121

112122
// ApplyTerraform5AttributePathStep always returns an error as it is not
@@ -169,9 +179,9 @@ func (a Float32Attribute) IsSensitive() bool {
169179
return false
170180
}
171181

172-
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
182+
// IsWriteOnly returns the WriteOnly field value.
173183
func (a Float32Attribute) IsWriteOnly() bool {
174-
return false
184+
return a.WriteOnly
175185
}
176186

177187
// IsRequiredForImport returns false as this behavior is only relevant

action/schema/float32_attribute_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,12 @@ func TestFloat32AttributeIsWriteOnly(t *testing.T) {
370370
attribute: schema.Float32Attribute{},
371371
expected: false,
372372
},
373+
"writeOnly": {
374+
attribute: schema.Float32Attribute{
375+
WriteOnly: true,
376+
},
377+
expected: true,
378+
},
373379
}
374380

375381
for name, testCase := range testCases {

action/schema/float64_attribute.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ type Float64Attribute struct {
107107
// xattr.TypeWithValidate interface, the validators defined in this field
108108
// are run in addition to the validation defined by the type.
109109
Validators []validator.Float64
110+
111+
// WriteOnly indicates that Terraform will not store this attribute value
112+
// in the plan or state artifacts.
113+
// If WriteOnly is true, either Optional or Required must also be true.
114+
// WriteOnly cannot be set with Computed.
115+
//
116+
// This functionality is only supported in Terraform 1.11 and later.
117+
// Practitioners that choose a value for this attribute with older
118+
// versions of Terraform will receive an error.
119+
WriteOnly bool
110120
}
111121

112122
// ApplyTerraform5AttributePathStep always returns an error as it is not
@@ -169,9 +179,9 @@ func (a Float64Attribute) IsSensitive() bool {
169179
return false
170180
}
171181

172-
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
182+
// IsWriteOnly returns the WriteOnly field value.
173183
func (a Float64Attribute) IsWriteOnly() bool {
174-
return false
184+
return a.WriteOnly
175185
}
176186

177187
// IsRequiredForImport returns false as this behavior is only relevant

action/schema/float64_attribute_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestFloat64AttributeIsSensitive(t *testing.T) {
359359
}
360360
}
361361

362-
func TestFloat54AttributeIsWriteOnly(t *testing.T) {
362+
func TestFloat64AttributeIsWriteOnly(t *testing.T) {
363363
t.Parallel()
364364

365365
testCases := map[string]struct {
@@ -370,6 +370,12 @@ func TestFloat54AttributeIsWriteOnly(t *testing.T) {
370370
attribute: schema.Float64Attribute{},
371371
expected: false,
372372
},
373+
"writeOnly": {
374+
attribute: schema.Float64Attribute{
375+
WriteOnly: true,
376+
},
377+
expected: true,
378+
},
373379
}
374380

375381
for name, testCase := range testCases {

action/schema/int32_attribute.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,16 @@ type Int32Attribute struct {
107107
// xattr.TypeWithValidate interface, the validators defined in this field
108108
// are run in addition to the validation defined by the type.
109109
Validators []validator.Int32
110+
111+
// WriteOnly indicates that Terraform will not store this attribute value
112+
// in the plan or state artifacts.
113+
// If WriteOnly is true, either Optional or Required must also be true.
114+
// WriteOnly cannot be set with Computed.
115+
//
116+
// This functionality is only supported in Terraform 1.11 and later.
117+
// Practitioners that choose a value for this attribute with older
118+
// versions of Terraform will receive an error.
119+
WriteOnly bool
110120
}
111121

112122
// ApplyTerraform5AttributePathStep always returns an error as it is not
@@ -169,9 +179,9 @@ func (a Int32Attribute) IsSensitive() bool {
169179
return false
170180
}
171181

172-
// IsWriteOnly always returns false as action schema attributes cannot be WriteOnly.
182+
// IsWriteOnly returns the WriteOnly field value.
173183
func (a Int32Attribute) IsWriteOnly() bool {
174-
return false
184+
return a.WriteOnly
175185
}
176186

177187
// IsRequiredForImport returns false as this behavior is only relevant

action/schema/int32_attribute_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ func TestInt32AttributeIsSensitive(t *testing.T) {
359359
}
360360
}
361361

362-
func TestInt2AttributeIsWriteOnly(t *testing.T) {
362+
func TestInt32AttributeIsWriteOnly(t *testing.T) {
363363
t.Parallel()
364364

365365
testCases := map[string]struct {
@@ -370,6 +370,12 @@ func TestInt2AttributeIsWriteOnly(t *testing.T) {
370370
attribute: schema.Int32Attribute{},
371371
expected: false,
372372
},
373+
"writeOnly": {
374+
attribute: schema.Int32Attribute{
375+
WriteOnly: true,
376+
},
377+
expected: true,
378+
},
373379
}
374380

375381
for name, testCase := range testCases {

0 commit comments

Comments
 (0)