PHPackages                             skluck/terraform-plan-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. skluck/terraform-plan-parser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

skluck/terraform-plan-parser
============================

A PHP parser for Hashicorp's Terraform plans

1.3.5(4y ago)25.9k1[1 issues](https://github.com/skluck/terraform-plan-parser/issues)MITPHPPHP &gt;=7.3

Since Mar 17Pushed 4y ago1 watchersCompare

[ Source](https://github.com/skluck/terraform-plan-parser)[ Packagist](https://packagist.org/packages/skluck/terraform-plan-parser)[ RSS](/packages/skluck-terraform-plan-parser/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (10)Dependencies (3)Versions (13)Used By (0)

[![CircleCI](https://camo.githubusercontent.com/e7177862b7a06520625a0bff4e5bbf29dd2214c4e421430d4a4b80e5bb5cfb99/68747470733a2f2f636972636c6563692e636f6d2f67682f736b6c75636b2f7465727261666f726d2d706c616e2d7061727365722e7376673f7374796c653d736869656c64)](https://circleci.com/gh/skluck/terraform-plan-parser)[![Latest Stable Version](https://camo.githubusercontent.com/b58ecd0d40373a37898f439fcd3664b79fd89e70b936f96c3095d6510d928258/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f736b6c75636b2f7465727261666f726d2d706c616e2d7061727365722e7376673f6c6162656c3d737461626c65)](https://packagist.org/packages/skluck/terraform-plan-parser)[![GitHub License](https://camo.githubusercontent.com/30a8b921d85f9048dc3366b32e9626f2999cc6bac6b9ab9a96f6a6336430d890/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f736b6c75636b2f7465727261666f726d2d706c616e2d7061727365722e737667)](https://packagist.org/packages/skluck/terraform-plan-parser)[![GitHub Language](https://camo.githubusercontent.com/9605091ad548d2e0e3fd09687da765ca12d85b045cd70e20e43ef6ab894adabf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f736b6c75636b2f7465727261666f726d2d706c616e2d7061727365722e737667)](https://camo.githubusercontent.com/9605091ad548d2e0e3fd09687da765ca12d85b045cd70e20e43ef6ab894adabf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c616e6775616765732f746f702f736b6c75636b2f7465727261666f726d2d706c616e2d7061727365722e737667)

Terraform Plan Parser
=====================

[](#terraform-plan-parser)

This is a PHP library for parsing output from `terraform plan`.

It will attempt to parse out **changed attributes** of modified resources from `terraform plan` as well as **used modules** from `terraform init`.

It supports both Terraform 0.11 and Terraform 0.12:

- [`Terraform11OutputParser`](src/Terraform11OutputParser.php)
- [`Terraform12OutputParser`](src/Terraform12OutputParser.php)

Terraform 0.12 supports native JSON output of plan files, however it is not as complete as the stdout and so we must continue to parse it.

Table of Contents
-----------------

[](#table-of-contents)

- [Use Case](#use-case)
- [Installation](#installation)
- [Usage](#usage)
- [Data Structure](#data-structure)

Use Case
--------

[](#use-case)

This library turns this:

```
Copying configuration from "git::https://git.example.com/terraform/module.git?ref=2.3.1"...

Initializing modules...
- module.fargate
  Getting source "./modules/fargate"

Initializing provider plugins...
- Checking for available provider plugins on https://releases.hashicorp.com...
- Downloading plugin for provider "aws" (2.2.0)...

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
    ~ update in-place
-/+ destroy and then create replacement
      (forces new resource)
        triggers.%:               "1" => "1"
        triggers.deploy_job_hash: "6c37ac7175bdf35e" => "1a0bd86fc5831ee6" (forces new resource)
```

into this:

```
{
    "changedResources": [
        {
            "action": "replace",
            "name": "promote_images",
            "fully_qualified_name": "null_resource.promote_images",
            "module_path": "",
            "is_new": true,
            "is_tainted": false,
            "attributes": {
                "id": {
                    "name": "id",
                    "force_new_resource": true,
                    "old": {
                        "type": "string",
                        "value": "1236159896537553123"
                    },
                    "new": {
                        "type": "computed",
                        "value": null
                    }
                },
                "triggers.%": {
                    "name": "triggers.%",
                    "force_new_resource": false,
                    "old": {
                        "type": "string",
                        "value": "1"
                    },
                    "new": {
                        "type": "string",
                        "value": "1"
                    }
                },
                "triggers.deploy_job_hash": {
                    "name": "triggers.deploy_job_hash",
                    "force_new_resource": true,
                    "old": {
                        "type": "string",
                        "value": "6c37ac7175bdf35e"
                    },
                    "new": {
                        "type": "string",
                        "value": "1a0bd86fc5831ee6"
                    }
                }
            }
        }
    ],
    "modules": [
        {
            "name": "module.fargate",
            "source": "./modules/fargate",
            "version": null
        },
        {
            "name": "root",
            "source": "git::https://git.example.com/terraform/module.git",
            "version": "2.3.1"
        }
    ]
}
```

This library is inspired and based on similar libraries for other languages. Check them out if PHP is not for you:

- [lifeomic/terraform-plan-parser](https://github.com/lifeomic/terraform-plan-parser) (typescript - cli)
- [chrislewisdev/prettyplan](https://github.com/chrislewisdev/prettyplan) (typescript - browser-based)

Installation
------------

[](#installation)

This package requires PHP 7.1 or higher. The CI workflow tests against PHP 7.1, 7.2, and 7.3. It has no runtime dependencies.

Download this package with composer:

```
composer require skluck/terraform-plan-parser ~1.1

```

Usage
-----

[](#usage)

```
