command/init: Add a new flag -lockfile=readonly (#27630)

Fixes #27506

Add a new flag `-lockfile=readonly` to `terraform init`.
It would be useful to allow us to suppress dependency lockfile changes
explicitly.

The type of the `-lockfile` flag is string rather than bool, leaving
room for future extensions to other behavior variants.

The readonly mode suppresses lockfile changes, but should verify
checksums against the information already recorded. It should conflict
with the `-upgrade` flag.

Note: In the original use-case described in #27506, I would like to
suppress adding zh hashes, but a test code here suppresses adding h1
hashes because it's easy for testing.

Co-authored-by: Alisdair McDiarmid <alisdair@users.noreply.github.com>
This commit is contained in:
Masayuki Morita
2021-03-10 01:12:00 +09:00
committed by GitHub
parent 98899df514
commit 31a5aa1878
6 changed files with 278 additions and 3 deletions

View File

@@ -157,6 +157,14 @@ You can modify `terraform init`'s plugin behavior with the following options:
You can use `-plugin-dir` as a one-time override for exceptional situations,
such as if you are testing a local build of a provider plugin you are
currently developing.
- `-lockfile=MODE` Set a dependency lockfile mode.
The valid values for the lockfile mode are as follows:
- readonly: suppress the lockfile changes, but verify checksums against the
information already recorded. It conflicts with the `-upgrade` flag. If you
update the lockfile with third-party dependency management tools, it would be
useful to control when it changes explicitly.
## Running `terraform init` in automation