-
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
terraform: destroy node should not create #1046
Conversation
var diffVal *InstanceDiff | ||
if n.Diff != nil { | ||
diffVal = *n.Diff | ||
} |
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 change allows us to EvalWriteDiff
a nil
value.
Unrelated CI errors... pass locally:
|
Also, @catsby's acceptance test now passes. |
I'm going to merge this now because this fixes a pretty critical bug and I don't want anyone running master to run into it. |
terraform: destroy node should not create
} | ||
|
||
if !reflect.DeepEqual(output, tc.Output) { | ||
t.Fatalf("bad: %d\n\n%#v", i, output) |
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.
@mitchellh We've talked about this a bit, and I know you were flying forward on a critical bug here so I'm not talking about this specific instance, but for new test case harnesses can we agree to prefer:
- Maps with test names instead of integer indexes
- Failure output that includes test name, expected output, and actual output (instead of just "bad: actual")
Perhaps I am a dummy, but for tests written in this style it takes me a lot of mental ramp time to be able to jump in and read these coherently. My theory is that a few tweaks today can provide compounding savings of future developer time.
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.
So I've been thinking about it in each instance, and the main thing for is "does the actual test case provide information vs. what I can provide here" and in this case I figured that the tc.Input
and output
give you everything you need to fix the bug. If the test itself is wrong then yes, you'd have to count the indices, but I'm assuming the test case itself is correct and won't need to be changed and that if you're fixing an implementation bug then this would catch it.
So, I'd say in this case, option 2 is best.
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.
I figured that the tc.Input and output give you everything you need to fix the bug
Thing is, you don't get input and output... you get something like:
--- FAIL bad: 2
&InstanceDiff{},
As a future human encountering this, I know I broke something, but how am I to go about figuring out what I broke?
If instead, the output was
--- FAIL "preserves Destroy: false"
expected: &InstanceDiff{Destroy: false},
got: &InstanceDiff{},
I immediately know what I broke.
I am attempting to optimize for Cost for Future Human Reloading of this Context into their Brains (CFHRCB). 😀
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. |
/cc @catsby @phinze: This is a doozy, but is a good example of the new refactor and how it comes into play in fixing bugs.
@catsby ran into a "diffs not matching" error on an acceptance test. Little did I know it'd lead me down this rabbit hole. Basically what was going on was that the acceptance test did a create before destroy (wow!) and in create before destroy, the destroy nodes were actually also doing the destroy. Shockingly, the Terraform core tests still passed. Still looking into how to make that not happen... but in the mean time, this PR.
I want to note that this bug was entirely introduced by the refactor merge, and is therefore not present in 0.3.7. This is just a master-only bug.
Here are the major changes made in this:
EvalFilterDiff
to filter out only the destroy part, and not the creation part. This is the critical change.EvalRequireState
to not callApply
on the provider if there isn't even a state to destroy. This is an optimization but some core tests depend on this behavior. Fair enough.EvalWriteDiff
with a nil diff. This fixes an issue where during create-before-destroy, the creation was keeping the diff around (not writing nil diff), and the destroy node was doing a destroy then re-create. I feel this logic is more correct anyways: the diff is gone once the apply is done.More comments inline in the code to better explain.