# terraform-get-plan

> A simple node library for running terraform plans and retrieving the result.

Latest version **0.0.2** (published 2020-01-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install terraform-get-plan
pnpm add terraform-get-plan
yarn add terraform-get-plan
bun add terraform-get-plan
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-01-17 |
| First published | 2020-01-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 5.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | jdhornsby |
| Maintainers | jdhornsby |
| Keywords | terraform, plan, test |

## Links

- npm: https://www.npmjs.com/package/terraform-get-plan
- Repository: https://github.com/jdhornsby/terraform-get-plan
- Homepage: https://github.com/jdhornsby/terraform-get-plan#readme
- Issues: https://github.com/jdhornsby/terraform-get-plan/issues
- npm.io page: https://npm.io/package/terraform-get-plan

## Dependencies (3)

- [jest](https://npm.io/package/jest.md) ^24.9.0
- [execa](https://npm.io/package/execa.md) ^4.0.0
- [randomstring](https://npm.io/package/randomstring.md) ^1.1.5

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 0.0.2 (latest) — 2020-01-17
- 0.0.1 — 2020-01-17

## README

# Terraform Get Plan

This simple library allows you to execute a Terraform plan from your Node.js application and retrieve the resulting plan as JSON or a native object.

## Usage

Require the module:

```js
const {getPlan} = require('terraform-get-plan');
```

You can run the plan on the current working directory:

```js
const plan = await getPlan();
```

You can run the plan on a different directory:

```js
const plan = await getPlan({workingDirectory: '/Users/tf'});
```

You can define a terraform file inline:
```js
const plan = await getPlan({
    terraform: `
    provider "aws" {
        region                      = "us-east-1"
        skip_credentials_validation = true
        skip_requesting_account_id  = true
        skip_metadata_api_check     = true
        s3_force_path_style         = true
        access_key                  = "mock_access_key"
        secret_key                  = "mock_secret_key"
    
    }
    
    resource "aws_ssm_parameter" "foo" {
        name  = "foo"
        type  = "String"
        value = "bar"
    }
    `
});
```

## Use Cases

My primary use case for writing this is so I can write `jest` tests on Terraform modules I am designing. These are not a replacement for a full integration suite, but having a fast static feedback loop is really important when writing code. This helps enable that. I am sure there are other use cases, too.

Here's an example:

```js
const {getPlan} = require('terraform-get-plan');

jest.setTimeout(120000); // plan can be slow...

test('Expect the module to work...', async () => {
    const plan = await getPlan({terraform: 
    `
    provider "aws" {
        alias                       = "mock"
        region                      = "us-east-1"
        skip_credentials_validation = true
        skip_requesting_account_id  = true
        skip_metadata_api_check     = true
        s3_force_path_style         = true
        access_key                  = "mock_access_key"
        secret_key                  = "mock_secret_key"
    }

    module "test" {
        source = "./terraform"
        value  = "hello"
        providers = {
            aws = aws.mock
        }
    }
    `
    });
    expect(plan.planned_values.root_module.child_modules[0].resources[0].type).toBe('aws_ssm_parameter');
    expect(plan.planned_values.root_module.child_modules[0].resources[0].name).toBe('my_param');
    expect(plan.planned_values.root_module.child_modules[0].resources[0].values.value).toBe('hello');
});
```

---
_Source: https://npm.io/package/terraform-get-plan · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
