Skip to content

nyamada100/tfsalvage

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tfsalvage

This is a wrapper command for Terraform CLI to salvage HCL files from Terraform's tfstate.

Usage

This command, when run with no arguments, restores all resources present in tfstate to HCL and prints to stdout.

go install github.com/azarashi2931/tfsalvage@latest
tfsalvage > salvaged.tf

The resources to restore can also be controlled by flags and a list of resource addresses passed from stdin.

cat <<EOF
resource.white_listed1
resource.white_listed2
resource.white_listed3
EOF | tfsalvage -include > salvaged.tf
cat <<EOF
resource.black_listed1
resource.black_listed2
resource.black_listed3
EOF | tfsalvage -exclude > salvaged.tf

Use-case: Import resources

You can salvage an HCL file from imported tfstate.

terraform import hoge.fuga
echo 'hoge.fuga' | tfsalvage -include > salvaged.tf

Limitations

  • This command knows nothing beyond what is provided by the Terraform provider schema.
    • For example, it is not possible to automatically remove attributes with the same value as the default value set by the cloud vendor.
  • Cannot control the order of resources, their attributes, or blocks. Because this command don't have such an flag.

About

Salvage HCL from tfstate

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 99.0%
  • Makefile 1.0%