Metadata-Version: 2.1
Name: terraformer
Version: 0.3.1
Summary: A python library
Author-email: Robert Hafner <robert@tedivm.com>
License: MIT License
        
        Copyright (c) 2022 Aptible
        Copyright (c) 2023 Robert Hafner
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
        
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Provides-Extra: dev
License-File: LICENSE

# 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.

```python
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.

```python
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.

```python
  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.

```bash
pip install terraformer
```

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