https://github.com/cda0/terrajs
Node wrapper for terraform
https://github.com/cda0/terrajs
aws azure dev devops infrastructure nodejs terraform wrapper
Last synced: 7 months ago
JSON representation
Node wrapper for terraform
- Host: GitHub
- URL: https://github.com/cda0/terrajs
- Owner: CDA0
- Created: 2019-04-23T07:54:29.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T10:48:25.000Z (about 3 years ago)
- Last Synced: 2025-05-24T00:06:43.795Z (9 months ago)
- Topics: aws, azure, dev, devops, infrastructure, nodejs, terraform, wrapper
- Language: JavaScript
- Homepage:
- Size: 450 KB
- Stars: 7
- Watchers: 5
- Forks: 5
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Terrajs
[](https://travis-ci.org/CDA0/terrajs)
[](https://badge.fury.io/js/%40cda0%2Fterrajs)
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`.
```js
const tf = new Terrajs( { terraformDir: 'path/to/configuration' } );
await tf.init({ backendConfig: { key: 'MY_KEY' } });
```
To view the generated Terraform command without running:
```js
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.
```js
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:
```js
await tf.plan({
var: {
subscriptionId: '123',
tenantId: 'abc',
zones: ['A', 'B'],
}
});
```
...will be mapped to the following command:
```bash
terraform plan -var "subscription_id=123" -var "tenant_id=abc" -var 'zones=["A","B"]'
```
...or on Windows (Command Prompt):
```batch
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`][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.
[child-process]: https://nodejs.org/api/child_process.html#child_process_child_process_exec_command_options_callback