Orchestrate OpenTofu (or Terraform) initialization and interactions with Ansible and Incus (including Incus S3 bucket as state backend).
Project description
tf-glue
Orchestrate OpenTofu (or Terraform) initialization and interactions with Ansible and Incus (including Incus S3 bucket as state backend).
Features
This tool provides some frequently needed glue for projects that combine part of, or all of, the following infrastructure automation stack:
- OpenTofu (or Terraform): infrastructure-as-code provisioner used to manage the lifecycle (create, update, delete) of the infrastructure resources (hosts, disks, networks, etc). OpenTofu is a fully open-source fork from HashiCorp's Terraform. OpenTofu is maintained under the Linux Foundation's CNCF stewardship. It was created in 2023 following HashiCorp's decision to switch from the Mozilla Public License to a more restricted license.
- Ansible: configuration management tool used to deploy applications and assets on hosts (once they are created, e.g. by OpenTofu). Ansible is the open-source engine (licensed under the GNU GPLv3) that powers the Red Hat Ansible Automation Platform.
- Incus: VMs and containers platform providing a user experience similar to that of a public cloud. It is well integrated with OpenTofu/Terraform and with Ansible. It is simple to use and can work efficiently on low-end systems and workstations, making it a great solution to simulate deployments locally. Incus is a community-driven fork of Canonical's LXD, created in 2023 following Canonical's decisions to takeover the project from LXC's community-led gouvernance and to change the license and require an additional Contributor License Agreement (which gives Canonical the right to re-license the contributed code, e.g. to sell it under a closed-source commercial license). Incus is licensed under the Apache 2.0 license.
Supported interactions between OpenTofu/Terraform and Incus:
- Read Incus client configuration from an OpenTofu/Terraform variables definition file (
variables.auto.tfvar) if present. - If not already present, write a
variables.auto.tfvarfile so that OpenTofu/Terraform can use the environment detected by the Incus command-line client. - Create and/or retrieve connexion details for an Incus-managed S3 bucket that can be used as an OpenTofu/Terraform state backend.
- Create an OpenTofu/Terraform backend configuration file (
backend.tfbackend) to use the Incus-managed S3 bucket. - Initialize OpenTofu/Terraform with the backend configuration file if applicable.
Supported interactions with Ansible:
- Read Incus client configuration from Ansible inventory's variables defined for the Incus connection plugin.
- Identify unused IP addresses on Incus networks, reserve them, so that they can be passed as variables to a dynamic Ansible inventory.
- Generate a dynamic Ansible inventory by compiling a YAML Jinja2 template with variables coming from Incus client and/or OpenTofu.
Installation
This tool can be installed from PyPI:
pip install tf-glue
Add the template extra (i.e. pyyaml and jinja2) to generate dynamic Ansible inventories from templates:
pip install tf-glue[template]
Usage
This tool can be used as a command-line application. The following example initializes OpenTofu (or Terraform) with an Incus-managed S3 bucket named myproject-state as its state backend (the bucket is automatically created if it does not exist yet) and variable definitions related to Incus client configuration:
tf-glue init --bucket myproject-state
See command-line help for available commands and options:
tf-glue --help
This tool can also be used as a Python library. Example:
#!/usr/bin/env python3
from tf_glue.ansible import generate_inventory
from tf_glue.incus import Incus
incus = Incus() # will use the environment detected by the Incus command-line client
generate_inventory("mytemplate.yml", incus=incus)
Contributing
Pull requests are welcome. See:
Legal
This tool is licensed under the MIT license.
It is not affiliated in any way with OpenTofu, Terraform, Ansible, Incus or any associated organization.
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 Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file tf_glue-1.0.0-py3-none-any.whl.
File metadata
- Download URL: tf_glue-1.0.0-py3-none-any.whl
- Upload date:
- Size: 24.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa8a2022c2a4f9d8911508ca8e689f497e68bdc6e0b6f2385fb9f921bab3db64
|
|
| MD5 |
8d6982a34769c6a9951c89f4d60195a2
|
|
| BLAKE2b-256 |
ccb5c9ddf613b238de488d3cbbe8795536948ac414fda55497e8d7acbb7b7ee3
|