adammck / terraform-inventory

Terraform State → Ansible Dynamic Inventory
MIT License
1.81k stars 324 forks source link

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 5 years ago

queglay commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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

tbennett6421 commented 5 years ago

114 see PR for more details

BenTheRabbit commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

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 commented 4 years ago

Does not works even with ./

image
happycouak commented 4 years ago

+1 Same result here.

Terraform v0.12.25 provider.openstack v1.28.0

a0s commented 3 years ago

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"