terraform-inventory icon indicating copy to clipboard operation
terraform-inventory copied to clipboard

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)

Open queglay opened this issue 5 years ago • 9 comments

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

queglay avatar Aug 17 '19 11:08 queglay

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

jimb0bmij avatar Aug 22 '19 20:08 jimb0bmij

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

tbennett6421 avatar Aug 23 '19 15:08 tbennett6421

#114 see PR for more details

tbennett6421 avatar Aug 23 '19 15:08 tbennett6421

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 avatar Sep 30 '19 10:09 BenTheRabbit

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=./

BenTheRabbit avatar Sep 30 '19 10:09 BenTheRabbit

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

alor avatar Oct 31 '19 09:10 alor

Does not works even with ./ image

augustgerro avatar Mar 11 '20 20:03 augustgerro

+1 Same result here.

Terraform v0.12.25 provider.openstack v1.28.0

happycouak avatar May 27 '20 12:05 happycouak

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"

a0s avatar Dec 22 '20 17:12 a0s