Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

PieTerraform

This is a wrapper for terraform to facilitate python developer to call terraform. It is designed to invoke terraform commands in "Functional Chaining" style

Note: Only python>=3.7 is supported.

Features

  • Builder pattern. One line code can call multiple terraform commands
  • Terraform commands' arguments are encapsulated as functions so code completion supported
  • No need to worry about the sequence of arguments

Usage

Make sure have terraform in $PATH

terraform version

Install

pip install pieterraform

Quick start

from pieterraform import Terraform

# suppose you have terraform files in ./tf
Terraform().workdir('./tf')
    .init().run()           # 'terraform init'
    .plan().run()           # 'terraform plan'
    .apply().run()          # 'terraform apply'

# suppose you have terraform files in ./tf/prod
Terraform().workdir('./tf')
    .init().dir('prod').run()
    .plan().dir('prod').run()
    .apply().dir('prod').run()

# suppose you have terraform files in ./tf/prod
Terraform().workdir()
    .init().dir('tf/prod').run()
    .plan().dir('tf/prod').run()
    .apply().dir('tf/prod').run()

Just ONE LINE code!

With Paramers

from pieterraform import Terraform

# suppose you have terraform files in ./tf
Terraform().workdir('./tf')
    # 'terraform init -no-color -upgrade=false'
    .init().no_upgrade().no_color().run()
    # 'terraform plan -state mystate.json -no-color'
    .plan().state_file('mystate.json').no_color().out('myplan').run()
    # 'terraform apply myplan'
    .apply().use_plan('myplan').run()
    # 'terraform destroy -auto-approve -state mystate.json'
    .destroy().auto_approve().state('mystate.json').run()

With Custome Log

By default it prints log in screen. But you can cusomize it to use any logger

import logging
from pieterraform import Terraform

# output log to file
logFormatter = logging.Formatter('%(asctime)s [%(levelname)-5.5s] %(message)s')
log_file = 'log.txt'
f_handler = logging.FileHandler(log_file)
f_handler.setFormatter(logFormatter)
f_handler.setLevel(logging.DEBUG)
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger.addHandler(f_handler)

# suppose you have terraform files in ./tf
Terraform(logger=logger) # this will output log to file 'log.txt'
    .workdir('./tf')
    .init().run()
    .plan().run()
    .apply().run()

Traditional calls rather than functions chain

from pieterraform import Terraform

tf = Terraform().workdir('./tf')
initer = tf.init()
initer.no_upgrade()
initer.no_color().run()
planer = tf.plan()
planer.state_file('mystate.json')
planer.no_color()
planer.out('myplan').run()
applyer = tf.apply()
applyer.use_plan('myplan')
applyer.run()

Check result

from pieterraform import Terraform

a_run = Terraform().workdir('./tf')
    .init().run()
    .plan().run()
    .apply().run()

for r in a_run.results:
    print(r.output)
    print(r.command)

Source Code

This project is fully using docker as dev environment.

Prerequisition

  • docker: ">= 17.06"
  • docker-compose: ">= 1.26"

No python needed.

Build

make

Install to local

make install

Run test

make test

Distribution

make dist

Development

Start dev docker

make docker-dev

this will start a container named pieterraform-devenv

Use VSCode

Open your vscode, attach to above container to do remote development

Metadata

Release files for pieterraform 0.0.1a15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pieterraform 0.0.1a15
File Size Uploaded Provenance Actions
pieterraform-0.0.1a15.tar.gz 6.6 kB Without provenance Details for pieterraform-0.0.1a15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pieterraform 0.0.1a15
File Interpreter ABI Platform Actions
pieterraform-0.0.1a15-py3-none-any.whl Python 3 none any Details for pieterraform-0.0.1a15-py3-none-any.whl

Total release size: 16.1 kB

Release files / pieterraform-0.0.1a15.tar.gz

Download URL pieterraform-0.0.1a15.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
7d6f7870332c3f09682a2d7fa5f88fa69d989fb89d1a61dfc05565a23192197a
BLAKE2b-256 checksum
How to use checksums
19045c1d01d55cb2770d746c6af61eaca8b22cc66010667cd8614dc881af5ac3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

Release files / pieterraform-0.0.1a15-py3-none-any.whl

Download URL pieterraform-0.0.1a15-py3-none-any.whl
Size 9.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ccf30ea85f07a71cb0fc969a0e897028e237c899135e09b60136bf8fc7d73b42
BLAKE2b-256 checksum
How to use checksums
2616f488c95e17ee6aeb0b36b0153cef91e9da5df5ef30ff51d84ad0e37207fd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.9

Security for pieterraform 0.0.1a15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page