-
Notifications
You must be signed in to change notification settings - Fork 9.5k
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: remove state from validate
graph walk
#26063
Conversation
A recent change to the backend had a side effect of causing all input vars to be requested twice (due to two calls to `contextDirect`) and provider input values to be omitted entirely (those were populated during Validate, but Validate was called on the "extra" context and not the returned context). This PR adds a Context.StatelessCopy function which returns a nearly-identical copy of a terraform.Context with the state "zeroed out", which can then be Validate()d. A better, future refactor should remove the need for this function and instead modify Validate() itself to ignore state. Fixes #26027 I've added tests that confirm both behaviors; I am not sure what test covers the behavior that lead to this change in the first place but I did verify locally using the reproduction in the original PR.
Codecov Report
|
// This will (helpfully) panic if more than one variable is requested during plan: | ||
// https://github.com/hashicorp/terraform/issues/26027 | ||
close := testInteractiveInput(t, []string{"bar"}) |
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.
Thanks for the comment!
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.
LGTM! Thanks for finding a better spot to remove the state from Validate.
terraform/context_apply_test.go
Outdated
// from the targeted resource | ||
if len(mod.OutputValues) != 0 { | ||
t.Fatalf("expected 0 outputs, got: %#v", mod.OutputValues) | ||
// the root output should not get removed |
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.
Maybe change this comment to indicate that we're verifying the current status-quo, but it's not necessarily incorrect to remove the output if we can manage it in the future.
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. |
This pull reverts a recent change to
backend/local
which created two context, one with and one without state. Instead I have removed the state entirely from the validate graph (by explicitly passing astates.NewState()
).This changed caused a test failure, which (ty so much for the help) @jbardin discovered was inaccurate all along: the test's call to
Validate()
was actually what was removing the output from state, which should not have been happening duringValidate
anyway. The new expected test output matches terraform's actual behavior on the command line: if you use -target to destroy a resource, an output that references only that resource is not removed from state.This includes two tests to cover the expected behavior:
TestPlan_varsUnset
has been updated so it will panic if it gets more than one request to input a variableTestPlan_providerArgumentUnset
covers terraform not properly storing provider args from command line when there is no provider block #26035Fixes #26035, #26027