mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-15 16:12:35 +00:00
Initial commit
This commit is contained in:
commit
cd5e05ffbf
23 changed files with 26743 additions and 0 deletions
48
wrapper/terraform.js
Executable file
48
wrapper/terraform.js
Executable file
|
|
@ -0,0 +1,48 @@
|
|||
#!/usr/bin/env node
|
||||
const io = require('@actions/io');
|
||||
const core = require('@actions/core');
|
||||
const { exec } = require('@actions/exec');
|
||||
|
||||
const OutputListener = require('./lib/output-listener');
|
||||
const pathToCLI = require('./lib/terraform-bin');
|
||||
|
||||
async function checkTerraform () {
|
||||
// Setting check to `true` will cause `which` to throw if terraform isn't found
|
||||
const check = true;
|
||||
return io.which(pathToCLI, check);
|
||||
}
|
||||
|
||||
(async () => {
|
||||
// This will fail if Terraform isn't found, which is what we want
|
||||
await checkTerraform();
|
||||
|
||||
// Create listeners to receive output (in memory) as well
|
||||
const stdout = new OutputListener();
|
||||
const stderr = new OutputListener();
|
||||
const listeners = {
|
||||
stdout: stdout.listener,
|
||||
stderr: stderr.listener
|
||||
};
|
||||
|
||||
// Execute terraform and capture output
|
||||
const args = process.argv.slice(2);
|
||||
const options = {
|
||||
listeners,
|
||||
ignoreReturnCode: true
|
||||
};
|
||||
const exitCode = await exec(pathToCLI, args, options);
|
||||
core.debug(`Terraform exited with code ${exitCode}.`);
|
||||
core.debug(`stdout: ${stdout.contents}`);
|
||||
core.debug(`stderr: ${stderr.contents}`);
|
||||
core.debug(`exitcode: ${exitCode}`);
|
||||
|
||||
// Set outputs, result, exitcode, and stderr
|
||||
core.setOutput('stdout', stdout.contents);
|
||||
core.setOutput('stderr', stderr.contents);
|
||||
core.setOutput('exitcode', exitCode.toString(10));
|
||||
|
||||
// A non-zero exitCode is considered an error
|
||||
if (exitCode !== 0) {
|
||||
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
||||
}
|
||||
})();
|
||||
Loading…
Add table
Add a link
Reference in a new issue