Skip to content

Commit 4e65479

Browse files
committed
feat(terraform/workspace): add support for missing workspace or organization
1 parent 85cec22 commit 4e65479

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

scripts/terraform/resources/workspace.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,16 @@ const WORKSPACE = {
1919

2020
list: async (args, returnOnly) => {
2121
if (!args[0]) {
22-
throw 'Organisation Missing'
22+
let responseOrgs = await Request('app.terraform.io', 'GET', `/api/v2/organizations/`, {
23+
'Authorization': `Bearer ${Environment().secrets.TFC_TOKEN}`
24+
});
25+
let errorString = 'Organization Missing\nPlease pass organization from list below:\n';
26+
JSON.parse(responseOrgs).data.forEach(org => {
27+
errorString += ` - ${org.id}\n`
28+
})
29+
throw errorString;
2330
}
31+
2432
const org = args[0];
2533

2634
let response = await Request('app.terraform.io', 'GET', `/api/v2/organizations/${org}/workspaces`, {
@@ -29,6 +37,9 @@ const WORKSPACE = {
2937
response = JSON.parse(response);
3038
if (response.errors) {
3139
response.errors.forEach(error => {
40+
if (error.status == 404) {
41+
throw `Organization ${org} not found.`
42+
}
3243
console.log(`error: [${error.status}] ${error.title}`);
3344
});
3445
throw "";

0 commit comments

Comments
 (0)