Skip to content

Commit 029e39e

Browse files
committed
feat(terraform/state): add subcommand to get latest state in a workspace
1 parent 51699eb commit 029e39e

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

scripts/terraform/resources/state.js

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1+
const Environment = require("../../shared/environment");
2+
const Request = require("../../shared/request");
3+
const Help = require("../help");
4+
const URL = require('url');
5+
const { writeFileSync, existsSync } = require("fs");
6+
17
const OUTPUT = {
2-
get: () => {
3-
throw "not implimented";
8+
get: async (...args) => {
9+
const env = Environment();
10+
if (!env.secrets.TFC_TOKEN) {
11+
Help('Missing TFC_TOKEN.');
12+
}
13+
if (!env.secrets.TFC_WORKSPACE) {
14+
Help('Missing TFC_WORKSPACE.');
15+
}
16+
const response = await Request('app.terraform.io', 'GET', `/api/v2/workspaces/${env.secrets.TFC_WORKSPACE}/current-state-version`, {
17+
'Authorization': `Bearer ${env.secrets.TFC_TOKEN}`
18+
});
19+
20+
const stateURL = URL.parse(JSON.parse(response).data.attributes['hosted-state-download-url']);
21+
const stateResponse = await Request(stateURL.hostname, 'GET', stateURL.path, {
22+
'Authorization': `Bearer ${env.secrets.TFC_TOKEN}`
23+
});
24+
25+
console.log(stateResponse)
426
},
527

628
set: () => {

0 commit comments

Comments
 (0)