Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benoit74/terraform-split-state
A lean Python tool to split Terraform state file
https://github.com/benoit74/terraform-split-state
Last synced: 9 days ago
JSON representation
A lean Python tool to split Terraform state file
- Host: GitHub
- URL: https://github.com/benoit74/terraform-split-state
- Owner: benoit74
- License: mit
- Created: 2023-06-06T13:50:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-06-06T14:01:48.000Z (over 1 year ago)
- Last Synced: 2024-11-25T17:48:29.621Z (about 2 months ago)
- Language: Python
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Terraform split state
====## Purpose
This tool is meant to split a Terraform state from one file to many. See demo for sample configuration.$
This tool probably does not work if workspaces are used.
This tool assumes that you might have direct access to Terraform state file from a local environment + that you have write access to `/tmp` folder on this local environment.
## Demo
Create an S3 bucket (empty preferably) to store your Terraform states and store its name in `shared_s3.tfbackend`
Setup AWS credentials to access this bucket (here we use an AWS_PROFILE, but it could be anything else - or even nothing if your environment is already ready)
```
export AWS_PROFILE=xxxx
``````
cd tool
python -m venv venv
source venv/bin/activate
pip install --upgrade pip
pip install --upgrade -r requirements.txt
cd ..
```Provision original infrastructure + init new workspaces
```
cd demo/orig_project
terraform init --backend-config=../shared_s3.tfbackend
terraform apply --auto-approve
cd ../1_new_project
terraform init --backend-config=../shared_s3.tfbackend
cd ../2_new_project
terraform init --backend-config=../shared_s3.tfbackend
cd ../orig_project_after
terraform init --backend-config=../shared_s3.tfbackend
cd ../..
```Apply demo moves (as configured in config.yaml)
```
cd demo
python ../tool/main.py
cd ..
```Check that everything has been moved with following actions which should all display nothing to do ("no changes"):
```
cd demo/orig_project_after
terraform plan
cd ../1_new_project
terraform plan
cd ../2_new_project
terraform plan
cd ../..
```