I've hit an issue that I can't seem to find a way out of, with regards Terraform state management.
Terraform v0.9.5-dev and Terraform v0.9.3
Command output:
$ terraform plan -var "project=$OS_PROJECT_NAME" -out tf.plan
1 error(s) occurred:
* module root: 5 error(s) occurred:
* Unknown root level key: version
* Unknown root level key: terraform_version
* Unknown root level key: serial
* Unknown root level key: lineage
* Unknown root level key: modules
Full debug log available, but it's 8000 lines long so too big for a Gist...
terraform plan should work.
Plan fails with above error.
Unknown as to how I got into this state.
Last action undertaken was to import a resource, however reverting the state file makes no difference.
However it's occurring on both local and remote swift state, and also after rolling back to a previous state file
Issue occurs in both 0.9.3 and 0.9.5-dev, with 'current', 'previous' and 'week old' state file.
Hi @fatmcgav! Sorry for this... confusing result.
Based on the keys being reported there, it looks like somehow Terraform is finding a state file in your configuration directory and confusing it for a configuration file. Do you have a state file with a filename ending in .tf in the directory along with your other configuration files? The conventional suffix for local Terraform states is .tfstate.
@apparentlymart
Ah, looks like you're bang on the money there... I had backed up the remote state using terraform state pull, and mistakenly saved it with a .tf.json extension...
Changed the extension to .tfstate and the issue above goes away... :)
Sorry for the noise...
No worries, @fatmcgav! I'm glad we figured it out.
Hey,
I'm getting the same error,
1 error(s) occurred:
module root: 1 error(s) occurred:
Unknown root level key: Yes
In my case, there is no state file.
Hi @amanbisht,
Do you have any files with names ending in .tf in your directory that have a line starting with the literal string Yes ?
Hey @apparentlymart,
Fixed it, somehow there was Yes wriiten in my file somewhere. It would have been easy to identify it if there would have been line number and column number associated with the error. If that could be done, it would save a lot of time.
Thanks for the reply :)
I'm glad that worked out, @amanbisht, but sorry it was so much work to track it down. Producing better error messages with context is definitely on the docket for our forthcoming (still early-planning) configuration language improvements.
Hi,
I have the same issue. I have this code
https://www.terraform.io/docs/providers/aws/d/eip.html
and when plan it it says
1 error(s) occurred:
module root: 1 error(s) occurred:
Unknown root level key: aws_eip_association
Yet I looked for a Yes and nothing in the .tf files.
I'm using terraform v0.9.6 as with v0.8.8 it was already saying it and I tought that was a new feature in 0.9.
Any idea as to why it's not working?
thx for any help
Ok I found the issue, it looks like the doc has an error based on this thread
https://github.com/hashicorp/terraform/pull/5236#issuecomment-213666380
The proper way to use aws_eip_association is via a resource command
instead of
aws_eip_association "proxy_eip" {
instance_id = "${var.instance_id}"
allocation_id = "${data.aws_eip.proxy_ip.id}"
}
the doc at https://www.terraform.io/docs/providers/aws/d/eip.html should say
resource "aws_eip_association" "proxy_eip" {
instance_id = "${var.instance_id}"
allocation_id = "${data.aws_eip.proxy_ip.id}"
}
Thanks for pointing that out, @itudoben! I fixed it in 482b7c603c5520b46dba8e6db73eb3134e4b0ab2 so it should get updated on the website after the next release.
FYI, I also experienced this error when I had a local declaration between my provider declaration and my backend declaration.
When I tried terraform I got the errors:
Error: Unknown root level key: connection
Error: Unknown root level key: provisioner
I am using terraform 0.11.7 version and the configuration is below
Please, could somebidy help me?
connection {
type ="ssh"
user ="debian"
#password ="${var.root_password}"
private_key ="${file("~/.ssh/id_rsa")}"
agent = false
}
provisioner "file" {
source ="script.sh"
destination ="/tmp/script.sh"
}
provisioner "remote-exec" {
inline =[
"chmod +x /tmp/script.sh",
"sudo /tmp/script.sh"
]
}
I had the same issue. For me the problem was that I named the file which contained the variables with .tf rather than .tfvars
I had a similar error to this when I had used an equals symbol in a resource declaration.
e.g.
resource = "google_pubsub_topic" "test_topic" { ...
Error: Unknown root level key: test_topic
Fixed by removing the equals
resource "google_pubsub_topic" "test_topic" { ...
My fault for doing the typo, but the error message is a bit cryptic. It's not that hard to find the line where it was happening (although line numbers would be lovely) but seeing the equals symbol that was not supposed to be there took me a while.
I was getting this error. In my case the error was "Error: Unknown root level key: App"
I had added a comment in my general.tfvars file starting with the keyword "App" and forgot to add "#". Basically terraform was not able to understand the word "App"
Just to add here - in my case when this was happening, I had a YAML file with configuration for AWS named as a .TF file. When I renamed it properly, Terraform is working as intended.
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.
Most helpful comment
Hi @amanbisht,
Do you have any files with names ending in
.tfin your directory that have a line starting with the literal stringYes?