Skip to content
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

Allow running terraform plan without persisting refreshed state #5952

Closed
wants to merge 1 commit into from

Conversation

toofishes
Copy link

In the case of running with a remote state file that one only has read-only
permissions on, terraform plan currently fails as it can't rewrite the remote
state file. Running with -refresh=false isn't a great option either, as then
the state we are planning from is not guaranteed to be current.

Add a new -persist flag that defaults to true to match existing behavior. If
this is set to false, we will continue to refresh remote state, but won't try
to write back our changes, allowing a read-only state file.

This addresses #2548.

In the case of running with a remote state file that one only has read-only
permissions on, `terraform plan` currently fails as it can't rewrite the remote
state file. Running with `-refresh=false` isn't a great option either, as then
the state we are planning from is not guaranteed to be current.

Add a new `-persist` flag that defaults to true to match existing behavior. If
this is set to false, we will continue to refresh remote state, but won't try
to write back our changes, allowing a read-only state file.

This addresses hashicorp#2548.
@toofishes
Copy link
Author

This is my first shot at a contribution to terraform. Please let me know if there are docs I missed, tests I should be writing, etc.!

Looking now, I'm guessing that to get this merged, I should update website/source/docs/commands/plan.html.markdown with the new flag, and possibly add some sort of test case to command/plan_test.go?

@apparentlymart
Copy link
Contributor

Thanks for writing this, @toofishes. It is an interesting idea.

One concern I have with this change is that I think it is in conflict with the change I'm trying to make in #4616, where a generated plan refers to a particular version of the state and Terraform will refuse to apply a plan that refers to an older state. If we allowed a plan to apply to a non-persisted refresh result, then on the subsequent apply the serial recorded in the current state wouldn't match.

Personally I think the mechanism in #4616 is important to avoid bad consequences of a real-world mistake I've made and seen people make several times. I wonder if we can adjust your proposed feature somehow so that it can coexist with the stale plan protection mechanism... but nothing came to my mind after some initial pondering. 😖

@radeksimko
Copy link
Member

Not persisting state on terraform plan is now the default behaviour.

See #6811

Is there still any value in turning off this behaviour - i.e. making plan behave exactly as it behaves in <= 0.6.16? 💭

@jen20
Copy link
Contributor

jen20 commented Jun 2, 2016

This feature was merged as #6811 after some reworking - thanks for opening a PR @toofishes! This behaviour is now standard in 0.7rc1

@jen20 jen20 closed this Jun 2, 2016
@toofishes
Copy link
Author

Thanks!

@ghost
Copy link

ghost commented Apr 25, 2020

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.

@ghost ghost locked and limited conversation to collaborators Apr 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants