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

Doesn't find any hosts with remote state #66

Open
ulope opened this issue Jun 13, 2017 · 13 comments
Open

Doesn't find any hosts with remote state #66

ulope opened this issue Jun 13, 2017 · 13 comments

Comments

@ulope
Copy link

ulope commented Jun 13, 2017

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

@adammck
Copy link
Owner

adammck commented Jun 13, 2017

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

@ulope
Copy link
Author

ulope commented Jun 13, 2017

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.

@MaxDesiatov
Copy link

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

@Dwaynekj
Copy link

Dwaynekj commented Oct 1, 2017

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

@sblaisot
Copy link

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

@jangrewe
Copy link

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

@danihodovic
Copy link

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

@adammck
Copy link
Owner

adammck commented Mar 25, 2018

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

@AndiDog
Copy link
Contributor

AndiDog commented Jan 28, 2019

Remote state works fine for me using HEAD (commit 260af32; 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? 🏆

@andir
Copy link

andir commented Jun 11, 2019

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

@jpiron
Copy link

jpiron commented Jul 11, 2019

Same for me with google/gcs backend and Terraform 0.11.13

@Obsecurus
Copy link

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
Copy link

I suppose terraform init -upgrade should also work

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