Skip to main content

Terraform task management wrapper for Python

Project description

twrapform

A Python library for running Terraform commands from Python with async support.

Features

  • Execute Terraform commands from Python code
  • Asynchronous execution support
  • Task management with unique IDs
  • Customizable task options
  • Error handling for Terraform operations

Requirements

  • Python 3.10 or higher
  • Terraform installed on your system

Installation

Using pip:

pip install twrapform

Usage Example

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())

Supported Commands

twrapform currently supports the following Terraform commands:

  • terraform init
  • terraform plan
  • terraform apply
  • terraform output
  • terraform workspace select

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

twrapform-0.0.5.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

twrapform-0.0.5-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file twrapform-0.0.5.tar.gz.

File metadata

  • Download URL: twrapform-0.0.5.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for twrapform-0.0.5.tar.gz
Algorithm Hash digest
SHA256 5a1b5ecb0060b990d72fe08c2ea499a66874008992cae89160644b5a33f598db
MD5 bdc6ce94e827085b2624d3c372f3784a
BLAKE2b-256 fb805294a3d482ec9c14d207cfc3038e240b502f62ef099e85d628fb5b17fe93

See more details on using hashes here.

Provenance

The following attestation bundles were made for twrapform-0.0.5.tar.gz:

Publisher: publish-pypi.yml on minthem/twrapform

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file twrapform-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: twrapform-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for twrapform-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 64f0e7a811a8f4422e868c8d80da4d3803e673e01bf2e8bed229137ef3b1613e
MD5 9450fb863e5f0ef3a542a171865c6629
BLAKE2b-256 ff946014fbaf56457301293cd3f04a33c3b2f54b32daacb7071d76057b2b880f

See more details on using hashes here.

Provenance

The following attestation bundles were made for twrapform-0.0.5-py3-none-any.whl:

Publisher: publish-pypi.yml on minthem/twrapform

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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