Terraform task management wrapper for Python
Project description
twrapform
A Python library for running Terraform commands from Python with asynchronous workflow management.
✨ Features
- Run Terraform commands natively from Python
- Asynchronous execution using
asyncio - Immutable task definitions with unique IDs
- Grouped workflow orchestration
- Granular error handling with structured results
📦 Requirements
- Python 3.10+
- Terraform installed and available in your system's
PATH
🔧 Installation
pip install twrapform
🚀 Usage Examples
Run a single workflow with chained Terraform tasks
import asyncio
from twrapform import Workflow
from twrapform.exception import TwrapformError
from twrapform.options import InitTaskOptions, PlanTaskOptions, ApplyTaskOptions, OutputTaskOptions
async def main():
# Create an instance of Twrapform
twrap = Workflow(work_dir="/terraform_rootpath")
# Add Terraform tasks one by one
twrap = twrap.add_task(InitTaskOptions())
# Chain multiple tasks
twrap = (
twrap
.add_task(PlanTaskOptions(var={"var1": 1}))
.add_task(ApplyTaskOptions(var={"var1": 1}))
.add_task(OutputTaskOptions(json=True))
)
# Execute all tasks
results = await twrap.execute()
try:
# Raise errors if any task fails
results.raise_on_error()
except TwrapformError as e:
print(f"Error occurred: {e.message}")
# Output results for successful tasks
for success_task in results.get_success_tasks():
print(success_task.stdout)
if __name__ == "__main__":
asyncio.run(main())
Manage multiple workflows in a group using WorkflowManager
from twrapform import Workflow, WorkflowManager
from twrapform.options import InitTaskOptions
import asyncio
async def main():
# Define workflows with Terraform initialization tasks
workflow1 = Workflow(work_dir="infra/project1").add_task(InitTaskOptions())
workflow2 = Workflow(work_dir="infra/project2").add_task(InitTaskOptions())
# Add workflows into a group and initialize the manager
manager = WorkflowManager().add_workflows(workflow1, workflow2, group_id="init-group")
# Run the grouped workflows asynchronously
result = await manager.execute()
# Display summaries for successfully completed tasks
for group_result in result.group_results:
for wf_result in group_result.workflow_results:
for task in wf_result.get_success_tasks():
print(task.summary())
if __name__ == "__main__":
asyncio.run(main())
⚙️ Supported Terraform Commands
twrapform currently supports the following Terraform commands:
terraform initterraform planterraform applyterraform outputterraform workspace select
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
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 twrapform-0.0.8.tar.gz.
File metadata
- Download URL: twrapform-0.0.8.tar.gz
- Upload date:
- Size: 23.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
29c46be7d1495e51f745106061693ca11704839811ad6441918bc8fc3589c728
|
|
| MD5 |
824600908cf62c1bd8189d752f7f6c54
|
|
| BLAKE2b-256 |
a12f0a80e1ad939bfae5a46b004c3ce8393b3972d1f85cd6d5887e8fe84e995a
|
Provenance
The following attestation bundles were made for twrapform-0.0.8.tar.gz:
Publisher:
publish-pypi.yml on minthem/python-terraform-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twrapform-0.0.8.tar.gz -
Subject digest:
29c46be7d1495e51f745106061693ca11704839811ad6441918bc8fc3589c728 - Sigstore transparency entry: 343138977
- Sigstore integration time:
-
Permalink:
minthem/python-terraform-wrapper@3bc09763fdef4007bfcaf61db32692c12edb951a -
Branch / Tag:
refs/tags/0.0.8 - Owner: https://github.com/minthem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3bc09763fdef4007bfcaf61db32692c12edb951a -
Trigger Event:
push
-
Statement type:
File details
Details for the file twrapform-0.0.8-py3-none-any.whl.
File metadata
- Download URL: twrapform-0.0.8-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5661593a36c76bd3fe5c2c090e6122bd3b03927f60bf6bd3eb0c0df4fd95d58
|
|
| MD5 |
5cb883307ac1b4b81ab1d0b00a249d62
|
|
| BLAKE2b-256 |
b0ad45cff3af9d6f0664fe3af754f4fa14777d3deceb6c9d7eb84ebe4148eff3
|
Provenance
The following attestation bundles were made for twrapform-0.0.8-py3-none-any.whl:
Publisher:
publish-pypi.yml on minthem/python-terraform-wrapper
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twrapform-0.0.8-py3-none-any.whl -
Subject digest:
e5661593a36c76bd3fe5c2c090e6122bd3b03927f60bf6bd3eb0c0df4fd95d58 - Sigstore transparency entry: 343139009
- Sigstore integration time:
-
Permalink:
minthem/python-terraform-wrapper@3bc09763fdef4007bfcaf61db32692c12edb951a -
Branch / Tag:
refs/tags/0.0.8 - Owner: https://github.com/minthem
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@3bc09763fdef4007bfcaf61db32692c12edb951a -
Trigger Event:
push
-
Statement type: