cycloidio / inframap

Read your tfstate or HCL to generate a graph specific for each provider, showing only the resources that are most important/relevant.
MIT License
1.7k stars 95 forks source link

How to do when the state is stored in a backend ? #44

Closed MichaelMure closed 4 years ago

MichaelMure commented 4 years ago

Is there a way to use this tool when the state is stored in a terraform backend like S3 ? There is no .tfstate file in that case.

Thanks :)

tormath1 commented 4 years ago

Hi @MichaelMure , thanks for raising this issue !

That's a good point to raise. Indeed, Terraform supports multiple backends (S3 included) but the goal of inframap is to only generate graphs from local tfstate (or HCL), it's currently up to the user to provide the tfstate or HCL.

In order to solve your use-case: inframap is able to read the tfstate (or HCL) from the stdin, you could simply make the following:

aws s3 cp s3://bucket/path/to/your/file.tfstate - | inframap generate --tfstate
tormath1 commented 4 years ago

@MichaelMure we added your question to the FAQ in this PR (https://github.com/cycloidio/inframap/pull/46) https://github.com/cycloidio/inframap#does-inframap-support-terraform-backends-

Thanks for your contribution ! :wink:

MichaelMure commented 4 years ago

thanks :)

purplepangolin commented 2 years ago

If using some other backend (such as the http backend) then an alternative approach is:

terraform state pull | inframap generate --tfstate
xescugc commented 2 years ago

Thanks @purplepangolin I'm gonna add it to the documentation so it's also easily available for people to use :) BTW if you want you can drop the --tfstate flag as it automatically identifies the type (HCL or State) if you want :)