Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for write only attributes #1044

Merged
merged 62 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 61 commits
Commits
Show all changes
62 commits
Select commit Hold shift + click to select a range
639eda9
initial ephemeral resource interfaces
austinvalle Aug 13, 2024
dfd0cdc
add ephemeral resource configure data
austinvalle Aug 13, 2024
fe2b7db
attribute implementations
austinvalle Aug 13, 2024
a88242a
uncomment custom type tests
austinvalle Aug 13, 2024
4e285b7
added block implementations
austinvalle Aug 13, 2024
9b81285
add nested attribute implementations
austinvalle Aug 13, 2024
99fb820
add schema test
austinvalle Aug 13, 2024
745ce70
remove todo
austinvalle Aug 14, 2024
76c9cad
doc updates, renames, removals
austinvalle Aug 27, 2024
1f24856
initial protov5 + fwserver implementation (protov6 stubbed)
austinvalle Aug 28, 2024
ce01e76
Merge branch 'main' into av/ephemeral-resources
austinvalle Aug 29, 2024
07f7437
add fromproto5 tests
austinvalle Aug 29, 2024
0985765
add toproto5 tests
austinvalle Aug 29, 2024
592fc33
add proto5server tests
austinvalle Aug 30, 2024
ec24f33
implement protov6
austinvalle Aug 30, 2024
bda9bbc
schema + metadata tests
austinvalle Aug 30, 2024
c4f94a9
add close proto5/6 tests
austinvalle Aug 30, 2024
bff71bb
add fwserver tests for schema/metadata
austinvalle Sep 3, 2024
9ff4f27
prevent random false positives
austinvalle Sep 3, 2024
56463dc
validate fwserver tests
austinvalle Sep 3, 2024
c7d5ae2
open/renew/close fwserver tests
austinvalle Sep 3, 2024
dce7c87
update error message
austinvalle Sep 4, 2024
b84bb1d
update plugin go
austinvalle Sep 4, 2024
1871b38
Update `terraform-plugin-go` dependency
SBGoods Sep 23, 2024
55f2ba6
Merge branch 'main' into av/ephemeral-resources
austinvalle Sep 24, 2024
627a49b
remove `config` from renew
austinvalle Sep 24, 2024
90cbd29
Implement write only attributes in the `resource/schema` package
SBGoods Sep 25, 2024
0f84c52
Implement write only attributes in the `datasource/schema` package
SBGoods Sep 25, 2024
2c9d3cb
Implement write only attributes in the `provider/schema` and `provide…
SBGoods Sep 25, 2024
1e41c4a
Implement write only attributes in the `internal/testing/testschema` …
SBGoods Sep 25, 2024
2279e84
Merge remote-tracking branch 'origin/av/ephemeral-resources' into SBG…
SBGoods Sep 26, 2024
a72206f
Update `terraform-plugin-go` dependency
SBGoods Sep 26, 2024
7328990
Implement write only attributes in the `ephemeral/schema` package
SBGoods Sep 26, 2024
aacc3e8
Populate writeOnly fields in `internal/toproto5` and `internal/toproto6`
SBGoods Sep 26, 2024
ee78f76
Implement `ValidateResourceConfigClientCapabilities` in the `Validate…
SBGoods Sep 26, 2024
63adba2
Add attribute validation for write only attributes
SBGoods Sep 26, 2024
32e1f49
Initial `RequiredWriteOnlyNilsAttributePaths()` implementation
SBGoods Oct 1, 2024
9f83fe3
Complete `RequiredWriteOnlyNilsAttributePaths()` implementation
SBGoods Oct 1, 2024
795ad64
Implement `validator.ValidateSchemaClientCapabilities`
SBGoods Oct 2, 2024
2d73905
Implement automatic write-only value nullification during `ApplyResou…
SBGoods Oct 2, 2024
23a025b
Explicitly set `ValidateSchemaClientCapabilities` during `ValidateDat…
SBGoods Oct 3, 2024
6a5e0a1
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Nov 26, 2024
b198907
Nullify write-only attributes during Plan and Apply regardless of cli…
SBGoods Dec 3, 2024
09ca993
Merge branch 'main' into SBGoods/write-only-attributes
austinvalle Dec 17, 2024
f4f97bd
remove apply client capability
austinvalle Dec 17, 2024
4b722e0
add validation for older terraform client versions
austinvalle Jan 2, 2025
428efef
add client capabilities to nested attribute validation
austinvalle Jan 2, 2025
f2c04b2
Update wording of `IsWriteOnly` comment for `ephemeral/schema`, `prov…
SBGoods Jan 14, 2025
da1433e
Update various comments for wording
SBGoods Jan 14, 2025
46205a8
Update test cases
SBGoods Jan 14, 2025
1ef9cb2
Update wording for `write-only` attribute validation errors
SBGoods Jan 14, 2025
4aa117c
Refactor write_only_nested_attribute_validation.go and write_only_nes…
SBGoods Jan 14, 2025
5c9c15c
Move `Required` + `WriteOnly` validations from `PlanResourceChange` R…
SBGoods Jan 15, 2025
f73d27e
Add write-only value nullification to `ReadResource`, `ImportResource…
SBGoods Jan 16, 2025
44d4a25
Add missing `IsWriteOnly()` unit tests for `ephemeral/schema` package
SBGoods Jan 17, 2025
cb1f813
Add godoc comment to `NullifyWriteOnlyAttributes()`
SBGoods Jan 17, 2025
2b72dc0
Add testing for nested types for `NullifyWriteOnlyAttributes()`
SBGoods Feb 4, 2025
e210315
Add website documentation
SBGoods Feb 5, 2025
fe7e644
Add recommendation to use private state to store hashes
SBGoods Feb 6, 2025
49afd6b
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Feb 6, 2025
fa3bc55
Add changelog entries
SBGoods Feb 6, 2025
c2fb98f
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Feb 10, 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
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20250206-114700.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'resource/schema: Added `WriteOnly` schema field for managed resource schemas to indicate a write-only attribute.
Write-only attribute values are not saved to the Terraform plan or state artifacts.'
time: 2025-02-06T11:47:00.176842-05:00
custom:
Issue: "1044"
5 changes: 5 additions & 0 deletions .changes/unreleased/NOTES-20250206-114436.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kind: NOTES
body: Write-only attribute support is in technical preview and offered without compatibility promises until Terraform 1.11 is generally available.
time: 2025-02-06T11:44:36.156747-05:00
custom:
Issue: "1044"
8 changes: 7 additions & 1 deletion datasource/schema/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
package schema

import (
"github.com/hashicorp/terraform-plugin-go/tftypes"

"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"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// Ensure the implementation satisifies the desired interfaces.
Expand Down Expand Up @@ -181,6 +182,11 @@ func (a BoolAttribute) IsRequired() bool {
return a.Required
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a BoolAttribute) IsWriteOnly() bool {
return false
}

// IsSensitive returns the Sensitive field value.
func (a BoolAttribute) IsSensitive() bool {
return a.Sensitive
Expand Down
31 changes: 30 additions & 1 deletion datasource/schema/bool_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"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"
)

func TestBoolAttributeApplyTerraform5AttributePathStep(t *testing.T) {
Expand Down Expand Up @@ -423,3 +424,31 @@ func TestBoolAttributeIsSensitive(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.BoolAttribute
expected bool
}{
"not-writeOnly": {
attribute: schema.BoolAttribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

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

import (
"github.com/hashicorp/terraform-plugin-go/tftypes"

"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"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// Ensure the implementation satisifies the desired interfaces.
Expand Down Expand Up @@ -182,6 +183,11 @@ func (a DynamicAttribute) IsSensitive() bool {
return a.Sensitive
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a DynamicAttribute) IsWriteOnly() bool {
return false
}

// DynamicValidators returns the Validators field value.
func (a DynamicAttribute) DynamicValidators() []validator.Dynamic {
return a.Validators
Expand Down
31 changes: 30 additions & 1 deletion datasource/schema/dynamic_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"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"
)

func TestDynamicAttributeApplyTerraform5AttributePathStep(t *testing.T) {
Expand Down Expand Up @@ -390,6 +391,34 @@ func TestDynamicAttributeIsSensitive(t *testing.T) {
}
}

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

testCases := map[string]struct {
attribute schema.DynamicAttribute
expected bool
}{
"not-writeOnly": {
attribute: schema.DynamicAttribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

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

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

Expand Down
5 changes: 5 additions & 0 deletions datasource/schema/float32_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,8 @@ func (a Float32Attribute) IsRequired() bool {
func (a Float32Attribute) IsSensitive() bool {
return a.Sensitive
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a Float32Attribute) IsWriteOnly() bool {
return false
}
28 changes: 28 additions & 0 deletions datasource/schema/float32_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,31 @@ func TestFloat32AttributeIsSensitive(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.Float32Attribute
expected bool
}{
"not-writeOnly": {
attribute: schema.Float32Attribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

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

import (
"github.com/hashicorp/terraform-plugin-go/tftypes"

"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"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// Ensure the implementation satisifies the desired interfaces.
Expand Down Expand Up @@ -188,3 +189,8 @@ func (a Float64Attribute) IsRequired() bool {
func (a Float64Attribute) IsSensitive() bool {
return a.Sensitive
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a Float64Attribute) IsWriteOnly() bool {
return false
}
31 changes: 30 additions & 1 deletion datasource/schema/float64_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"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"
)

func TestFloat64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
Expand Down Expand Up @@ -423,3 +424,31 @@ func TestFloat64AttributeIsSensitive(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.Float64Attribute
expected bool
}{
"not-writeOnly": {
attribute: schema.Float64Attribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}
5 changes: 5 additions & 0 deletions datasource/schema/int32_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,8 @@ func (a Int32Attribute) IsRequired() bool {
func (a Int32Attribute) IsSensitive() bool {
return a.Sensitive
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a Int32Attribute) IsWriteOnly() bool {
return false
}
28 changes: 28 additions & 0 deletions datasource/schema/int32_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,31 @@ func TestInt32AttributeIsSensitive(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.Int32Attribute
expected bool
}{
"not-writeOnly": {
attribute: schema.Int32Attribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}
8 changes: 7 additions & 1 deletion datasource/schema/int64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
package schema

import (
"github.com/hashicorp/terraform-plugin-go/tftypes"

"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"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

// Ensure the implementation satisifies the desired interfaces.
Expand Down Expand Up @@ -188,3 +189,8 @@ func (a Int64Attribute) IsRequired() bool {
func (a Int64Attribute) IsSensitive() bool {
return a.Sensitive
}

// IsWriteOnly returns false as write-only attributes are not supported in data source schemas.
func (a Int64Attribute) IsWriteOnly() bool {
return false
}
31 changes: 30 additions & 1 deletion datasource/schema/int64_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ import (
"testing"

"github.com/google/go-cmp/cmp"
"github.com/hashicorp/terraform-plugin-go/tftypes"

"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"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"
)

func TestInt64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
Expand Down Expand Up @@ -423,3 +424,31 @@ func TestInt64AttributeIsSensitive(t *testing.T) {
})
}
}

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

testCases := map[string]struct {
attribute schema.Int64Attribute
expected bool
}{
"not-writeOnly": {
attribute: schema.Int64Attribute{},
expected: false,
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

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

got := testCase.attribute.IsWriteOnly()

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