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

TF_CLI_ARGS with -var-file causes terraform plugin error. #14847

Closed
ephur opened this issue May 25, 2017 · 19 comments · Fixed by #17400
Closed

TF_CLI_ARGS with -var-file causes terraform plugin error. #14847

ephur opened this issue May 25, 2017 · 19 comments · Fixed by #17400
Labels
bug cli v0.9 Issues (primarily bugs) reported against v0.9 releases v0.10 Issues (primarily bugs) reported against v0.10 releases v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases

Comments

@ephur
Copy link

ephur commented May 25, 2017

Terraform Version

 terraform -v
Terraform v0.9.5

Affected Resource(s)

Please list the resources as a list, for example:

  • provider.terraform
  • provider.aws

This looks like an issue with handling of TF_CLI_ARGS

Terraform Configuration Files

Not provided.

Debug Output

snipped a lot of stuff out of the log to what appear to be relevant items, can't expose configuration details that much of debug log exposes.

https://gist.github.com/anonymous/39e50ec98e78b4d66f97e17af3af0d25

Expected Behavior

The plan should have been executed by just executing terraform plan with the environment variables set.

Actual Behavior

The following errors were observed and the plan is not executed. Unsetting environment variable and then

Error asking for user input: 2 error(s) occurred:

* provider.aws: plugin exited before we could connect
* provider.terraform: plugin exited before we could connect

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. export TF_CLI_ARGS="-var-file=../../global.tfvars -var-file=../../dev.tfvars"
  2. terraform apply
  3. Observe error:
Error asking for user input: 2 error(s) occurred:

* provider.terraform: plugin exited before we could connect
* provider.aws: plugin exited before we could connect
  1. unset TF_CLI_ARGS
  2. terraform apply -var-file=../../global.tfvars -var-file=../../dev.tfvars
  3. After unsetting the env var the command executes fine and the plan completes.

Important Factoids

Are there anything atypical about your accounts that we should know? For example: Running in EC2 Classic? Custom version of OpenStack? Tight ACLs?

References

@ephur
Copy link
Author

ephur commented Jun 8, 2017

Confirmed this still exists in 0.9.8

@antonbabenko
Copy link
Contributor

It still exists in 0.9.10. All I wanted was to disable colors when running on CI - TF_CLI_ARGS="-no-color"

@johnmarcou
Copy link

johnmarcou commented Jul 13, 2017

I was about to open an issue, but I found that one.
I confirm I had that issue as well.

Here the information:

[moby] ~/Terraform/empty # ls
main.tf
[moby] ~/Terraform/empty # cat main.tf
data "template_file" "config-01" {
  template = "$${hostname}"

  vars {
    hostname = "infra-01"
  }
}

[moby] ~/Terraform/empty # terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.

data.template_file.config-01: Refreshing state...
No changes. Infrastructure is up-to-date.

This means that Terraform did not detect any differences between your
configuration and real physical resources that exist. As a result, Terraform
doesn't need to do anything.

[moby] ~/Terraform/empty # TF_CLI_ARGS="-no-color" terraform plan
Error asking for user input: 1 error(s) occurred:

* provider.template: plugin exited before we could connect

[moby] ~/Terraform/empty # terraform version
Terraform v0.9.11


[moby] ~/Terraform/empty # uname -a
Darwin macjohn.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64

@jlambert121
Copy link

We are having this issue as well. Granted it's 0.9.9. I have a trace log of this I'm happy to send privately if that is of value.

@reimerp
Copy link

reimerp commented Sep 21, 2017

confirmed against 0.10.6

@agyepiga
Copy link

I am having the same issue in Terraform v0.10.7

@DBarthe
Copy link

DBarthe commented Jan 31, 2018

Happening in v0.11.2 when the terraform script contains provisioner 'file' or 'remote-exec' and with TF_CLI_ARGS=-no-color

@johnmarcou
Copy link

johnmarcou commented May 4, 2018

This is what I am doing as a workaround, loading this in my bashrc.

_terraform() {
  terraform $@ -var-file ~/.terraform.tfvars
}

alias terraform='_terraform'

If you have a better suggestion ?

@evanstachowiak
Copy link

Confirmed also in v0.11.7

@lorengordon
Copy link
Contributor

Looks like I can workaround this problem using the command-specific variations...

export TF_CLI_ARGS_apply="-no-color"
export TF_CLI_ARGS_plan="-no-color"

@rwillians
Copy link

rwillians commented Nov 30, 2018

It also affects terraform output (Terraform v0.11.10).
Whatever arguments and options you pass, the command always returns its help message.

Btw, @lorengordon's workaround worked for me.

kaii-zen pushed a commit to kaii-zen/xinomorf that referenced this issue Dec 15, 2018
@ajorpheus
Copy link

ajorpheus commented May 14, 2019

Setting the CLI args per commands seems to be fine :

# Create a single var to hold the common CLI args
export TF_CLI_CUSTOM_ARGS="-var-file=$HOME/.aws/terraform.tfvars"

# Note that the variable expansion happens eagerly, so everytime you change the value of the above, need to re-run this command
for command in validate apply plan ; \
do export TF_CLI_ARGS_${command}="$TF_CLI_CUSTOM_ARGS"; done

# Check the value of the CLI args
set | grep -i "TF_CLI"

@pecigonzalo
Copy link

This is opened since 2017, is there any roadmap?

@rptaylor
Copy link

rptaylor commented Jun 8, 2019

Still happening in 0.11.13

@emcniece
Copy link

Arrived here after installing https://github.com/sickill/stderred to get some stderr visibility. Colours break something in here.

@hashibot hashibot added the v0.11 Issues (primarily bugs) reported against v0.11 releases label Aug 29, 2019
etwillbefine added a commit to goci-io/docker-terraform-images that referenced this issue Sep 8, 2019
@jlsan92
Copy link

jlsan92 commented Oct 27, 2019

Hello everyone! Any plan to fix this? Still happening, TF v0.12.12 🙏

@luk2302
Copy link

luk2302 commented Nov 5, 2019

Still happens in 0.12.13. The core problem itself is a Wrong number of args of a spawned child process. Terraform starts its providers and provisioners as child processes and communicates with those processes afterwards. Note that this issue does not have anything to do with -var-file but with basically anything in TF_CLI_ARGS, in our case the contents are -no-color. The output we see after setting TF_LOG=TRACE is:

2019/11/05 09:50:44 [TRACE] LoadSchemas: retrieving schema for provisioner "local-exec"
2019-11-05T09:50:44.846+0100 [DEBUG] plugin: starting plugin: path=/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform args=[/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform, internal-plugin, provisioner, local-exec]
2019-11-05T09:50:44.849+0100 [DEBUG] plugin: plugin started: path=/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform pid=35888
2019-11-05T09:50:44.849+0100 [DEBUG] plugin: waiting for RPC address: path=/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform
2019-11-05T09:50:44.870+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [INFO] Terraform version: 0.12.13
2019-11-05T09:50:44.870+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [INFO] Go runtime version: go1.12.9
2019-11-05T09:50:44.870+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [INFO] CLI args: []string{"/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform", "internal-plugin", "provisioner", "local-exec"}
2019-11-05T09:50:44.870+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [DEBUG] Attempting to open CLI config file: /Users/lukasrinke/.terraformrc
2019-11-05T09:50:44.870+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2019-11-05T09:50:44.871+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [INFO] TF_CLI_ARGS value: "-no-color"
2019-11-05T09:50:44.871+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 [INFO] CLI command args: []string{"internal-plugin", "-no-color", "provisioner", "local-exec"}
2019-11-05T09:50:44.871+0100 [DEBUG] plugin.terraform: 2019/11/05 09:50:44 Wrong number of args; expected: terraform internal-plugin pluginType pluginName
2019-11-05T09:50:44.872+0100 [DEBUG] plugin: plugin process exited: path=/usr/local/Cellar/tfenv/1.0.2/versions/0.12.13/terraform pid=35888 error="exit status 1"

The code responsible for handling, splitting and merging (!) the command line arguments and env variables is wrappedMain in main.go. Run in internal_plugin.go then expects a set amount of aruments but receives an extra one, namely -no-color.

// Prefix the args with any args from the EnvCLI
args, err = mergeEnvArgs(EnvCLI, cliRunner.Subcommand(), args)
with
EnvCLI = "TF_CLI_ARGS".

For the latest version of TF the log form the main process is no longer plugin exited before we could connect but Error: Failed to instantiate provisioner "local-exec" to obtain schema: Unrecognized remote plugin message:

Minimal main.tf to reproduce:
resource "null_resource" "null" { provisioner "file" { } }

Note that this affects everything that goes through internal_plugin.go which I suspect are all provisioners.

@danieldreier
Copy link
Contributor

I have also reproduced this on a local build of the current tip of master for 0.12.18 with:

TF_CLI_ARGS="-no-color" terraform apply

for a trivial null resource tf config:

resource "null_resource" "example" {
  provisioner "local-exec" {
    command = "true"
  }
}

Many thanks to @luk2302 for digging into why this is happening.

@danieldreier danieldreier added the v0.10 Issues (primarily bugs) reported against v0.10 releases label Dec 4, 2019
@danieldreier danieldreier added v0.12 Issues (primarily bugs) reported against v0.12 releases v0.9 Issues (primarily bugs) reported against v0.9 releases labels Dec 4, 2019
@ghost
Copy link

ghost commented Mar 28, 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 Mar 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug cli v0.9 Issues (primarily bugs) reported against v0.9 releases v0.10 Issues (primarily bugs) reported against v0.10 releases v0.11 Issues (primarily bugs) reported against v0.11 releases v0.12 Issues (primarily bugs) reported against v0.12 releases
Projects
None yet
Development

Successfully merging a pull request may close this issue.