terraform-inventory
terraform-inventory copied to clipboard
Doesn't find any hosts with remote state
The merge of #41 supposedly enables remote state. However this doesn't actually seems to be true.
I use s3 with the following configuration:
terraform {
backend "s3" {
bucket = "some.bucket.name"
key = "terraform.tfstate"
region = "us-east-1"
}
}
My .terraform/terraform.tfstate contains:
{
"version": 3,
"serial": 0,
"lineage": "abcdef01-2345-6789-abcd-ef0123456789",
"backend": {
"type": "s3",
"config": {
"bucket": "some.bucket.name",
"key": "terraform.tfstate",
"region": "us-east-1"
},
"hash": 01234567890123456789
},
"modules": [
{
"path": [
"root"
],
"outputs": {},
"resources": {},
"depends_on": []
}
]
}
Yet terraform-inventory -list results in: {"all":{"hosts":null,"vars":{}}}
Oh dear, #60 must have broken your workflow. Which version of Terraform are you using? My understanding is that newer versions don't use that path for remote state any more. (But of course, some people will still be expecting that, so we should probably fall back to it.) Does it work if you specify the path to the state file?
TF_STATE=.terraform/terraform.tfstate terraform-inventory -list
Thanks for the fast response!
I was on 0.9.6 but upgrading to 0.9.8 and running terraform refresh didn't change anything.
Also your suggested command doesn't show any hosts in the output.
For now I've worked around the problem by wrapping terraform-inventory in a shell script and manually writing the output of terraform state pull into a temp file.
this is reproducible for me too, the state returned with TF_STATE=.terraform/terraform.tfstate terraform-inventory -list is {}
It works for me if I do a terraform refresh and use the local terraform.tfstate.backup
same problem here
$ terraform --version Terraform v0.11.1
- provider.aws v1.5.0
- provider.scaleway v1.0.0
$ terraform-inventory --version terraform-inventory version v0.7-pre
with remote tfstate in S3
I'm also working around this by doing:
terraform state pull > .terraform/local.tfstate
TF_STATE=.terraform/local.tfstate ansible-playbook --inventory-file=$(which terraform-inventory) ansible/site.yml
@adammck is anyone working on this? Are you open for PRs?
@danihodovic I'm not actively working on this, but I'm happy to review and merge PRs. I expect that many people would appreciate this being fixed.
Remote state works fine for me using HEAD (commit https://github.com/adammck/terraform-inventory/commit/260af322ebe37c186c6368c9384e812678b85654; tested via S3). @adammck could you please tag a release so that the latest features and fixes can flow into homebrew and other package managers? 🏆
Just tried this with the google/gcs backend on revision 3a1f43306133e8fc981801ea3e0aa31a537edbba and still only getting {"all":{"hosts":null,"vars":{}}} :/
Same for me with google/gcs backend and Terraform 0.11.13
For anyone else continuing to have this issue make sure you delete your local provider plugins in either .terraform/plugins or ~/.terraform.d/plugins and re-run terraform init. This fixed the issue for me.
I suppose terraform init -upgrade should also work