{"id":15663719,"url":"https://github.com/magodo/tfmerge","last_synced_at":"2025-04-14T12:50:43.875Z","repository":{"id":59045537,"uuid":"530158546","full_name":"magodo/tfmerge","owner":"magodo","description":"A tool to merge Terraform state files","archived":false,"fork":false,"pushed_at":"2024-05-10T03:34:28.000Z","size":40,"stargazers_count":24,"open_issues_count":0,"forks_count":6,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-03T15:53:30.458Z","etag":null,"topics":["terraform","tool"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/magodo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-08-29T09:52:32.000Z","updated_at":"2025-02-18T16:01:49.000Z","dependencies_parsed_at":"2024-05-10T04:30:56.273Z","dependency_job_id":null,"html_url":"https://github.com/magodo/tfmerge","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/magodo%2Ftfmerge","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magodo%2Ftfmerge/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magodo%2Ftfmerge/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/magodo%2Ftfmerge/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/magodo","download_url":"https://codeload.github.com/magodo/tfmerge/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248884602,"owners_count":21177444,"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":["terraform","tool"],"created_at":"2024-10-03T13:39:33.679Z","updated_at":"2025-04-14T12:50:43.827Z","avatar_url":"https://github.com/magodo.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tfmerge\n\nA tool to merge multiple Terrafrom state files into one.\n\n## Usage\n\nGiven you have an initialized Terraform working directory (abbr. *wd*) (create one and run `terraform init` in it if not existed yet). The state file in *wd* will be used as the *base state file* (i.e. the `lineage` will be reserved, and the `serial` will be incremented). Meanwhile, you have other three state files to be merged: `state1`, `state2`, `state3`, where the module and resource addresses among these state files together with the *base state file* have no overlaps.\n\n`tfmerge` helps you merging these state files into the *base state file* by simply running `tfmerge -o terraform.tfstate state1 state2 state3` within the *wd*.\n\nIf your *wd* is using [a non-local backend](https://www.terraform.io/language/settings/backends/configuration), you'll need to manually upload the merged state file via `terraform state push`.\n\n## How\n\n*The process is inspired by https://support.hashicorp.com/hc/en-us/articles/4418624552339-How-to-Merge-State-Files*\n\n`tfmerge` will simply do followings:\n\n- Run `terraform state pull` to retrieve the *base state file*, works for both local and non-local backends. Especially, the output can be an empty string if there is no state file in the working directory, in this case a new state file will be created with a new lineage.\n- Run `terraform state list` on the *base state file* and the to-be-merged state files, to list all the items to be moved. Meanwhile, ensure there is no resource/module address overlap.\n- Copy all the state files to a temporary directory, to avoid mutation on existing state files.\n- Repeatedly run `terraform state mv -state-out=\u003cbase statefile copy\u003e -state=\u003cstatefile1 copy\u003e \u003citem address\u003e \u003citem address\u003e`\n- Return the merged base state file\n\n## Reference\n\n- https://discuss.hashicorp.com/t/will-state-and-state-out-be-removed-for-terraform-state-mv-subcommand/44630\n- https://support.hashicorp.com/hc/en-us/articles/4418624552339-How-to-Merge-State-Files\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagodo%2Ftfmerge","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmagodo%2Ftfmerge","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmagodo%2Ftfmerge/lists"}