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

Make persist interval configurable via environment variable #35116

Closed
wants to merge 1 commit into from

Conversation

alexott
Copy link
Contributor

@alexott alexott commented May 6, 2024

By default, the remote state backend persists state to the remote storage every 20 seconds—this value is hardcoded. But when the state is big (> 100Mb), this operation takes a long time and consumes a significant portion of these 20 seconds. This PR allows to make the persist interval configurable via the TF_BACKEND_PERSIST_INTERVAL_SECONDS environment variable, which allows to specify how often persistence should happen.

Please guide what part of the documentation needs to be updated to document it...

P.S. I thought about adding the ability to completely disable this persist interval like it's done when the remote execution backend is used - but this could be a topic for discussion.

Fixes #35115

Target Release

1.8.x

Draft CHANGELOG entry

NEW FEATURES | UPGRADE NOTES | ENHANCEMENTS | BUG FIXES | EXPERIMENTS

  • Added TF_BACKEND_PERSIST_INTERVAL_SECONDS environment variable to control persist interval in the remote state backend.

@crw crw added the enhancement label May 6, 2024
@brandonc brandonc self-assigned this May 8, 2024
@brandonc
Copy link
Contributor

brandonc commented May 8, 2024

@alexott Hey, Alex, thanks for this improvement. We'd like to enable this capability, but we need to account for allowing HCP Terraform to set a minimum interval in order to protect itself from state snapshot load. What I've found with your version is that I can override any interval our platform sets due to the way that backends are structured and used.

What I'm thinking is that this env variable that you've recommended can define the maximum interval to allow you to store state less frequently than what is set by HCP Terraform, which will now define the minimum interval. I'll incorporate your code in an upcoming PR of my own.

@alexott
Copy link
Contributor Author

alexott commented May 10, 2024

@brandonc hmmm, as I saw in the code, this change doesn't affect the behavior of HCP Terraform, etc. It just allows to specify persist interval via environment variable instead of using the hardcoded one... No other places are affected. Of course, if the new behavior exists, then it's just a way a previous version was implemented...

But anyway, I'm happy if you implement something else that will allow to reach the desired behavior - do you have any ETA on that?

@brandonc
Copy link
Contributor

@alexott It's a little roundabout, but the gist is that HCP Terraform ends up running terraform using a local backend, and users may set environment variables in that context. ETA probably next week or two, as it's prioritized in with some other stuff.

@alexott
Copy link
Contributor Author

alexott commented May 14, 2024

@brandonc do you need any help from me to speedup this implementation?

@brandonc
Copy link
Contributor

@alexott not at this time. The work is prioritized and narrowly scoped so it shouldn't be too much of a wait

@sebasslash
Copy link
Contributor

Hey Alex! Thanks again for your contribution here. Going to close this PR in favor of #35176 which includes some minor refactoring. All credit goes to you! 👍

@sebasslash sebasslash closed this May 17, 2024
@brandonc
Copy link
Contributor

@alexott We discovered that the maximum interval was already implemented but opened a new PR to move ENV evaluation. Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make persistence interval configurable for the remote state backend
4 participants