terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Make persist interval configurable via environment variable

Open alexott opened this issue 1 year ago • 5 comments

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.

alexott avatar May 06 '24 07:05 alexott

@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.

brandonc avatar May 08 '24 21:05 brandonc

@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?

alexott avatar May 10 '24 10:05 alexott

@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.

brandonc avatar May 10 '24 17:05 brandonc

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

alexott avatar May 14 '24 15:05 alexott

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

brandonc avatar May 14 '24 16:05 brandonc

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 avatar May 17 '24 16:05 sebasslash

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

brandonc avatar May 17 '24 16:05 brandonc

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

github-actions[bot] avatar Jun 18 '24 02:06 github-actions[bot]