Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open the API #279

Open
till opened this issue Feb 19, 2022 · 3 comments
Open

Open the API #279

till opened this issue Feb 19, 2022 · 3 comments

Comments

@till
Copy link

till commented Feb 19, 2022

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:

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?

@kmoe
Copy link
Member

kmoe commented Apr 12, 2022

Thanks for the well-written feature request and your patience while we get the subcommands implemented.

Our aim with terraform-exec is to have support for all Terraform subcommands which make sense in this API. The library is intended to be opinionated about how you use those subcommands and flags. state pull and state push are perfectly reasonable and those PRs should be merged soon.

If tfexec had implemented all subcommands you want to use, would you still want this feature?

@till
Copy link
Author

till commented Apr 14, 2022

@kmoe Probably not. At least I can't think of a use-case beyond extending or changing the API.

IMO it wouldn't hurt and it would allow for free use?

But assuming everything is implemented there are of course less reasons.

@draeron
Copy link

draeron commented Feb 8, 2023

supporting arbitrary arguments would enable some options having to code every possible options

as an example, I need to add the -compact-warnings on a plan but can't because it's not supported.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants