-
Notifications
You must be signed in to change notification settings - Fork 120
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
JSON Patch remove operations should consider and predict the item location on the list #2075
Comments
The
https://pkg.go.dev/encoding/json#Marshal
|
However even the raw patches are also sorted
|
Related to mattbaird/jsonpatch#30 |
From the patch remove examples above and from testing, it seems that AWSCC lexically sorts the remove operations in the patch document by index. The sorting order needs to be reversed so that AWSCC API can apply the remove operations properly, and according to the RFC6902 standard. AWSCC organizes operations in the patch document by remove and add operations (in that order) to add/replace/remove elements in the resource array. Example:
Desired resource configuration:
AWSCC patch document (remove, then add ops, lexically sorted by tag index):
Reverse sorting the patch remove operations and updating the resource manually through the cli yields the desired configuration in the Tags array:
|
Community Note
Description
AWSCC uses JSON patch to create delta changes between old and new state.
In the event when the new state will remove certain items for Attribute list, then it will produce multiple patch document such as:
In the AWS Cloud Control API (CCAPI), the patch operations is applied sequentially in the order that they appear in the patch document. Ref
As such, the patch document sent by the AWSCC provider to the CCAPI should be aware of relative positions of each item after subsequent patch operations.
Now imagine a situation where we have resource as follow
Resource before changes
Resource after changes
And let's assume we will remove / comment the first 3 tags
State file before changes
And assume the current state file as follows (redacted for brevity). Noticed that the order of the tags are a bit different from the HCL.
Order of patch operations
Using the earlier example of the patch order:
{"op":"remove","path":"/Tags/0"}
) there are only 5 Tags remaining in the list.{"op":"remove","path":"/Tags/4"}
), there are only 4 tags remaining in the list.{"op":"remove","path":"/Tags/6"}
)Example error logs:
New or Affected Resource(s)
References
The text was updated successfully, but these errors were encountered: