Terraform: Error: Unknown root level key

Created on 2 Aug 2018  ยท  9Comments  ยท  Source: hashicorp/terraform

Hello Team,
when i am trying to do the Terraform init ,it is returning me with the error :
Error: Unknown root level key: tags
Error: Unknown root level key: Resource
Error: Unknown root level key: provisoner
I have moved the file to a whole new directory and even checked if there are any existing .tfstate files .
There are none.
Still it is returning me with this kind of error.
I am trying to resolve a very minor terraform provisoner example.

bug cli

All 9 comments

Hi @AnujNautiyal1956! Sorry this isn't working as expected.

Could you please share the configuration you are trying to use? Without seeing the configuration you're using it's not really possible to say what might be going on here.

I have the same issue with backend config

Initializing modules...

  • module.kubernetes_cluster

Initializing the backend...

Error: Unknown root level key: storage_account_name

Error: Unknown root level key: container_name

Error: Unknown root level key: key

Error: Unknown root level key: access_key

terraform {
  backend "azurerm" {
    storage_account_name = "ACCOUNT_NAME"
    container_name       = "states"
    key                  = "demo.state.tfstate"
    access_key           = "KEY"
  }
}

Hi @hmarcelodn! Thanks for sharing those details.

When we've seen this sort of error in the past the cause has been another file in the configuration directory that ends with .tf but is not actually formatted as a configuration file. In your case the keys listed are ones from the backend configuration... are you by any chance using the -backend-config=... option on terraform init with a backend settings file whose name ends with .tf?

If not, are there any other .tf files in the directory alongside the one you shared here, which might not actually be regular Terraform configuration files?

I had the same issue. For me the problem was that I named the file which contained the variables with .tf rather than .tfvars

Hi all,

I sounds to me like the cause of this is giving the backend config file a name ending in .tf, as @mario-paniccia reported.

I tried this with the v0.12.0-alpha2 prerelease build to see how the error result differs with the new configuration loader, and although it's got additional context it's still rather confusing indeed:

$ terraform init -backend-config=backend-config.tf
There are some problems with the configuration, described below.

The Terraform configuration must be valid before initialization so that
Terraform can determine which modules and providers need to be installed.

Error: Unsupported attribute

  on backend-config.tf line 1:
   1: path = "foo.tfstate"

An attribute named "path" is not expected here.

Terraform first parses the backend-config.tf file _as_ a backend config and does so successfully, but it then subsequently finds it again when looking for configuration files and runs into the above error trying to load it as one.

I think the best thing we can do here is make Terraform reject backend configuration files, variables files, and plan files ending with .tf. That way we can give a more helpful error message explaining that .tf is not a valid name for those situations, _before_ Terraform then tries to parse the same file as a configuration file.

Since the 0.12.0 scope is already quite large at this point we won't be able to get this in before that release, but we'll make this change in a subsequent one. In the mean time, the fix is to ensure that the file you pass to terraform init -backend-config=..., any -var-file= argument, or terraform plan -out... use a file name that does _not_ end with .tf or .tf.json.

Thanks everyone for sharing the extra details here! I'm going to relabel this to reflect that it'll be a change in the handling of these command line arguments rather than a bug in the configuration language itself.

what can be done is : Where you have defined the variable to be renamed with .tfvars and also define all the ID,s in the main This will help. It helped me.

Hello again!

We didn't hear back from you, so I'm going to close this in the hope that a previous response gave you the information you needed. If not, please do feel free to re-open this and leave another comment with the information my human friends requested above. Thanks!

I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings