Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error reading tfstate file: 0.12 format error: <nil>; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format) #121

Open
queglay opened this issue Aug 17, 2019 · 9 comments

Comments

@queglay
Copy link

queglay commented Aug 17, 2019

I updated to tf .12.6 and terraform inventory .9, but I'm getting errors that the tfstate is not current. I'm not sure why, because this is a whole new rollout started from scratch with no lingering .11 to my knowledge.

vagrant@openfirehawkserverdev:/vagrant$ /vagrant/ansible/inventory/terraform-inventory --list
Error reading tfstate file: 0.12 format error: <nil>; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)
vagrant@openfirehawkserverdev:/vagrant$ /vagrant/ansible/inventory/terraform-inventory --version
/vagrant/ansible/inventory/terraform-inventory version 0.9
vagrant@openfirehawkserverdev:/vagrant$ terraform --version
Terraform v0.12.6
+ provider.aws v2.24.0
+ provider.null v2.1.2
+ provider.random v2.2.0
@jimb0bmij
Copy link

I updated to tf .12.6 and terraform inventory .9, but I'm getting errors that the tfstate is not current. I'm not sure why, because this is a whole new rollout started from scratch with no lingering .11 to my knowledge.

vagrant@openfirehawkserverdev:/vagrant$ /vagrant/ansible/inventory/terraform-inventory --list
Error reading tfstate file: 0.12 format error: <nil>; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)
vagrant@openfirehawkserverdev:/vagrant$ /vagrant/ansible/inventory/terraform-inventory --version
/vagrant/ansible/inventory/terraform-inventory version 0.9
vagrant@openfirehawkserverdev:/vagrant$ terraform --version
Terraform v0.12.6
+ provider.aws v2.24.0
+ provider.null v2.1.2
+ provider.random v2.2.0

Getting the same issue but using provider.vsphere

@tbennett6421
Copy link

You can try terraform-inventory --list ./; that worked for me.

@tbennett6421
Copy link

#114 see PR for more details

@BenTheRabbit
Copy link

You can try terraform-inventory --list ./; that worked for me.

Indeed, but as you cannot use arguments with ansible, you cannot call it from the --inventory-file option. Or am I doing something wrong?

TF_STATE=/path/to/terraform.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory test.yml
 [WARNING]:  * Failed to parse /path/to/terraform-inventory with script plugin: Inventory script (/path/to/terraform-inventory) had an execution error: Error reading
tfstate file: 0.12 format error: <nil>; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)

@BenTheRabbit
Copy link

You can try terraform-inventory --list ./; that worked for me.

Indeed, but as you cannot use arguments with ansible, you cannot call it from the --inventory-file option. Or am I doing something wrong?

TF_STATE=/path/to/terraform.tfstate ansible-playbook --inventory-file=/path/to/terraform-inventory test.yml
 [WARNING]:  * Failed to parse /path/to/terraform-inventory with script plugin: Inventory script (/path/to/terraform-inventory) had an execution error: Error reading
tfstate file: 0.12 format error: <nil>; pre-0.12 format error: <nil> (nil error means no content/modules found in the respective format)

ok, works if TF_STATE=./

@alor
Copy link

alor commented Oct 31, 2019

any plan to fix this without forcing the user to add the TF_STATE variable or the ./ at the end of the command? thank you

@augustgerro
Copy link

Does not works even with ./
image

@happycouak
Copy link

happycouak commented May 27, 2020

+1
Same result here.

Terraform v0.12.25
provider.openstack v1.28.0

@a0s
Copy link

a0s commented Dec 22, 2020

Working inventory:

ansible/inventory/a_terraform.sh:

#!/usr/bin/env bash
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
TERRAFORM_INVENTORY=`which terraform-inventory`
TF_STATE="$CURRENT_DIR/../../terraform"    # <<== relative path to dir with .tfstate
"$TERRAFORM_INVENTORY" "$@" "$TF_STATE"

pli888 added a commit to pli888/gigadb-website that referenced this issue Mar 31, 2022
Seems like we need to provide the path to the directory with the
.tfstate file. Adding ./ does this.

See adammck/terraform-inventory#121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants