-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Multi-line diffs are not displayed properly sometimes #21817
Comments
Hi @lawliet89! Thanks for reporting this inconsistency. I think the reason for this difference is that these particular attributes are not being updated by this change, and so there isn't a pair of old and new values to show. Instead, it is just showing the old value, and thus Terraform uses a different codepath to render it. However, this all-on-one-line form isn't readable even if there are no changes, so I agree that Terraform ought to be consistently using the same formatting in both cases, which in this situation would mean just printing out the string over multiple lines even though it won't have any |
Hey @apparentlymart, there is a change in the diff I pasted above, though. It's under |
Ahh yes, I didn't spot that! That situation is a different one: in that case, Terraform is treating it as a change to the list rather than a change to the string, and Terraform uses an "element-oriented" diff (similar to the line-oriented diff it would normally use for multi-line strings not inside lists) and that diff algorithm can currently produce only "remove" and "add" changes, not edit-in-place changes, because it prefers to be able to show insertions into the list as additions rather than as edits to every subsequent unchanged element. To improve that one would require some additional functionality: the diff renderer would need to check any case where there's a removal immediately followed by an addition, see if both are strings, and then use a similarity heuristic to decide whether to transform that pair of changes into a single "update in-place" ( Unfortunately diffing algorithms tend to be very heuristic-based, because it needs to work backwards from just the old and new values to try to infer what change is likely to have caused that difference. We can tweak these tradeoffs to try to maximize readability in common cases, but it'll never be possible for it to get this totally right every time: there are lots of different ways to represent a change between two values. We'll see what we can do to improve this, though. Addressing the problem I described in my previous comment is likely to be more straightforward, so we may wish to address that one separately first. |
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. |
Terraform Version
Terraform Configuration Files
Relevant part: https://github.com/basisai/terraform-modules-gcp/blob/d7ff455/modules/consul/esm.tf
Expected Behavior
When showing the diff during plans, the multi-line strings in
values
should be displayed properly as per #15180Actual Behavior
The multi-line diffs are still displayed in an unreadable manner.
Steps to Reproduce
terraform plan
Additional Context
The relevant lines in the provider doesn't seem to be out of the ordinary. I am not sure if this is a problem with the provider itself, or with Terraform.
Or, it might be because the values were provided by the
template_file
data source.(EDIT: Replacing it with the
templatefile()
function does not make a difference.)I have seen proper diffs for other resources, though.
The text was updated successfully, but these errors were encountered: