-
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
Feature request: Generate .terraform.lock.hcl including zh and h1 hash values for given platforms from required_providers block without downloading providers and modules #27264
Comments
This would be very helpful for renovate too, see renovatebot/renovate#7895 |
Hi @minamijoyo! Thanks for raising this. We have a few different technical constraints to work through in order to achieve what you described here. I'm going to describe them here just to kick off a potential discussion about what technical solutions might change these constraints, and not meaning to say that we don't want to achieve these goals. Terraform Registry only supports the "ziphash" (
|
@apparentlymart Thank you for your comprehensive explanation. Since the Terraform Registry cannot return h1 hashes for now, it's unavoidable to download each provider package at least once. With that in mind, I would like to discuss a short term workaround without changing the registry protocol. My top priority is suppressing the unexpected git diff caused by I came up with some ideas. Let me share them: (1) Use h1 hashes only in a lock file (2) Calculate zh hashes if a mirror contains a zip file (3) Add zh hashes without download Do these conflict with the current security model or other constraints? |
(4) Add a new environment variable or CLI flag to suppress updating the lockfile I found this discussion: #27241 (comment)
Even though this doesn't resolve all problems described in my issue, I think it has the same effect as (1) in my workflow. @apparentlymart Is it acceptable? If it's worth considering adding a new option to suppress updating the lockfile, I'll open a new feature request. Thanks! |
Hi @minamijoyo, Focusing on your latest comment only for now (I'll review the other ideas in more detail soon), I think it could be reasonable to add a new option to My initial idea for that interface would be I think the main requirement for that option is that installation can succeed as long as all packages can be verified with information already recorded in the lock file. The option would disable Terraform from updating the file to record any new information it learned (such as a hash using a new scheme) but Terraform would still rely on and check against the information already recorded. It seems to follow then that |
I've opened a new feature request for |
Is there any progress on this issue? I find that
It may work on the next attempt, or it fails on a different provider. Even if it's not possible to eliminate all the downloads, it would be a major improvement if only the missing providers were downloaded. Most of the time only one provider at a time is getting upgraded, so the hashes for the others are already in the lockfile. It shouldn't be necessary to download those again. |
For those who struggle to update multiple .terraform.lock.hcl at scale After more than two years of waiting for Terraform Registry protocol change with no progress, I finally implemented lock file updates in tfupdate myself without Terraform CLI, knowing that it is implementation details of Terraform. The tfupdate v0.7.0 introduced a new tfupdate lock command, which parses the required_providers block in your configuration, downloads provider packages, and calculates hash values under the hood. The most important point is that it caches calculated hash values in memory, giving us a huge performance advantage when updating multiple directories using the recursive option. For details, see minamijoyo/tfupdate#90 I know this isn't the ideal solution, but it helps me get things done in practice. I'll keep this issue open, hoping that the Terraform Registry protocol will improve in the future. |
I just created this ~50-line bash script to update all |
Current Terraform Version
Use-cases
I have 200+ root modules and I'm automating a provider version up workflow in CI with tfupdate, which updates all version constraints in Terraform configurations recursively. My laptop is macOS and CI is Linux, so I want to pre-populate hash values for all platforms I need in the workflow to avoid a checksum mismatch error.
I'm looking for an efficient way to maintain
.terraform.lock.hcl
for multiple root modules and platforms environments.Attempted Solutions
For downloading providers:
As you know, there are two hash formats, that is, zh and h1, and zh is recorded only when a provider zip package is downloaded from Terraform Registry. I want to avoid redundant downloads because I have a lot of root modules, so I tried to create a local filesystem mirror with the
terraform providers mirror
command at git project repository root, and then generated lock files at each sub directory with theterraform providers lock
command using the mirror. It recorded only h1 hash values. It's ok.I wrote a script to generate
.terraform.lock.hcl
for multiple directories and platforms.However, with the lock file recorded only h1 hash values, if I run
terraform init
without any mirror or cache, the init command adds zh hash values to the lock file. It causes an unexpected lock file change.I expect
terraform init
without the-upgrade
flag not to update the existing lock file, becauseterraform init
is essential command for all workflows and I think it's not desirable to cause a git diff unexpectedly. Is it intentional by design or a bug?Pre-populating zh hash values requires redundant downloads, so I want to avoid it. My pain points are:
If my understanding is correct, it would be great if the Terraform Registry returns not only zh hash values, but also h1 hash values for all platforms without download.
For downloading modules:
If a root module depends on other modules, the
terraform providers lock
command requiresterraform init
. I understand selecting a correct version needs all module contents for completeness.However, before Terraform v0.14, there was no lock file, so I've already defined all provider dependencies I need in the
required_providers
block at each root module. In that case, it's not always necessary to get all modules because I know it. It works but it's inefficient. It would be great if we can have a shallow check option at own risk.Proposal
Allow the
terraform providers lock
command to generate.terraform.lock.hcl
including zh and h1 hash values for given platforms fromrequired_providers
block without downloading providers and modules.References
Related to:
The text was updated successfully, but these errors were encountered: