Fix aws_cloudfrontkeyvaluestore_keys_exclusive value JSON encoding bug#46900
Merged
YakDriver merged 1 commit intohashicorp:mainfrom Mar 17, 2026
Conversation
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.
Contributor
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
|
YakDriver
approved these changes
Mar 17, 2026
Member
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-keys-exclusive-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 16:54:50 Creating Terraform AWS Provider (SDKv2-style)...
2026/03/17 16:54:50 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_disappears
=== PAUSE TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_mutex
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange
=== CONT TestAccCloudFrontKeyValueStoreKey_basic
=== CONT TestAccCloudFrontKeyValueStoreKey_disappears
=== CONT TestAccCloudFrontKeyValueStoreKey_value
=== CONT TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic
--- PASS: TestAccCloudFrontKeyValueStoreKey_mutex (30.04s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_disappears (35.60s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_basic (46.37s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_basic (46.46s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_value (55.44s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_noRefreshNoChange (297.70s)
--- PASS: TestAccCloudFrontKeyValueStoreKey_Identity_ExistingResource_basic (302.52s)
PASS
ok github.com/hashicorp/terraform-provider-aws/internal/service/cloudfrontkeyvaluestore 309.449s
Contributor
|
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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #46899
Description
This PR fixes a bug in the
aws_cloudfrontkeyvaluestore_keys_exclusiveresource where string values were being incorrectly JSON-encoded, resulting in extra quotes being stored in AWS.Root Cause
When the resource was refactored to use AutoFlEx, the
flex.Expandandflex.Flattenfunctions introduced JSON encoding/decoding of string values. This caused values to be stored in AWS with extra quotes. For example, a configured value of"hello"would be stored in AWS as"\"hello\""(displayed as"hello"with quotes in the console).The bug was masked in tests because:
flex.ExpandJSON-encodes values during Create/Update operationsflex.FlattenJSON-decodes values during Read operationsChanges
Bug Fix
flex.Expandcalls insyncKeyValuePairs()method to prevent JSON encodingflex.Flattencalls inRead()method to prevent JSON decodingTesting Improvements
testAccCheckKeysExclusiveHasValues()helper function that directly calls AWS API to verify stored valuesTestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacterstest case with special characters (quotes, braces, backslashes)Testing
Ran acceptance tests with real AWS resources:
TestAccCloudFrontKeyValueStoreKeysExclusive_specialCharacters- PASS (26.53s)TestAccCloudFrontKeyValueStoreKeysExclusive_value- PASS (34.83s)Related Work
This is the same bug that was fixed in the
aws_cloudfrontkeyvaluestore_keyresource in PR #46898.Changelog