Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix(tfc/output): add error handling for no output #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 93 additions & 70 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
},
"dependencies": {
"command-line-args": "^5.2.0",
"follow-redirects": "^1.14.1"
"follow-redirects": "^1.14.1",
"yargs": "^17.2.0"
}
}
16 changes: 13 additions & 3 deletions scripts/shared/environment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { existsSync, readFileSync } = require('fs');
const path = require('path');
const yargs = require('yargs');

const currentEnv = {
TFCRC_PATH: undefined,
Expand All @@ -21,19 +22,28 @@ const Environment = (render) => {
});
}

const args = yargs(process.argv.slice(4))
.options('workspace', {
default: process.env.TFC_WORKSPACE || TFC_CONFIG.TFC_WORKSPACE || TFC_CONFIG.WORKSPACE_ID
})
.options('token', {
default: process.env.TFC_TOKEN || TFC_CONFIG.TFC_TOKEN
})
.argv;

currentEnv.config = {
// args: process.argv,
paths: {
pwd: process.env.PWD,
home: process.env.HOME,
},
secrets: {
TFC_TOKEN: process.env.TFC_TOKEN || TFC_CONFIG.TFC_TOKEN,
TFC_WORKSPACE: process.env.TFC_WORKSPACE || TFC_CONFIG.TFC_WORKSPACE || TFC_CONFIG.WORKSPACE_ID,
TFC_TOKEN: args.token,
TFC_WORKSPACE: args.workspace,
},
action: process.argv[3] || '',
resource: process.argv[2] || '',
args: process.argv.slice(4)
args
}
}

Expand Down
8 changes: 6 additions & 2 deletions scripts/terraform/resources/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,12 @@ const OUTPUT = {
const state = await Request('app.terraform.io', 'GET', `/api/v2/workspaces/${env.secrets.TFC_WORKSPACE}/current-state-version`, {
'Authorization': `Bearer ${env.secrets.TFC_TOKEN}`
});

const output_id = JSON.parse(state).data.relationships.outputs.data[0].id;
const stateObj = JSON.parse(state);
if (stateObj.data.relationships.outputs.data.length <= 0) {
console.log('error: No outputs in current workspace');
return;
}
const output_id = stateObj.data.relationships.outputs.data[0].id;

let outputs = await Request('app.terraform.io', 'GET', `/api/v2/state-version-outputs/${output_id}`, {
'Authorization': `Bearer ${env.secrets.TFC_TOKEN}`
Expand Down