hashicorp / hashicorp/terraform-exec

Add an Init option for -lockfile=MODE

Open
#602 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
786
Forks
129
PR merge metrics
No merged PRs in 30d

Description

### Terraform CLI behavior

`terraform init` supports `-lockfile=MODE`. The currently documented mode is `readonly`, which suppresses dependency lock file changes while still verifying checksums. This is useful in automation that treats `.terraform.lock.hcl` as an explicitly managed input.

### terraform-exec gap

`Terraform.Init` does not currently expose this flag as an `InitOption`. Using `TF_CLI_ARGS_init` as a fallback is also unavailable through `Terraform.SetEnv`, because terraform-exec intentionally prohibits `TF_CLI_ARGS_*`.

### Proposed API

Expose the mode as an Init option, with a name that does not conflict with the existing `LockFile(bool)` option for `terraform providers mirror -lock-file`. For example:

```go
tf.Init(ctx, tfexec.LockFileMode("readonly"))
```

Terraform CLI documentation: https://developer.hashicorp.com/terraform/cli/commands/init#plugin-installation

I plan to submit a focused pull request with command-construction and end-to-end coverage.

Contributor guide

Open the contributing guide

Research direction

Start at Terraform.Init and the existing InitOption handling, especially LockFile(bool), to understand command construction and avoid the naming conflict. Add focused command-construction coverage and end-to-end coverage for the documented readonly mode; done means Terraform.Init accepts the new option and passes -lockfile=MODE to the CLI.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, terraform
Domain
cli
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
74/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.