A python library
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file terraformer-0.3.1.tar.gz
.
File metadata
- Download URL: terraformer-0.3.1.tar.gz
- Upload date:
- Size: 38.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46c9077e12e7378c7b000970acb5db29b1ee1aefcdd4320d8bfb7f646895ff96 |
|
MD5 | c084a41295361b85331c90600502c4a4 |
|
BLAKE2b-256 | 6d0681f80f6e87f27a5fbcfaed71c7cb2dff09014c3979f3ec37aa3d8965d73a |
File details
Details for the file terraformer-0.3.1-py3-none-any.whl
.
File metadata
- Download URL: terraformer-0.3.1-py3-none-any.whl
- Upload date:
- Size: 39.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cbd107f73ef29775f869b25b4240a0408110be6d46dfd809d21a67428a88a30 |
|
MD5 | 77401d0ff39fd9f158a8519560a37a45 |
|
BLAKE2b-256 | 36df2768c9344adc46c7549963e679cd51cde6496232d485236eee106f858226 |