tfrewind
is a tool that can back-convert your tfstate file into a useable main.tf.
This is especially useful if you are running terraform import
and want to convert the resulting .tfstate
file into something immediately useable
From Source - requires go
- clone this repository
- from this repository run
go install .
- from the folder where a
.tfstate
file lives, calltfrewind
From Binary
- grab the binary for your OS from this release and add it to your
$gopath/bin
directory or wherever your PATH looks for binaries
e.g. on mac its usually /usr/bin/
or /usr/local/bin
as long as that folder is on your $PATH
An example terraform.tfstate
file has been given to demonstrate what will happen. If you installed the app correctly, running tfrewind
from this directory with the provided example, you should get an output main.tf
that looks like the provided main_example.tf
.
If you were to terraform import
your own resources prior to running this, you'd get a proper main.tf
.
I started this thinking it'd be cool to add some functionality to my Terraform workflow and as such I haven't added everything under the sun, but if there's a resource you need imported, please add it.
- You'll need to add a file to
/resources
with the conventionprovider_resource.go
so for exampleaws_iam_user.go
oronelogin_user.go
- In that file implement the
HCLShape() interface{}
method. You'll return the address to a struct that will be used for marshalling/unmarshalling json from the.tfstate
file. (Seeaws_iam_user.go
for example) - Add the parseable resource you just set up to the
parsables-factory.go
file
case "<your_parsable>":
imf.parsables[parsableType] = &<your_parsable>{}
Currently supports only v0.12.xx
Support Terraform v0.13.xx
.
Automatic imports based on providers' list resources
APIs