Skip to main content

A simple Terraform wrapper to use variable definition files if they match the workspace name.

Project description

pipeline status

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’s 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 it’s invoked.

License

This software is licensed under the MIT license (see the LICENSE.txt file).

Author

Nimrod Adar, contact me or visit my website. Patches are welcome via git send-email. The repository is located at: https://git.shore.co.il/nimrod/.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

terraformation-0.3.1.tar.gz (4.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

terraformation-0.3.1-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file terraformation-0.3.1.tar.gz.

File metadata

  • Download URL: terraformation-0.3.1.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.10.0 requests/2.27.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.8

File hashes

Hashes for terraformation-0.3.1.tar.gz
Algorithm Hash digest
SHA256 c676a2c9b7121249eda3c701e8bc0f8e8a2880560c15a1f40965846d5cf9e5fa
MD5 59ae58d2e7722707e5a0a4999c50538c
BLAKE2b-256 41a3f470507e0145e1a1784bc7990ce308d835e32ee01a819d09a9aed41645c3

See more details on using hashes here.

File details

Details for the file terraformation-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: terraformation-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.10.0 requests/2.27.1 setuptools/39.2.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.6.8

File hashes

Hashes for terraformation-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b56536612f4e901422eafeada4ec2b84f15eb83419757503b25164585e4e7152
MD5 b298926cebf26e58d79bb9352823b37a
BLAKE2b-256 a3225b3000dfd9afcb332b529465207308dcdd701dbf6db3ede6933ff4de865b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page