CLI to migrate Terraform configuration and State
- tfmigrator/tfmigrator: Go framework to migrate Terraform configuration and State
- tfmigrator/cli: CLI to migrate Terraform configuration and State
terraformer で雑に生成した tf ファイル と state を分割したくてツールを書いた
tfmigrator
is a CLI tool to migrate Terraform configuration and State into multiple states.
tfmigrator
configures rules to classify resources and migrate resources to other states via terraform state mv
and hcledit.
- Terraform CLI
- hcledit
Download a binary from the release page.
$ vi tfmigrator.yaml
$ cat *.tf | tfmigrator run [-skip-state]
example of tfmigrator.yaml
items:
- rule: |
"name" not in Values
exclude: true
- rule: |
Values.name contains "foo"
state_out: foo/terraform.tfstate
resource_name: "{{.Values.name}}"
tf_path: foo/resource.tf
- rule: |
Values.name contains "bar"
state_out: bar/terraform.tfstate
resource_name: "{{.Values.name}}"
tf_path: bar/resource.tf
tfmigrator migrates Terraform configuration with hcledit and doesn't support to expand the expression. For example, if Terraform configuration refers local values, the migrated configuration may be broken.