Skip to content

tfmigrator/tfmigrator

Repository files navigation

tfmigrator

Go Reference Build Status Go Report Card GitHub last commit License

Go library to migrate Terraform Configuration and State with terraform state mv and terraform state rm command and hcledit.

Using tfmigrator, you can do the following.

  • migrate resource address
    • e.g. null_resource.foo => null_resource.bar
      • terraform state mv null_resource.foo null_resource.bar
      • hcledit block mv -u -f main.tf resource.null_resource.foo resource.null_resource.bar
    • e.g. module.foo => module.bar
  • move resources in a Terraform Configuration file and State to the other file and State
    • e.g. terraform.tfstate => foo/terraform.tfstate
    • e.g. main.tf => foo/main.tf
  • remove resources from State and Terraform Configuration
    • e.g. terraform state rm null_resource.foo
    • e.g. hcledit block rm -u -f main.tf resource.null_resource.foo

On the other hand, tfmigrator doesn't support the following things.

  • change resource fields (attributes and blocks)
    • e.g. hcledit attribute

Requirement

  • Go
  • Terraform

hcledit isn't needed.

Example

Please see examples.

Document

https://pkg.go.dev/github.com/tfmigrator/tfmigrator/tfmigrator

Getting Started

The example and README tell us how to use tfmigrator and how tfmigrator works. You can implement a command for migration with Go simply. About the detail of Planner, please see the document of Source and MigratedResource.

QuickRun provides a high level API, so if you use QuickRun, you don't have to know about other API like Runner. But if you need low level API, please check other API like Runner.

Check tfmigrator/cli too

We have implemented CLI with this framework.

https://github.com/tfmigrator/cli

Release Note (Change log)

https://github.com/tfmigrator/tfmigrator/releases

LICENSE

MIT