hashicorp / hashicorp/terraform-exec
Open the API
- Dominant language
- Go
- Stars
- 786
- Forks
- 129
- PR merge metrics
- No merged PRs in 30d
Description
Hey 👋🏼
I wanted to ask for your thoughts on the "re-usability" of this tool.
I know that the maintainers/HashiCorp cannot implement everything that people want and it seems like adding commands is a long undertaking right now (from looking at the PRs). I understand that this tool may not be of highest priority etc., and people have something else to do.
Having said all of the above, would it be possible to e.g. open the API of the tool a little bit, so people can implement custom commands more easily downstream?
I am specifically looking at this which would already give me the ability to run arbitrary commands:
https://github.com/hashicorp/terraform-exec/blob/main/tfexec/cmd.go#L173-L196
For example, I want to add a `state pull` and a `state push` command for my purposes (I understand the potential complications of editing Terraform state), but I can't re-use this now and I am already using `terraform-exec` in an internal tool for state recovery 🙈 . So I'd generally like to continue to use it for the convenience that's already there. Due to the methods not being public, it leads to copy/paste on my end.
I am copying parts of `buildTerraformCmd` for some re-use, but that doesn't seem ideal:
```golang
func (tf *Terraform) buildTerraformCmd(ctx context.Context, mergeEnv map[string]string, args ...string) *exec.Cmd {
cmd := exec.Command(tf.execPath, args...)
cmd.Env = tf.buildEnv(mergeEnv)
cmd.Dir = tf.workingDir
tf.logger.Printf("[INFO] running Terraform command: %s", cmd.String())
return cmd
}
```
This leads to all of kinds of other code that I need to take parts from:
- `runTerraformCmdJSON`
- `runTerraformCmd` / `runTerraformCmdJSON`
- ...
Any thoughts on allowing for this use?
Contributor guide
Research direction
Start with tfexec/cmd.go, especially buildTerraformCmd and the referenced runTerraformCmd and runTerraformCmdJSON helpers. Trace how command construction, environment, working directory, logging, and execution are shared, then determine what public API shape the request requires for custom commands. Done would need an agreed API and corresponding implementation scope; the issue does not specify tests or acceptance criteria.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100