Terraform apply and get value in prompt

I have variable.tf and ,main.tf , when I use terrform apply , terraform wants to get data in command line:

$ terraform apply
var.ENVIRONMENT_CONTEXT__VARIABLES__IPV4_NETMASK
  The IPv4 subnet mask, in bits (example: 24 for 255.255.255.0).

  Enter a value:

How to tell terraform to discard get value?

If there is a variable defined without a default and the value isn’t obtainable from elsewhere (i.e. being set on the command line, via an environment variable or from a tfvars file) it will prompt you to enter it.

If you don’t want it to prompt you will need to either make it optional (by setting a default, which might not be possible depending what it is representing) or specifying it using another method (tfvar file/env var/command line).

1 Like

In addition to @stuart-c’s answer, which covers the main points, I want to note that you can also choose to run Terraform in non-interactive mode using either the -input=false command line option or the TF_INPUT=0 environment variable.

In that case, instead of showing a prompt Terraform will show an error message to tell you that this required variable must be assigned a value. You can then assign it a value in one of the ways discussed in the previous reply in order to get past that error.

1 Like