A simple Terraform wrapper to use variable definition files if they match the workspace name.
Project description
A simple Terraform wrapper to use variable definition files if they match the workspace name.
Rationale
With workspaces, one can use the same module in different environments with minor changes like different domain name, size of a cluster, instance type. One can use variable definition files to store the values for each workspace in a dedicated file. This wrapper replaces the following:
terraform workspace select prod
terraform plan -var-files=prod.tfvars -out tfplan
to:
terraform workspace select prod
tf plan -out tfplan
Installation
python3 -m pip install terraformation
The wrapper is a single Python3 script with no external dependencies. If you
prefer, you can download the tf.py
and use that instead.
Usage
Replace terraform
with tf
. In case there’s a variable
definitions file (that ends with .tfvars
) that matches the current
workspace name (if the current workspace name is prod
and a file named
prod.tfvars
exists) than a -var-file=prod.tfvars
argument is
added to the relevant commands (like plan
and import
). All
other arguments are kept as they were. Similarly, if a directory exists with
the same name as the workspace, for all the files inside that directory that
end with .tfvars
, a -var-file
argument is added. For example:
-var-file=prod/a.tfvars
and -var-file=prod/b.tfvars
.
By default tf
invokes terraform
, but if you’re using a
different tool (like OpenTofu you can set the
TF_CLI
environment variable to that tool name. If you wish to know the
exact command tf
is running set the TF_DEBUG
environment
variable to 1
and the command will printed before the it’s invoked.
License
This software is licensed under the MIT license (see the LICENSE.txt
file).
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file terraformation-0.2.0.tar.gz
.
File metadata
- Download URL: terraformation-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.9.6 requests/2.27.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe701df5fe5d4ec6caab40105bc6167f5bbfaaeed54a4cb3e90515011450ad46 |
|
MD5 | 8048a6761db3aaff655f1a3a421efcf7 |
|
BLAKE2b-256 | f2cac80f9330fac96c761b5f68c92d787ad35a46369d69733f2a68bdb968e94d |
File details
Details for the file terraformation-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: terraformation-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.9.6 requests/2.27.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b24b3084d0beb24a5d2c935a2499fc34170dd44bbd2f5429efb03db2ddca11b |
|
MD5 | 4d9d9d352f78ca31dccd59c21992b6c2 |
|
BLAKE2b-256 | 3836fd8cc79789627c68a5d2f29ee771fa26f0a2bff37b97f2cc417ec72cbb53 |