Terraform does not prompt when value is not defined in a variable - Running from Docker container

We have decided to use Terraform from docker containers instead of using our local environment, this way we can keep different versions of Terraform running for different projects and it’s also easier to onboard people in projects but we currently have the following scenario that seems to not work as we expected.

When we want the user to provide a value to a variable through the command line, this is not happening. Terraform doesn’t prompt the user for it.
Is this directly related to be running Terraform in a docker container? Is there any solution for this?

We have ran Terraform from our local environment and in this case it prompts for the user input.

I did a quick test and get prompted. What docker image and run command are you using?

Here is my output:

docker run -v $PWD:/files -i -t hashicorp/terraform:light apply files
var.test
  Enter a value: foo


Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

test = foo

We are using the following command through a Makefile.
docker run --rm -ti -e TF_LOG -v <PATH_TO_PRJECT> --workdir <ENVIRONMENT> hashicorp/terraform:0.11.11 plan -out terraform.tfplan -parallelism=100

Can you make a gist of your Makefile and a simple example of tf code to reproduce this error? This works for me:

cat Makefile
run: 
    docker run --rm -ti -e TF_LOG -v $(shell pwd):/files --workdir /files hashicorp/terraform:0.11.11 plan -out terraform.tfplan -parallelism=100

Here is a gist: https://gist.github.com/mmingorance-dh/be1702d791c9ef91d6aca074c70fadcb

An example code would be this: https://github.com/mmingorance-dh/terraform-prompt-example

Thanks for helping!

That’s a pretty complex makefile and code. Can you reproduce the issue with the simple explain I posted?

I just found the problem.

I checked with running the docker command as you mentioned and it worked, then when I looked closely to the Makefile, I saw that we run terraform validate right before terraform plan and that’s the reason why it fails and never gets to prompt me for the value.

Sorry for the inconvenience and thank you very much for your help

1 Like