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

Uploaded Python 3

File details

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

File metadata

  • Download URL: twrapform-0.0.4.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.4.tar.gz
Algorithm Hash digest
SHA256 07cccd4fd03ecac065226a943ec8d5213e8dd39f20034810f09a4e903a5f486c
MD5 40ec653c55140448e26a0deda489e257
BLAKE2b-256 c1a2c81736cd8841fd4a02bcba9b6081e6a5383fcbcd1765122b70553d3dfa87

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: twrapform-0.0.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 6f7ce891e61d79707c9c6d88fd226e285216778aef4789bb4d23c9aae890a04f
MD5 f45a9bb9c700ab9419fa537b15ad2e43
BLAKE2b-256 b7dc986b079df5ee19fc6d0de70571279a2848ec2552d30344d1d6bed395bd5e

See more details on using hashes here.

Provenance

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