How to fix error value for undeclared variable a variable named was assigned on the command line?



In this article we are going to fix

Error Value for undeclared variable A variable named was assigned on the command line, but the root module does not declare a variable of that name. To use this value, add a variable block to the configuration

The above mentioned issue very common with terraform and 99% of the case you might have forgotten -

  1. Either declaring variable
  2. Or did not create a variable.tf file.

Here is the pic which might help you to understand this issue visually -

Value for undeclared variable A variable named was assigned on the command line, but the root module does not declare a variable of that name





How to fix?

  1. Look for the variable which you are trying to create.
  2. Create that variable inside your terraform file.
  3. Check your variable.tf and see if the variable is defined or not.
  4. Also check if there is mismatch in the variable name.



Read More - Terragrunt -

  1. How to use Terragrunt?

Posts in this series