Skip to content

Commit

Permalink
Fix Terraform plan group output (#50)
Browse files Browse the repository at this point in the history
* fix group

* seperate group

* move end
  • Loading branch information
drsherluck authored Jan 16, 2023
1 parent 465963e commit b7f4787
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23957,6 +23957,7 @@ async function terraform(terraformDirectory, args) {
core.startGroup('Run terraform plan');
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, `-refresh=${terraformRefresh}`, '-out=terraform.plan', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy));
core.endGroup();

if (tfp.status == 1) { // 0 = no error no changes, 1 = error, 2 = no error with changes (from -detailed-exitcode documentation)
tf_plan = status_failed;
core.setFailed(`Failed to prepare the terraform plan [err:${tfp.status}]`);
Expand All @@ -23965,6 +23966,7 @@ async function terraform(terraformDirectory, args) {
tf_plan = status_success;
}

core.startGroup('Save terraform change status');
core.setOutput('changes', tfp.status == 2 ? 'true' : 'false');

// write to file and upload to artifact storage
Expand All @@ -23979,6 +23981,8 @@ async function terraform(terraformDirectory, args) {
};
const artifactClient = artifact.create();
const uploadResponse = await artifactClient.uploadArtifact('terraform', [fileName], '.', options);
core.endGroup();

if (uploadResponse.failedItems.length > 0) {
core.setFailed('Failed to upload artfiact');
}
Expand Down
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ async function terraform(terraformDirectory, args) {
core.startGroup('Run terraform plan');
const tfp = await terraform(terraformDirectory, ['plan', `-lock=${terraformLock}`, `-parallelism=${terraformParallelism}`, `-refresh=${terraformRefresh}`, '-out=terraform.plan', '-detailed-exitcode'].concat(terraformTargets).concat(terraformVariableFiles).concat(terraformPlanDestroy));
core.endGroup();

if (tfp.status == 1) { // 0 = no error no changes, 1 = error, 2 = no error with changes (from -detailed-exitcode documentation)
tf_plan = status_failed;
core.setFailed(`Failed to prepare the terraform plan [err:${tfp.status}]`);
Expand All @@ -241,6 +242,7 @@ async function terraform(terraformDirectory, args) {
tf_plan = status_success;
}

core.startGroup('Save terraform change status');
core.setOutput('changes', tfp.status == 2 ? 'true' : 'false');

// write to file and upload to artifact storage
Expand All @@ -255,6 +257,8 @@ async function terraform(terraformDirectory, args) {
};
const artifactClient = artifact.create();
const uploadResponse = await artifactClient.uploadArtifact('terraform', [fileName], '.', options);
core.endGroup();

if (uploadResponse.failedItems.length > 0) {
core.setFailed('Failed to upload artfiact');
}
Expand Down

0 comments on commit b7f4787

Please sign in to comment.