Skip to main content

A cli tool used to make running terraform or opentofu project simpler. Includes secret fetching and remote state management.

Project description

Tfrunner

Welcome to tfrunner, a cli tool to run terraform commands with the following facilities:

  • Multi-project support
  • Automation support
  • Remote backend
  • GitLab secrets pulling

Installation

Since tfrunner is a cli tool, the recommended installation is using pipx.

Please ensure you have a compatible python >= 3.12 version.

Install with: pipx install tfrunner

Usage

Requirements: tfrunner expects the following binaries to be installed:

  • terraform: tfrunner is a wrapper on top of terraform
  • git: when using the --git-sandbox flag, ensure you have git installed and that you are running the command in a git project

To use it to manage multiple projects, create a yaml file configuring each.

Here is an example file, let's name it tfrunner.yaml:

flavour: terraform # Can use tofu

state_backend:
  kind: gitlab
  spec:
    url: https://gitlab.com
    project_id: 12345678
    token_var: GITLAB_TOKEN

secrets_backend:
  kind: gitlab
  spec:
    url: https://gitlab.com
    project_id: 12345678
    token_var: GITLAB_TOKEN

tfvars:
  gitlab_token: $GITLAB_TOKEN

projects:
  dev: # Reflects name of the environment
    path: ../infra/dev
    state_name: dev
    # Inner environment gets added (and overrides colliding vars) with global env vars
    # env vars take precedence over secrets
    tfvars:
      doppler_token: $DOPPLER_TOKEN
    # Inner secrets backend takes precendence
    secrets_backend:
      kind: doppler
      spec:
        project: my-project
        config: dev
        token_var: DOPPLER_TOKEN

Now you can run tfrunner as you would run any regular terraform command (options are also included). You need only to be wary of two additional arguments that are needed:

  • --project: name of your project, as specified in your config file.
  • --config_path: path to your configuration file. By default it will look for a tfrunner.yaml file in the current folder

As examples, for the great-project in our example tfrunner.yaml file, you could run:

tfrunner init --project great-project
tfrunner fmt --project great-project
tfrunner validate --project great-project
tfrunner plan --project great-project
tfrunner apply --project great-project
tfrunner destroy --config_path tfrunner.yaml --project great-project

The --config_path is optional in the tfrunner destroy command, as tfrunner will by default assume its path to be tfrunner.yaml.

Usage with git-sandboxes

tfrunner init --project great-project --git-sandbox
tfrunner plan --project great-project --git-sandbox
tfrunner apply --project great-project --git-sandbox
tfrunner destroy --project great-project --git-sandbox

Local development

Requirements:

  • uv installed
  • terraform installed
  • git installed
  1. Install virtual environment: uv sync --all-groups

TODO:

  • Make tfrunner plan generate a plan file by default
  • Make tfrunner apply use that plan file by default

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

tfrunner-0.12.1.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

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

tfrunner-0.12.1-py3-none-any.whl (17.5 kB view details)

Uploaded Python 3

File details

Details for the file tfrunner-0.12.1.tar.gz.

File metadata

  • Download URL: tfrunner-0.12.1.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for tfrunner-0.12.1.tar.gz
Algorithm Hash digest
SHA256 2c5105ff84e6056452d7b37db841464b499670b61d6e5d1af74d55ed44934d19
MD5 facd03b13d58181a32cc419783c27f4d
BLAKE2b-256 962f9e49f9a071c99d1c8d87499fd5e4a86c25c2b70947f6612fcb61d91add52

See more details on using hashes here.

File details

Details for the file tfrunner-0.12.1-py3-none-any.whl.

File metadata

  • Download URL: tfrunner-0.12.1-py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for tfrunner-0.12.1-py3-none-any.whl
Algorithm Hash digest
SHA256 76a212bc539c3160a58e0415d0255e9dcd7b7f4e6fe9fdacf85ea05fcb279fbd
MD5 32cfc9dbf11c28d78a6c54ab356355e0
BLAKE2b-256 4df2113b3a2f616aa9fb78bca5f4bf444456dd08375d79ee52b7f137c94bd656

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