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

Doesn't find any hosts with remote state

Open ulope opened this issue 8 years ago • 13 comments

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":{}}}

ulope avatar Jun 13 '17 14:06 ulope

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

adammck avatar Jun 13 '17 14:06 adammck

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.

ulope avatar Jun 13 '17 15:06 ulope

this is reproducible for me too, the state returned with TF_STATE=.terraform/terraform.tfstate terraform-inventory -list is {}

MaxDesiatov avatar Jun 15 '17 18:06 MaxDesiatov

It works for me if I do a terraform refresh and use the local terraform.tfstate.backup

Dwaynekj avatar Oct 01 '17 14:10 Dwaynekj

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

sblaisot avatar Dec 14 '17 16:12 sblaisot

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

jangrewe avatar Mar 19 '18 10:03 jangrewe

@adammck is anyone working on this? Are you open for PRs?

danihodovic avatar Mar 25 '18 13:03 danihodovic

@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.

adammck avatar Mar 25 '18 14:03 adammck

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? 🏆

AndiDog avatar Jan 28 '19 21:01 AndiDog

Just tried this with the google/gcs backend on revision 3a1f43306133e8fc981801ea3e0aa31a537edbba and still only getting {"all":{"hosts":null,"vars":{}}} :/

andir avatar Jun 11 '19 12:06 andir

Same for me with google/gcs backend and Terraform 0.11.13

jpiron avatar Jul 11 '19 16:07 jpiron

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.

Obsecurus avatar Oct 17 '19 16:10 Obsecurus

I suppose terraform init -upgrade should also work

Obsecurus avatar Oct 17 '19 16:10 Obsecurus