{"id":15630586,"url":"https://github.com/afeld/tfmv","last_synced_at":"2025-04-29T13:58:53.067Z","repository":{"id":136986968,"uuid":"111362005","full_name":"afeld/tfmv","owner":"afeld","description":"proof of concept: a tool to help refactoring Terraform resources","archived":false,"fork":false,"pushed_at":"2020-04-15T16:07:29.000Z","size":44,"stargazers_count":11,"open_issues_count":3,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T12:11:51.801Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/afeld.png","metadata":{"files":{"readme":"README.md","changelog":"changes.go","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-20T04:33:26.000Z","updated_at":"2025-01-08T17:46:59.000Z","dependencies_parsed_at":null,"dependency_job_id":"55aa1a75-e572-415b-9cde-e9891ea1f80b","html_url":"https://github.com/afeld/tfmv","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeld%2Ftfmv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeld%2Ftfmv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeld%2Ftfmv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/afeld%2Ftfmv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/afeld","download_url":"https://codeload.github.com/afeld/tfmv/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251515174,"owners_count":21601719,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-03T10:33:29.335Z","updated_at":"2025-04-29T13:58:53.048Z","avatar_url":"https://github.com/afeld.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfmv [![CircleCI](https://circleci.com/gh/afeld/tfmv.svg?style=svg)](https://circleci.com/gh/afeld/tfmv)\n\n\"Terraform Move\", a tool to help with Terraform refactoring. The use case: Let's say you have a resource:\n\n```hcl\n// terraform/main.tf\nresource \"aws_instance\" \"app\" {\n  // ...\n}\n```\n\nIf you change the resource name:\n\n```hcl\n// \"app\" --\u003e \"webapp\"\nresource \"aws_instance\" \"webapp\" {\n  // ...\n}\n```\n\nor move it into a module:\n\n```hcl\n// terraform/main.tf --\u003e terraform/shared/main.tf\nresource \"aws_instance\" \"app\" {\n  // ...\n}\n```\n\nthe [resource address](https://www.terraform.io/docs/internals/resource-addressing.html) is different, and Terraform treats it as the old `resource` being deleted, and the new one being created. Why not reuse them? [`terraform state mv`](https://www.terraform.io/docs/commands/state/mv.html) allows you to update the addresses of resources by hand, but this can be tedious if you are moving more than a few resources.\n\n### Goals\n\nIn order:\n\n1. Improve algorithm for resource matching.\n   - Currently it's just matching created resources with destroyed ones of the same type, in the order it comes across them. It could be better at guessing created/destroyed resources that are likely meant to be the same.\n1. Gain enough confidence in its functionality that it can be used in deployment pipelines, where it's hard to do `state mv` by hand.\n1. Propose merging into Terraform core.\n\n## Setup\n\n1. [Install Go 1.6+.](https://golang.org/doc/install)\n1. Install the package.\n\n   ```sh\n   go get github.com/afeld/tfmv\n   ```\n\n## Usage\n\n1. Create a plan.\n\n   ```sh\n   cd \u003cyour module\u003e\n   terraform plan -out=tfplan\n   ```\n\n1. Run the executable. It will compute `state mv` commands to efficiently reuse resources.\n\n   ```\n   $ tfmv\n   terraform state mv aws_instance.my_instance module.shared.aws_instance.my_instance\n   ...\n   ```\n\n1. After double-checking the output, you can run the commands to avoid deleting and recreating resources unnecessarily.\n\n## See also\n\n- [Google Groups discussion](https://groups.google.com/forum/#!topic/terraform-tool/CE2ScmDBTIE)\n- [GitHub issue about resource equivalence maps](https://github.com/hashicorp/terraform/issues/9048)\n\n## Development\n\n1. Install Terraform.\n1. [Install dep.](https://golang.github.io/dep/docs/installation.html)\n1. Install the dependencies.\n\n   ```sh\n   dep ensure\n   ```\n\n1. Run tests.\n\n   ```sh\n   go test\n   ```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeld%2Ftfmv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fafeld%2Ftfmv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fafeld%2Ftfmv/lists"}