@cda0/terrajs

0.6.1 • Public • Published

Terrajs

Build Status npm version

A module to help with creating Terraform commands.

Supported Commands

  • apply
  • fmt
  • get
  • graph
  • import
  • init
  • output
  • plan
  • providers
  • refresh
  • show
  • taint
  • untaint
  • validate
  • version
  • workspace
    • delete
    • list
    • new
    • select
    • show

Usage

Terrajs will run Terraform commands from the directory passed in with terraformDir.

const tf = new Terrajs( { terraformDir: 'path/to/configuration' } );
await tf.init({ backendConfig: { key: 'MY_KEY' } });

To view the generated Terraform command without running:

const tf = new Terrajs({ execute: false, terraformDir: 'path/to/configuration' });
console.log(await tf.init({ backendConfig: { key: 'MY_KEY' } }));

If you need to use a Terraform binary that's not on your path as terraform, then you can tell Terrajs where to find it in the constructor.

const tf = new Terrajs( { command: 'terraform12', terraformDir: 'path/to/configuration' } );
await tf.init({ backendConfig: { key: 'MY_KEY' } });

See example.js for a quick impression of how to use the extra commands.

Variables

Variables are mapped from JavaScript camelCase convention to Terraform CLI snake_case convention. For example:

await tf.plan({
  var: {
    subscriptionId: '123',
    tenantId: 'abc',
    zones: ['A', 'B'],
  }
});

...will be mapped to the following command:

terraform plan -var "subscription_id=123" -var "tenant_id=abc" -var 'zones=["A","B"]'

...or on Windows (Command Prompt):

terraform plan -var "subscription_id=123" -var "tenant_id=abc" -var "zones=[\"A\",\"B\"]"

If variables are not being represented as you expect, please set TF_LOG=trace and check to see what Terraform is receiving. Terrajs uses the default shell assumed by child_process which is generally /bin/sh and cmd.exe (on Windows). If a variable's value is quite complex with special characters, this may cause problems with the shell's interpolation.

Test

npm run test

Coverage

npm run coverage

Contributing

Terraform commands live in the templates directory.

Each command has a line for each partial, found in the partials directory.

A partial contains the logic for a command line argument.

Readme

Keywords

none

Package Sidebar

Install

npm i @cda0/terrajs

Weekly Downloads

11

Version

0.6.1

License

MIT

Unpacked Size

19.8 kB

Total Files

77

Last publish

Collaborators

  • cda0