A module to help with creating Terraform commands.
apply
fmt
get
graph
import
init
output
plan
providers
refresh
show
taint
untaint
validate
version
workspace
delete
list
new
select
show
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 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.
npm run test
npm run coverage
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.