Tool to manage multiple states in Terraform - Allows Multi account setups
terrastate --var-file ../../dev.tfvars
terrastate apply --var-file ../../dev.tfvars
terrastate apply --var-file ../../dev.tfvars -- -auto-approve
This generates a statefile called terrastate.tf
It will also replace an exisiting terrastate.tf file with the new information.
Some variables must be set in the varfile used by terrastate. Some of these variables are used by terrastate and others are depending on the backend.
The state_backend var defines the backend type and therefore which backend implementation should be used by terrastate. If the given backend is not supported terrastate returns an error. In this example s3 is configured as backend.
state_backend = "s3"
The currently supported backends are:
Feel free to add a new backend and create a pull request - How to create a new backend?
For more information about the backend specific variables click the backend in the list above.
state_auto_remove_old = true
When you set the value to true, the .terraform folder in the current directory gets removed when you create a terrastate.tf backend configuration through terrastate. If you set the value to false or don't set it, then the .terraform folder will not be removed.
This option allowes you to execute terrastate and then directly terraform init without manually removing the .terraform folder.
terrastate version
terrastate help
Paste these functions into your ~/.zshrc or ~/.bashrc file and adapt the var-file path according to your project structure
ts was chosen as a shorthand for terrastate, you could also use tf instead
function tsplan {
echo terrastate plan --var-file ../test/$@.tfvars;
terrastate plan --var-file ../test/$@.tfvars;
}
function tsaplly {
echo terrastate apply --var-file ../test/$@.tfvars;
terrastate apply --var-file ../test/$@.tfvars;
}
function tsdestroy {
echo terrastate destroy --var-file ../test/$@.tfvars;
terrastate destroy --var-file ../test/$@.tfvars;
}
Terrastate offers the following options to set additional configuration
The terrastate config file is a yaml file which can be either specified via --terrastate-file
flag or is loaded from $HOME/.terrastate.yaml
tf-init-upgrade: True
Environemt variables prefixed with TERRASTATE_
are automatically loaded by Terrastate, see the section for available variables below
Some config options can be set via subcommand flag, e.g. --tf-init-upgrade
Terraform init offers an -upgrade
option which automatically updates all modules and plugins during init.
By specifying one of the following Terrastate config variables, this init option will be added by Terrastate.
The default is: false
- Config file:
- Key is
tf-init-upgrade
- Value can be
True
orFalse
- Key is
- Flag
- The flag
--tf-init-upgrade
added to apply, plan, destroy or refresh commands
- The flag
- Environment variable
TERRASTATE_TF_INIT_UPGRADE=True
orTERRASTATE_TF_INIT_UPGRADE=False
Get the formula
brew tap janritter/terrastate
Install terrastate
brew install terrastate
- Download the latest release binary for your OS - Releases - For Linux (64bit) this would be 'linux_amd64_terrastate'
- Rename the downloaded binary to terrastate and move it to your '/usr/bin/' or '/usr/local/bin' directory
- Start using terrastate
make prepare
compiles to bin/terrastate
make build
Author: Jan Ritter
License: MIT