When loading tfvars.json as a --var -file getting error

in my project we are using below versions. When we use tfvars as input it’s working fine. When we converted the tfvars to tfvars.json getting error as shown below. tfvars.json is as per json format and it has complex configurations .

Error
Error: Argument or block definition required

│ on .tfl.auto.tfvars line 2:

│ 2: {

│ An argument or block definition is required here.

Stack details
Version : 2.4.1
Build Timestamp : 2023-05-11T20:05:45+0000
Go Version : go1.19.6

simple json(test.tfvars.json) like the below as well getting me same error

{
“name”:“John”
}

Hi @gsuda2001,

Your file is named with a .tfvars suffix alone, so Terraform assumes you’ve written it in the native syntax.

To use the JSON variant of this format, use the suffix .tfvars.json instead.

If it doesn’t work even with the correct suffix then please share an example of how you are running Terraform with that renamed file and exactly what error message it returned, in full.

I am executing the plan passing the json file as shown below. When I passed test.tfars containing same key, value its working fine.

tfl plan --var-file variables/test.tfvars.json

Json content is
{
“name”: “test1”,
“org-name”: “TEST1”
}

Error I am getting:
Initializing Terraform configuration…

Error: Argument or block definition required

│ on .tfl.auto.tfvars line 2:
│ 2: {
│ An argument or block definition is required here.
Run Status: errored
ERROR: error running plan: run errored

Hi @gsuda2001,

The error message is referring to a different file tfl.auto.tfvars, and not to the one you passed on the command line. Terraform loads that one automatically because it has the .auto.tfvars suffix. You will need to either delete that file or rename it to have the .auto.tfvars.json suffix if you want Terraform to interpret it as JSON.

Hi @apparentlymart there is no such file .auto.tfvars in the project. But when I renamed my variable/test.tfvars.json to test.auto.tfvars.json & executing tfl plan it’s working fine. Not sure previously how it is trying to load .auto.tfvars with out any such file.