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

all: Add support for write-only attributes #1375

Merged
merged 63 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from 53 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
6e8402b
Update `terraform-plugin-go` dependency
SBGoods Aug 30, 2024
d30854f
Add `WriteOnly` attribute to schema and internal schema validation.
SBGoods Aug 30, 2024
17b4a61
Add `WriteOnly` validation for data source, provider, and provider me…
SBGoods Aug 30, 2024
5218321
Add WriteOnly capabilities validation to `ValidateResourceTypeConfig`…
SBGoods Aug 30, 2024
bb2bb08
Skip value validation for `Required` + `WriteOnly` attributes.
SBGoods Aug 30, 2024
1d70831
Fix intermittent test failures for `hasWriteOnly()`
SBGoods Aug 30, 2024
e7d79db
Validate non-null values for `Required` and `WriteOnly` attributes in…
SBGoods Sep 3, 2024
d171fb7
Add initial implementation for `PreferWriteOnlyAttribute()` validator
SBGoods Sep 5, 2024
25c2a13
Finish `PreferWriteOnlyAttribute()` validator implementation.
SBGoods Sep 9, 2024
2f917f8
Move `schema.ValidateResourceConfigFuncs` to `schema.Resource` and im…
SBGoods Sep 9, 2024
cab2a27
Add automatic state handling for writeOnly attributes
SBGoods Sep 10, 2024
6cc6811
Apply suggestions from code review
SBGoods Sep 16, 2024
994bc66
Wrap `setWriteOnlyNullValues` call in client capabilities check
SBGoods Sep 17, 2024
ff70638
Refactor tests to match diag summary changes
SBGoods Sep 17, 2024
c5c870d
Move write-only helper functions and tests to their own files.
SBGoods Sep 17, 2024
21cebbe
Refactor test attribute names for clarity
SBGoods Sep 17, 2024
a276ff4
Refactor `validateWriteOnlyNullValues()` to build an attribute path.`
SBGoods Sep 23, 2024
fac41b5
Refactor `validateWriteOnlyRequiredValues()` to build an attribute pa…
SBGoods Sep 23, 2024
7cf9024
Refactor field and function names based on PR feedback.
SBGoods Sep 23, 2024
d3a4926
Add clarifying comments.
SBGoods Sep 23, 2024
437577d
Add internal validation preventing data sources from defining `Valida…
SBGoods Sep 23, 2024
d5a7bd6
Change `writeOnlyAttributeName` parameter to use `cty.Path`
SBGoods Oct 3, 2024
5c2e2e2
Simplify validation condition logic
SBGoods Oct 3, 2024
1c21c96
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Nov 25, 2024
a5d8c2a
run `go mod tidy`
SBGoods Nov 25, 2024
3f32220
update `terraform-plugin-go` dependency
SBGoods Nov 25, 2024
28a5768
Add write-only support to `ProtoToConfigSchema()`
SBGoods Nov 26, 2024
2aec830
Nullify write-only attributes during Plan and Apply regardless of cli…
SBGoods Dec 3, 2024
1479d62
Introduce `(*ResourceData).GetRawWriteOnly()` and `(*ResourceData).Ge…
SBGoods Dec 17, 2024
18894a8
Revert "Introduce `(*ResourceData).GetRawWriteOnly()` and `(*Resource…
SBGoods Dec 17, 2024
20550b9
Introduce `(*ResourceData).GetRawConfigAt()` helper method for retrie…
SBGoods Dec 17, 2024
396b49b
null out write-only values
austinvalle Dec 18, 2024
e1dbbac
Return `diag.Diagnostics` instead of error for `(*ResourceData).GetRa…
SBGoods Dec 18, 2024
84b9873
Update `terraform-plugin-go` dependency
SBGoods Dec 18, 2024
0a9d11a
Add additional tests for automatic write-only value nullification
SBGoods Dec 18, 2024
6461314
Resolve linting errors and add copyright headers
SBGoods Dec 18, 2024
45cceb5
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Dec 18, 2024
0816d60
Remove "incorrect" test case
SBGoods Dec 18, 2024
e844e2d
Use `cty.DynamicVal` as default value for `GetRawConfigAt()`
SBGoods Dec 19, 2024
ec6675f
Throw validation error for computed blocks with write-only attributes
SBGoods Dec 19, 2024
f529da0
add `GetRawConfigAt` to `ResourceDiff` for usage in `CustomizeDiff` f…
austinvalle Jan 3, 2025
5f29273
unit tests for `ResourceDiff`
austinvalle Jan 3, 2025
c0d2bac
Add validation error for `WriteOnly` and `ForceNew`
SBGoods Jan 3, 2025
1dcc224
Add write-only value nullification to `ImportResourceState` and `Upgr…
SBGoods Jan 14, 2025
f831b07
Move `Required` + `WriteOnly` attribute validation to `ValidateResour…
SBGoods Jan 15, 2025
48b23cd
Merge remote-tracking branch 'origin/SBGoods/write-only-attributes' i…
SBGoods Jan 15, 2025
3e85928
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Jan 15, 2025
511005e
Add website documentation
SBGoods Jan 21, 2025
b6c06cf
Add changelog entries
SBGoods Jan 21, 2025
36978c5
Update `terraform-plugin-go` dependency to `v0.24.0`
SBGoods Jan 22, 2025
33b7ee4
Replace fully qualified links with relative links in website document…
SBGoods Jan 22, 2025
d1d4c14
Add more test cases for `GetRawConfigAt()`
SBGoods Jan 22, 2025
1b935c4
Add link to ephemeral resource documentation
SBGoods Jan 22, 2025
5070aeb
Apply suggestions from code review
SBGoods Jan 24, 2025
4b5b363
Apply suggestions from code review
SBGoods Jan 24, 2025
c1a1556
Fix write-only attribute error assertions
SBGoods Jan 24, 2025
d40b6b0
Prevent `WriteOnly` from being used with `Default` and `DefaultFunc`.
SBGoods Jan 24, 2025
6d9ab94
Update error messaging
SBGoods Jan 24, 2025
91bc003
Add null value test case
SBGoods Jan 24, 2025
2c0793b
Rename "write-only attributes" to "write-only arguments" in website d…
SBGoods Jan 24, 2025
099130f
Add configuration examples to `cty.Path` documentation
SBGoods Feb 3, 2025
74dccee
Merge branch 'main' into SBGoods/write-only-attributes
SBGoods Feb 3, 2025
e58d5e3
Add changelog entry for `ValidateRawResourceConfigFuncs`
SBGoods Feb 3, 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-20250121-165644.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'helper/schema: Added `WriteOnly` schema behavior for managed resource schemas to indicate a write-only attribute.
Write-only attributes are managed resource attributes whose values are not saved to the Terraform plan or state artifacts.'
time: 2025-01-21T16:56:44.038893-05:00
custom:
Issue: "1375"
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20250121-170105.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'helper/validation: Added `PreferWriteOnlyAttribute()` validator that warns practitioners when a write-only version of
a configured attribute is available.'
time: 2025-01-21T17:01:05.40229-05:00
custom:
Issue: "1375"
5 changes: 5 additions & 0 deletions .changes/unreleased/NOTES-20250121-170545.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-01-21T17:05:45.398836-05:00
custom:
Issue: "1375"
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/hashicorp/logutils v1.0.0
github.com/hashicorp/terraform-exec v0.21.0
github.com/hashicorp/terraform-json v0.24.0
github.com/hashicorp/terraform-plugin-go v0.25.0
github.com/hashicorp/terraform-plugin-go v0.26.0
github.com/hashicorp/terraform-plugin-log v0.9.0
github.com/mitchellh/copystructure v1.2.0
github.com/mitchellh/go-testing-interface v1.14.1
Expand All @@ -38,7 +38,7 @@ require (
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
github.com/hashicorp/terraform-registry-address v0.2.3 // indirect
github.com/hashicorp/terraform-registry-address v0.2.4 // indirect
github.com/hashicorp/terraform-svchost v0.1.1 // indirect
github.com/hashicorp/yamux v0.1.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -49,13 +49,13 @@ require (
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
golang.org/x/mod v0.22.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.29.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/protobuf v1.35.1 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc v1.69.4 // indirect
google.golang.org/protobuf v1.36.3 // indirect
)
40 changes: 28 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ github.com/go-git/go-billy/v5 v5.6.0 h1:w2hPNtoehvJIxR00Vb4xX94qHQi/ApZfX+nBE2Cj
github.com/go-git/go-billy/v5 v5.6.0/go.mod h1:sFDq7xD3fn3E0GOwUSZqHo9lrkmx8xJhA0ZrfvjBRGM=
github.com/go-git/go-git/v5 v5.13.0 h1:vLn5wlGIh/X78El6r3Jr+30W16Blk0CTcxTYcYPWi5E=
github.com/go-git/go-git/v5 v5.13.0/go.mod h1:Wjo7/JyVKtQgUNdXYXIepzWfJQkUEIGvkvVkiXRR/zw=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE=
Expand All @@ -42,6 +46,8 @@ github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-checkpoint v0.5.0 h1:MFYpPZCnQqQTE18jFwSII6eUQrD/oxMFp3mlgcqk5mU=
Expand Down Expand Up @@ -74,12 +80,12 @@ github.com/hashicorp/terraform-exec v0.21.0 h1:uNkLAe95ey5Uux6KJdua6+cv8asgILFVW
github.com/hashicorp/terraform-exec v0.21.0/go.mod h1:1PPeMYou+KDUSSeRE9szMZ/oHf4fYUmB923Wzbq1ICg=
github.com/hashicorp/terraform-json v0.24.0 h1:rUiyF+x1kYawXeRth6fKFm/MdfBS6+lW4NbeATsYz8Q=
github.com/hashicorp/terraform-json v0.24.0/go.mod h1:Nfj5ubo9xbu9uiAoZVBsNOjvNKB66Oyrvtit74kC7ow=
github.com/hashicorp/terraform-plugin-go v0.25.0 h1:oi13cx7xXA6QciMcpcFi/rwA974rdTxjqEhXJjbAyks=
github.com/hashicorp/terraform-plugin-go v0.25.0/go.mod h1:+SYagMYadJP86Kvn+TGeV+ofr/R3g4/If0O5sO96MVw=
github.com/hashicorp/terraform-plugin-go v0.26.0 h1:cuIzCv4qwigug3OS7iKhpGAbZTiypAfFQmw8aE65O2M=
github.com/hashicorp/terraform-plugin-go v0.26.0/go.mod h1:+CXjuLDiFgqR+GcrM5a2E2Kal5t5q2jb0E3D57tTdNY=
github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow=
github.com/hashicorp/terraform-registry-address v0.2.3 h1:2TAiKJ1A3MAkZlH1YI/aTVcLZRu7JseiXNRHbOAyoTI=
github.com/hashicorp/terraform-registry-address v0.2.3/go.mod h1:lFHA76T8jfQteVfT7caREqguFrW3c4MFSPhZB7HHgUM=
github.com/hashicorp/terraform-registry-address v0.2.4 h1:JXu/zHB2Ymg/TGVCRu10XqNa4Sh2bWcqCNyKWjnCPJA=
github.com/hashicorp/terraform-registry-address v0.2.4/go.mod h1:tUNYTVyCtU4OIGXXMDp7WNcJ+0W1B4nmstVDgHMjfAU=
github.com/hashicorp/terraform-svchost v0.1.1 h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
github.com/hashicorp/terraform-svchost v0.1.1/go.mod h1:mNsjQfZyf/Jhz35v6/0LWcv26+X7JPS+buii2c9/ctc=
github.com/hashicorp/yamux v0.1.1 h1:yrQxtgseBDrq9Y652vSRDvsKCJKOUD+GzTS4Y0Y8pvE=
Expand Down Expand Up @@ -142,6 +148,16 @@ github.com/zclconf/go-cty v1.16.1 h1:a5TZEPzBFFR53udlIKApXzj8JIF4ZNQ6abH79z5R1S0
github.com/zclconf/go-cty v1.16.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940 h1:4r45xpDWB6ZMSMNJFMOjqrGHynW3DIBuR2H9j0ug+Mo=
github.com/zclconf/go-cty-debug v0.0.0-20240509010212-0d6042c53940/go.mod h1:CmBdvvj3nqzfzJ6nTCIwDTPZ56aVGvDrmztiO5g3qrM=
go.opentelemetry.io/otel v1.31.0 h1:NsJcKPIW0D0H3NgzPDHmo0WW6SptzPdqg/L1zsIm2hY=
go.opentelemetry.io/otel v1.31.0/go.mod h1:O0C14Yl9FgkjqcCZAsE053C13OaddMYr/hz6clDkEJE=
go.opentelemetry.io/otel/metric v1.31.0 h1:FSErL0ATQAmYHUIzSezZibnyVlft1ybhy4ozRPcF2fE=
go.opentelemetry.io/otel/metric v1.31.0/go.mod h1:C3dEloVbLuYoX41KpmAhOqNriGbA+qqH6PQ5E5mUfnY=
go.opentelemetry.io/otel/sdk v1.31.0 h1:xLY3abVHYZ5HSfOg3l2E5LUj2Cwva5Y7yGxnSW9H5Gk=
go.opentelemetry.io/otel/sdk v1.31.0/go.mod h1:TfRbMdhvxIIr/B2N2LQW2S5v9m3gOQ/08KsbbO5BPT0=
go.opentelemetry.io/otel/sdk/metric v1.31.0 h1:i9hxxLJF/9kkvfHppyLL55aW7iIJz4JjxTeYusH7zMc=
go.opentelemetry.io/otel/sdk/metric v1.31.0/go.mod h1:CRInTMVvNhUKgSAMbKyTMxqOBC0zgyxzW55lZzX43Y8=
go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HYdmJys=
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc=
Expand All @@ -153,8 +169,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down Expand Up @@ -195,14 +211,14 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM=
google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142 h1:e7S5W7MGGLaSu8j3YjdezkZ+m1/Nm0uRVRMEMGk26Xs=
google.golang.org/genproto/googleapis/rpc v0.0.0-20240814211410-ddb44dafa142/go.mod h1:UqMtugtsSgubUsoxbuAoiCXvqvErP7Gf0so0mK9tHxU=
google.golang.org/grpc v1.67.1 h1:zWnc1Vrcno+lHZCOofnIMvycFcc0QRGIzm9dhnDX68E=
google.golang.org/grpc v1.67.1/go.mod h1:1gLDyUQU7CTLJI90u3nXZ9ekeghjeM7pTDZlqFNg2AA=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 h1:X58yt85/IXCx0Y3ZwN6sEIKZzQtDEYaBWrDvErdXrRE=
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53/go.mod h1:GX3210XPVPUjJbTUbvwI8f2IpZDMZuPJWDzDuebbviI=
google.golang.org/grpc v1.69.4 h1:MF5TftSMkd8GLw/m0KM6V8CMOCY6NZ1NQDPGFgbTt4A=
google.golang.org/grpc v1.69.4/go.mod h1:vyjdE6jLBI76dgpDojsFGNaHlxdjXN9ghpnd2o7JGZ4=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.35.1 h1:m3LfL6/Ca+fqnjnlqQXNpFPABW1UD7mjh8KO2mKFytA=
google.golang.org/protobuf v1.35.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
google.golang.org/protobuf v1.36.3 h1:82DV7MYdb8anAVi3qge1wSnMDrnKK7ebr+I0hHRN1BU=
google.golang.org/protobuf v1.36.3/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
1 change: 1 addition & 0 deletions helper/schema/core_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ func (s *Schema) coreConfigSchemaAttribute() *configschema.Attribute {
Description: desc,
DescriptionKind: descKind,
Deprecated: s.Deprecated != "",
WriteOnly: s.WriteOnly,
}
}

Expand Down
19 changes: 19 additions & 0 deletions helper/schema/core_schema_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,25 @@ func TestSchemaMapCoreConfigSchema(t *testing.T) {
BlockTypes: map[string]*configschema.NestedBlock{},
}),
},
"write-only": {
map[string]*Schema{
"string": {
Type: TypeString,
Optional: true,
WriteOnly: true,
},
},
testResource(&configschema.Block{
Attributes: map[string]*configschema.Attribute{
"string": {
Type: cty.String,
Optional: true,
WriteOnly: true,
},
},
BlockTypes: map[string]*configschema.NestedBlock{},
}),
},
}

for name, test := range tests {
Expand Down
38 changes: 38 additions & 0 deletions helper/schema/grpc_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,32 @@ func (s *GRPCProviderServer) ValidateResourceTypeConfig(ctx context.Context, req
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
return resp, nil
}
if req.ClientCapabilities == nil || !req.ClientCapabilities.WriteOnlyAttributesAllowed {
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, validateWriteOnlyNullValues(configVal, schemaBlock, cty.Path{}))
}

r := s.provider.ResourcesMap[req.TypeName]

// Calling all ValidateRawResourceConfigFunc here since they validate on the raw go-cty config value
// and were introduced after the public provider.ValidateResource method.
if r.ValidateRawResourceConfigFuncs != nil {
writeOnlyAllowed := false

if req.ClientCapabilities != nil {
writeOnlyAllowed = req.ClientCapabilities.WriteOnlyAttributesAllowed
}

validateReq := ValidateResourceConfigFuncRequest{
WriteOnlyAttributesAllowed: writeOnlyAllowed,
RawConfig: configVal,
}

for _, validateFunc := range r.ValidateRawResourceConfigFuncs {
validateResp := &ValidateResourceConfigFuncResponse{}
validateFunc(ctx, validateReq, validateResp)
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, validateResp.Diagnostics)
}
}

config := terraform.NewResourceConfigShimmed(configVal, schemaBlock)

Expand Down Expand Up @@ -394,6 +420,9 @@ func (s *GRPCProviderServer) UpgradeResourceState(ctx context.Context, req *tfpr
// Normalize the value and fill in any missing blocks.
val = objchange.NormalizeObjectFromLegacySDK(val, schemaBlock)

// Set any write-only attribute values to null
val = setWriteOnlyNullValues(val, schemaBlock)

// encode the final state to the expected msgpack format
newStateMP, err := msgpack.Marshal(val, schemaBlock.ImpliedType())
if err != nil {
Expand Down Expand Up @@ -738,6 +767,7 @@ func (s *GRPCProviderServer) ReadResource(ctx context.Context, req *tfprotov5.Re

newStateVal = normalizeNullValues(newStateVal, stateVal, false)
newStateVal = copyTimeoutValues(newStateVal, stateVal)
newStateVal = setWriteOnlyNullValues(newStateVal, schemaBlock)

newStateMP, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
if err != nil {
Expand Down Expand Up @@ -937,6 +967,9 @@ func (s *GRPCProviderServer) PlanResourceChange(ctx context.Context, req *tfprot
plannedStateVal = SetUnknowns(plannedStateVal, schemaBlock)
}

// Set any write-only attribute values to null
plannedStateVal = setWriteOnlyNullValues(plannedStateVal, schemaBlock)

plannedMP, err := msgpack.Marshal(plannedStateVal, schemaBlock.ImpliedType())
if err != nil {
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
Expand Down Expand Up @@ -1184,6 +1217,8 @@ func (s *GRPCProviderServer) ApplyResourceChange(ctx context.Context, req *tfpro

newStateVal = copyTimeoutValues(newStateVal, plannedStateVal)

newStateVal = setWriteOnlyNullValues(newStateVal, schemaBlock)

newStateMP, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
if err != nil {
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
Expand Down Expand Up @@ -1305,6 +1340,9 @@ func (s *GRPCProviderServer) ImportResourceState(ctx context.Context, req *tfpro
newStateVal = cty.ObjectVal(newStateValueMap)
}

// Set any write-only attribute values to null
newStateVal = setWriteOnlyNullValues(newStateVal, schemaBlock)

newStateMP, err := msgpack.Marshal(newStateVal, schemaBlock.ImpliedType())
if err != nil {
resp.Diagnostics = convert.AppendProtoDiag(ctx, resp.Diagnostics, err)
Expand Down
Loading
Loading