Metadata-Version: 2.1
Name: flatplan
Version: 1.1.0
Summary: Flatplan is a tool that groups all resources and providers specified in a Terraform plan file
Home-page: https://github.com/egonbraun/python-project-template
Author: Egon Braun
Author-email: egon@mundoalem.io
License: UNKNOWN
Project-URL: Bug Reports, https://github.com/egonbraun/flatplan/issues
Project-URL: Source, https://github.com/egonbraun/flatplan
Keywords: terraform,plan,tools,cli
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Topic :: Software Development :: Build Tools
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.7, <4
Description-Content-Type: text/markdown
Requires-Dist: colorama
Requires-Dist: coloredlogs
Requires-Dist: fire
Provides-Extra: dev
Requires-Dist: black ; extra == 'dev'
Requires-Dist: coverage ; extra == 'dev'
Requires-Dist: pytest ; extra == 'dev'
Requires-Dist: sphinx ; extra == 'dev'
Requires-Dist: tox ; extra == 'dev'
Requires-Dist: twine ; extra == 'dev'

# Flatplan


![](https://github.com/egonbraun/flatplan/workflows/CI/badge.svg)

Flatplan is a command line tool that can be used to *flatten* the resources and providers found inside a terraform plan.
You can obtain a JSON version of the plan by running:

```bash
terraform plan -out=planfile
terraform show -json planfile > plan.json
```

Now, we can feed our exported JSON plan to flatplan:

```bash
flatplan --plan=plan.json --output=flattened_plan.json --debug
```

The problem we are trying to solve with flatplan is that, when you export the plan to JSON the resources might be in
different locations which makes it hard for other tools to find them. Therefore, flatplan will extract all resources and
providers for you and return a much simpler JSON structure.

For example, let's say we have a complex terraform project that uses many modules and submodules. When we create the
plan file for this project and then export it to JSON we might end up with something like this:

```json
{
    ...
    "planned_values": {
        "root_module": {
            "resources": [
                ... a lot of resources here ...
            ],
            "child_modules": [{
                "resources": [
                    ... a lot of resources here ...
                ],
                "child_modules": [{
                    "resources": [
                        ... a lot of resources here ...
                    ],
                    "child_modules": [{
                        ... and so on ...
                    }]
                }]
            }, {
                "resources": [
                    ... a lot of resources here ...
                ],
                "child_modules": [{
                    "resources": [
                        ... a lot of resources here ...
                    ],
                    "child_modules": [{
                        ... and so on ...
                    }]
                }]
            }]
        }
    },
    ...
    "configuration": {
        "provider_config": {
            "aws": {
                "name": "aws",
                "expressions": {
                    "region": {
                        "constant_value": "us-east-1"
                    }
                }
            }
        }
    }
}
```

As you can see this recursive nature of the plan can get quite ugly if you use a lot of modules and submodules. After,
flatplan process this file we will get:

```json
{
    "resources": [ ... all resources here ... ],
    "providers": [ ... all providers here ... ]
}
```

This makes it easy for tools like Open Policy Agent to process our file since it has no way to recursively traverse a
raw terraform plan.

## Install


If you use pip:

```bash
pip install flatplan
```

If you use pipx:

```bash
pipx install flatplan
```

## Usage

Flatplan accepts the following command line parameters:

`--debug`: Sets log level to debug, default: False.

`--output="path"`: Writes flattened plan to the specified path, default: STDOUT.

`--plan="path"`: Reads JSON plan from the specified path, default: STDIN.

`--remove="tag=value"`: Removes the resources that contain a certain tag, default: empty

Example:

```bash
flatplan --debug --output=flattened.json --plan=plan.json --remove="remove=true"
```


