1

I try to lean terraform for usage with our AWS environment. I have created a .tf file and terraform init was successful.

In the .tf file I have a number of variables that are populated via .var files (not .tfvar) because I want to assign values per instance/project etc.

The problem is that when I run the command

terraform plan -var-file="myvars.var"

all I get is the terraform usage message.

Where is my mistake?

closed as off-topic by Tensibai Aug 31 '18 at 15:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Tensibai
If this question can be reworded to fit the rules in the help center, please edit the question.

2

You define variables in variables.tf file. However, you can define inputs to these defined variables in a .tfvars(recommended) or any other files.

Values for the input variables of a root module can be gathered in variable definition files and passed together using the -var-file=FILE option.

For all files which match terraform.tfvars or *.auto.tfvars present in the current directory, Terraform automatically loads them to populate variables. If the file is located somewhere else, you can pass the path to the file using the -var-file flag. It is recommended to name such files with names ending in .tfvars. more...

Make sure you are running terraform plan from the directory where the variable file resides.

  • 1
    I do! It is in the same directory! The documentation says that I can use whatever filename is want, as long as I specify it in the -var-file. The directory has the following files: create_instance.tf, general variables.tf, myvars.var – Peter Aug 31 '18 at 13:42
  • Yes, you could use whatever file name you want. The same command works for me, except if the file is missing, or probably running it from a different directory. Would you mind to paste exact output you get when you run the command? – JSapkota Aug 31 '18 at 13:45
  • terraform plan -var-file="my-vars.vars" invalid value "my-vars.vars" for flag -var-file: multiple map declarations not supported for variables Usage: terraform plan [options] [DIR-OR-PLAN] – Peter Aug 31 '18 at 14:26
  • Sorry, wrong output (I was in another directory, sorry). Here is what I get: terraform plan -var-file=idm-vars.vars Usage: terraform plan [options] [DIR-OR-PLAN] Generates an execution plan for Terraform. This execution plan can be reviewed prior to running apply to get a sense for what Terraform will do. Optionally, ... – Peter Aug 31 '18 at 14:32
  • What do you get if you run the plan command without -var-file parameter? – JSapkota Aug 31 '18 at 14:41
0

The problem was a typo in the var-file I had a double " in a value:

varname = ""value"

Not the answer you're looking for? Browse other questions tagged or ask your own question.