tfmigrator
Go library to migrate Terraform Configuration and State with terraform state mv
and terraform state rm
command and hcledit.
Using tfmigrator, we 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)
Requirement
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.
We 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 we use QuickRun, we don't have to know about other API like Runner.
But if we need low level API, please check other API like Runner.
Compared with suzuki-shunsuke/tfmigrator
This is a Go package. On the other hand, suzuki-shunsuke/tfmigrator is CLI tool.
Originally we have been developing suzuki-shunsuke/tfmigrator before this package.
In suzuki-shunsuke/tfmigrator, we define rules for migration with YAML, Go's text/template, and expr.
So we don't have to write code with Go.
But when we migrate many resources, it is hard to write the configuration file.
So we started to develop tfmigrator as Go package instead of suzuki-shunsuke/tfmigrator.
Using this package, we can implement the migration rules with Go freely.
By implementing the interface Planner, we can migrate resources.
This is very simple and powerful and flexible.
And we don't have to learn the configuration file format and expr's Language specification, so the learning cost is low.
Using QuickRun function, we can implement CLI for migration quickly.
And compared with suzuki-shunsuke/tfmigrator v1.0.0, this package provides rich feature.
- Support to remove Resource
- Support to update Terraform Configuration files in place
- Don't have to install hcledit command
- Support the migration of Module address
- etc
Release Note (Change log)
https://github.com/tfmigrator/tfmigrator/releases
LICENSE
MIT