Skip to main content

terraformer

terraformer is a Python wrapper around the Terraform CLI.

Usage

Quick Start

terraformer usage centers around the Workspace object, which can be used to run the typical Terraform commands in that workspace. Just like with the CLI you have to initialize the workspace before you can run plans or applies.

from terraformer import Workspace

workspace = Workspace(path="./")
workspace.init()

results, plan = workspace.plan()

if !results.successful:
  raise Exception(f"Terraform run failed without output: {results.stdout}")

if plan.deletions > 0:
  raise Exception("Deletions not expected from this plan")

results, apply_log = workspace.apply(plan_path=plan.plan_path, auto_approve=True)

if !results.successful:
  print("Terraform Apply was not successful.")

for resource_name, resource_data in apply_log.resources.items():
  print(f"${resource_name}: ${resource['message']}")

for output_name, output_data in apply_log.outputs.items():
  print(f"{output_name}:\n")
  print(yaml.dumps(output_data))
  print("\n\n\n")

The plan step can be skipped if you are auto approving.

from terraformer import Workspace

workspace = Workspace(path="./")
workspace.init()
results, apply_log = workspace.apply(auto_approve=True)

There is also the capability to parse an existing plan JSON and create a plan object with the sensitive and unknown attributes sanitized in the output.

  import json

  plan_from_json = TerraformPlan("", "tests/terraform/plans/sensitive_plan.json", False)
  for address, resource_change in plan_from_json.changes:
    print(f"address: {address}\n")
    print("before:\n")
    print(json.dumps(resource_change.before_sanitized))
    print("\nafter:\n")
    print(json.dumps(resource_change.after_sanitized))

Installation

terraformer can be installed with pip.

pip install terraformer

In addition to terraformer you should have the Terraform binary installed on your system.

Release files for terraformer 0.3.1

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

Source distribution (sdist)

Source distribution for terraformer 0.3.1
File Size Uploaded
terraformer-0.3.1.tar.gz 38.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for terraformer 0.3.1
File Interpreter ABI Platform
terraformer-0.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 78.3 kB

Release files / terraformer-0.3.1.tar.gz

Download URL terraformer-0.3.1.tar.gz
Size 38.9 kB
Tags Source
SHA-256 checksum
How to use checksums
46c9077e12e7378c7b000970acb5db29b1ee1aefcdd4320d8bfb7f646895ff96
BLAKE2b-256 checksum
How to use checksums
6d0681f80f6e87f27a5fbcfaed71c7cb2dff09014c3979f3ec37aa3d8965d73a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release files / terraformer-0.3.1-py3-none-any.whl

Download URL terraformer-0.3.1-py3-none-any.whl
Size 39.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5cbd107f73ef29775f869b25b4240a0408110be6d46dfd809d21a67428a88a30
BLAKE2b-256 checksum
How to use checksums
36df2768c9344adc46c7549963e679cd51cde6496232d485236eee106f858226
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.11.4

Release history Release notifications | RSS feed

This release

0.3.1 This release

2 release files

0.2.0

2 release files

0.1.0

2 release files

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