-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
helper/schema,terraform: handle computed primitives in diffs #9618
Conversation
Fixes #3309 There are two primary changes, one to how helper/schema creates diffs and one to how Terraform compares diffs. Both require careful understanding. == 1. helper/schema Changes helper/schema, given any primitive field (string, int, bool, etc.) _used to_ create a basic diff when given a computed new value (i.e. from an unkown interpolation). This would put in the plan that the old value is whatever the old value was, and the new value was the actual interpolation. For example, from #3309, the diff showed the following: ``` ~ module.test.aws_eip.test-instance.0 instance: "<INSTANCE ID>" => "${element(aws_instance.test-instance.*.id, count.index)}" ``` Then, when running `apply`, the diff would be realized and you would get a diff mismatch error because it would realize the final value is the same and remove it from the diff. **The change:** `helper/schema` now marks unknown primitive values with `NewComputed` set to true. Semantically this is correct for the diff to have this information. == 2. Terraform Diff.Same Changes Next, the way Terraform compares diffs needed to be updated Specifically, the case where the diff from the plan had a NewComputed primitive and the diff from the apply _no longer has that value_. This is possible if the computed value ended up being the same as the old value. This is allowed to pass through. Together, these fix #3309.
New: "${var.foo}", | ||
Old: "", | ||
New: "${var.foo}", | ||
NewComputed: true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This here is an actual test CHANGE versus a new change. The old behavior I believe to be incorrect since there was no way to tell that when applying, the EXACT value of ${var.foo}
wasn't expected... the diff comparison would simply never work.
Thanks! |
For #9618, we added the ability to ignore old diffs that were computed and removed (because the ultimate value ended up being the same). This ended up breaking computed list/set logic. The correct behavior, as is evident by how the other "skip" logics work, is to set `ok = true` so that the remainder of the logic can run which handles stuff such as computed lists and sets.
For hashicorp#9618, we added the ability to ignore old diffs that were computed and removed (because the ultimate value ended up being the same). This ended up breaking computed list/set logic. The correct behavior, as is evident by how the other "skip" logics work, is to set `ok = true` so that the remainder of the logic can run which handles stuff such as computed lists and sets.
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. |
Fixes #3309
There are two primary changes, one to how helper/schema creates diffs
and one to how Terraform compares diffs. Both require careful
understanding.
1. helper/schema Changes
helper/schema, given any primitive field (string, int, bool, etc.)
used to create a basic diff when given a computed new value (i.e. from
an unkown interpolation). This would put in the plan that the old value
is whatever the old value was, and the new value was the actual
interpolation. For example, from #3309, the diff showed the following:
Then, when running
apply
, the diff would be realized and you would geta diff mismatch error because it would realize the final value is the
same and remove it from the diff.
The change:
helper/schema
now marks unknown primitive values withNewComputed
set to true. Semantically this is correct for the diff tohave this information.
2. Terraform Diff.Same Changes
Next, the way Terraform compares diffs needed to be updated
Specifically, the case where the diff from the plan had a NewComputed
primitive and the diff from the apply no longer has that value. This
is possible if the computed value ended up being the same as the old
value. This is allowed to pass through.
Together, these fix #3309.