README
¶
Terravalet
A tool to help with some Terraform operations.
For the time being it generates state migration scripts that work also for Terraform workspaces. The idea of migrations comes from the excellent tfmigrate.
Status
This is BETA code, although we already use it in production. The instructions provide also ways to manually recover, but be careful and ensure you UNDERSTAND what you are doing if you use it for something important!
You have been warned.
The API can change in breaking ways until we reach v1.0.0
Usage
Collect information
$ cd $ROOT_MODULE_DIR
$ terraform plan -no-color 2>&1 | tee plan-01.txt
Exact match, success
Take as input the Terraform plan plan-01.txt and generate UP and DOWN migration scripts:
$ terravalet \
-plan plan-01.txt -up 001_TITLE.up.sh -down 001_TITLE.down.sh
NOTE: It us up to the user to ensure that the migration number is correct with respect to what is already present in the migration directory.
Exact match, failure
Depending on how the elements have been renamed in the Terraform configuration, it is possible that the exact match will fail:
$ terravalet \
-plan plan-01.txt -up 001_TITLE.up.sh -down 001_TITLE.down.sh
match_exact:
unmatched create:
aws_route53_record.private["foo"]
unmatched destroy:
aws_route53_record.foo_private
Fuzzy match
WARNING Fuzzy match can make mistakes. It is up to you to validate that the migration makes sense
If exact match failed, it is possible to enable q-gram distance fuzzy matching with the -fuzzy-match flag:
$ terravalet -fuzzy-match \
-plan plan-01.txt -up 001_TITLE.up.sh -down 001_TITLE.down.sh
WARNING fuzzy match enabled. Double-check the following matches:
9 aws_route53_record.foo_private -> aws_route53_record.private["foo"]
Install
Install from binary package
- Download the archive for your platform from the releases page.
- Unarchive and copy the
terravaletexecutable somewhere in your$PATH. I like to use$HOME/bin/.
Install from source
- Install Go.
- Install task.
- Run
task$ task - Copy the executable
bin/terravaletto a directory in your$PATH. I like to use$HOME/bin/.
Making a release
Setup
- Install github-release.
- Install gopass or equivalent.
- Configure a GitHub token:
3.1 Go to Personal Access tokens
3.2 Click on "Generate new token"
3.3 Select only the
reposcope - Store the token securely with a tool like
gopass. The nameGITHUB_TOKENis expected bygithub-release$ gopass insert gh/terravalet/GITHUB_TOKEN
Each time
- Update CHANGELOG
- Update this README and/or additional documentation.
- Commit and push.
- Begin the release process with
$ env RELEASE_TAG=v0.1.0 gopass env gh/terravalet task release - Finish the release process by following the instructions printed by
taskabove. - To recover from a half-baked release, see the hints in the Taskfile.
License
This code is released under the MIT license, see file LICENSE.
Documentation
¶
There is no documentation for this package.