r/aws_cloudfrontkeyvaluestore_key: Fix value JSON encoding issue#46898
Conversation
Fixes the bug where string values were being JSON-encoded, resulting in extra quotes in the stored values. For example, `value = "asdf"` was being stored as `"asdf"` (with extra quotes) instead of `asdf` in AWS CloudFront KeyValueStore. **Root Cause:** The bug was introduced in commit c69a552 when the resource was refactored to use AutoFlEx (fwflex.Expand/Flatten). AutoFlEx was JSON-encoding the Value field during Create/Update and JSON-decoding it during Read, creating a symmetrical encode/decode cycle that masked the issue in tests. **Changes:** 1. key.go: Manually set Value field in Create, Update, and Read operations to bypass AutoFlEx JSON encoding/decoding 2. key_test.go: Added testAccCheckKeyHasValue helper that directly calls AWS API to verify stored values (not just Terraform state) 3. key_test.go: Enhanced existing tests with AWS API validation 4. key_test.go: Added TestAccCloudFrontKeyValueStoreKey_specialCharacters to test values with quotes and special characters **Testing:** All acceptance tests pass with real AWS resources: - TestAccCloudFrontKeyValueStoreKey_basic - TestAccCloudFrontKeyValueStoreKey_value - TestAccCloudFrontKeyValueStoreKey_specialCharacters Closes hashicorp#46897
Community GuidelinesThis comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀 Voting for Prioritization
Pull Request Authors
|
|
✅ Thank you for correcting the previously detected issues! The maintainers appreciate your efforts to make the review process as smooth as possible. |
|
Added changelog entry in commit 338b48f |
Fixes hashicorp#46899 When the resource was refactored to use AutoFlEx, the flex.Expand/flex.Flatten functions introduced JSON encoding/decoding of string values. This caused values to be stored in AWS with extra quotes (e.g., "hello" stored as "\"hello\""). The bug was masked in tests because: - flex.Expand JSON-encodes values during Create/Update - flex.Flatten JSON-decodes values during Read - This symmetrical encode/decode cycle made Terraform state appear correct - Tests only verified Terraform state, not actual AWS values Changes: - Manually set Value fields in syncKeyValuePairs() after flex.Expand to avoid JSON encoding - Manually set Value fields in Read() after flex.Flatten to avoid JSON decoding - Added testAccCheckKeysExclusiveHasValues() helper to verify actual AWS values - Added TestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacters test This is the same bug that was fixed in aws_cloudfrontkeyvaluestore_key resource in PR hashicorp#46898.
YakDriver
left a comment
There was a problem hiding this comment.
LGTM 🎉
% make t T=TestAccCloudFrontKeyValueStoreKey_ K=cloudfrontkeyvaluestore
make: Verifying source code with gofmt...
==> Checking that code complies with gofmt requirements...
make: Running acceptance tests on branch: 🌿 f-cloudfrontkeyvaluestore-key-value-encoding-fix 🌿...
TF_ACC=1 go1.25.8 test ./internal/service/cloudfrontkeyvaluestore/... -v -count 1 -parallel 20 -run='TestAccCloudFrontKeyValueStoreKey_' -timeout 360m -vet=off
2026/03/17 15:02:08 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/17 15:02:08 Initializing Terraform AWS Provider (SDKv2-style)...
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== PAUSE TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== RUN TestAccCloudFrontKeyValueStoreKey_basic
=== PAUSE TestAccCloudFrontKeyValueStoreKey_basic
=== RUN TestAccCloudFrontKeyValueStoreKey_mutex
=== PAUSE TestAccCloudFrontKeyValueStoreKey_mutex
=== RUN TestAccCloudFrontKeyValueStoreKey_value
=== PAUSE TestAccCloudFrontKeyValueStoreKey_value
=== RUN TestAccCloudFrontKeyValueStoreKey_specialCharacters
=== PAUSE TestAccCloudFrontKeyValueStoreKey_specialCharacters
=== RUN TestAccCloudFrontKeyValueStoreKey_disappears
=== PAUSE TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_mutex
=== CONT TestAccCloudFrontKeyValueStoreKey_specialCharacters
=== CONT TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== CONT TestAccCloudFrontKeyValueStoreKey_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_value
--- PASS: TestAccCloudFrontKeyValueStoreKey_specialCharacters (33.82s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_disappears (34.87s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_basic (42.09s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_basic (43.97s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_value (44.72s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_mutex (45.88s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange (344.87s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic (345.94s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore 352.681s|
Warning This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them. Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed. |
|
This functionality has been released in v6.37.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you! |
Fixes #46897
Description
Fixes the bug where string values in
aws_cloudfrontkeyvaluestore_keyresource were being JSON-encoded, resulting in extra quotes in the stored values.For example:
value = "asdf"was stored as"asdf"(with extra quotes) in AWSvalue = "asdf"is stored asasdf(plain string) in AWSRoot Cause
The bug was introduced in commit c69a552 when the resource was refactored to use AutoFlEx (
fwflex.Expand/fwflex.Flatten).The problem:
fwflex.ExpandJSON-encodes theValuefield → AWS stores"asdf"instead ofasdffwflex.FlattenJSON-decodes it back → Terraform state showsasdf(correct)Changes
internal/service/cloudfrontkeyvaluestore/key.go
Valueafterfwflex.Expandto bypass JSON encodingValueafterfwflex.Expandto bypass JSON encodingValueafterfwflex.Flattento bypass JSON decodinginternal/service/cloudfrontkeyvaluestore/key_test.go
testAccCheckKeyHasValue- Directly calls AWS API to verify stored values (not just Terraform state)TestAccCloudFrontKeyValueStoreKey_basicandTestAccCloudFrontKeyValueStoreKey_valueTestAccCloudFrontKeyValueStoreKey_specialCharacters- Tests values with quotes, braces, and other special charactersTesting
All acceptance tests pass with real AWS resources:
The new test helper (
testAccCheckKeyHasValue) ensures that the actual values stored in AWS match expectations, preventing this type of bug from reoccurring.References
Output from acceptance testing: