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.6.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.6-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: twrapform-0.0.6.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.6.tar.gz
Algorithm Hash digest
SHA256 976d53ba7054bd73283dfeb7deced45c0f05b04f98f7a5792bb33298ca0a39e2
MD5 679d77f9ceb82ae59d1a177a384c9a52
BLAKE2b-256 3a9758f5e634977a6cada84b8243527e92bfb783a5078c5e428c405fdafd66dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for twrapform-0.0.6.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.6-py3-none-any.whl.

File metadata

  • Download URL: twrapform-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 11.4 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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 e5a3db5f9c38491ca241232c25879c833884d3395e41ededefce8b9637922067
MD5 d0e02dfacccdf3b93d8fee40d7d7b69d
BLAKE2b-256 a0132c51d6c5ac9b4d36e38bc94153799df3d3ade2a6b16a8c79ca526f2dc39b

See more details on using hashes here.

Provenance

The following attestation bundles were made for twrapform-0.0.6-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