Skip to content

Create a script of `terraform import` statements for resources from a given Terraform v4 state file.

License

Notifications You must be signed in to change notification settings

cmdpdx/tf-state-import

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tf-state-import

A tool for importing resources from a given Terraform state file. Outputs a list of terraform state rm and terraform state import commands to refresh a state file. Helpful when transitioning between incompatible versions of a provider.

Resource dependencies are considered when compiling the rm and import statements. Resources are removed from most dependent to least dependant resource, and imported in the opposite order.

Usage

$ go install .

# Run with no flags to look in the current directory for terraform.tfstate
$ tf-state-import
terraform state rm resource_foo.name
terraform state rm resource_bar.name
...
terraform state import resource_bar.name bar_id
terraform state import resource_foo.name foo_id

# Generate terraform import blocks 
$ tf-state-import --tfstate=/path/to/statefile.tfstate --format=block
import {
  to = resource_foo.name
  id = foo_id
}
import {
  to = resource_bar.name
  id = bar_id
}

About

Create a script of `terraform import` statements for resources from a given Terraform v4 state file.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages