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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

command: add TF_CLI_ARGS to specify additional CLI args #11922

Merged
merged 6 commits into from
Feb 13, 2017
Merged

Conversation

mitchellh
Copy link
Contributor

This introduces an env var TF_CLI_ARGS that can be used to specify additional CLI args.

The primary use for this is easier CI and automation integration.

The flag is parsed like a shell line, so the value TF_CLI_ARGS="-foo 'bar baz'" will turn into ["-foo", "bar baz"] internally.

The additional args are appended before any args specified on the CLI after the command. So, if you invoke TF_CLI_ARGS="-force" terraform apply -input=false then it is equivalent to specifying terraform apply -force -input=false. This ordering forces the CLI args to take precedent over the env var.

Updating the docs now.

@mitchellh mitchellh added this to the Terraform 0.9 milestone Feb 13, 2017
main.go Outdated
// after the first non-flag arg.
idx := -1
for i, v := range args {
if v[0] != '-' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An arg can be 0 length -- even more likely in an automated system like TFE.
strings.HasPrefix?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really good catch, really good. Fixing now.

main.go Outdated
idx++

// Copy the args
newArgs := make([]string, len(args)+len(extra))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to worry about non-flag arguments in the TF_CLI_ARGS variable? ( I can't think of a case where it matters, just tossing out the question)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just make explicit that we insert the args right after the command. If that works, great, if that doesn't for them for normal args, then its documented.

@mitchellh mitchellh merged commit d2f9df3 into master Feb 13, 2017
@mitchellh mitchellh deleted the f-tf-cli branch February 13, 2017 23:26
@ghost
Copy link

ghost commented Apr 16, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants