Skip to content

Commit 298ffd8

Browse files
sarath.krishnan@slalom.com-at-617780835636sarath.krishnan@slalom.com-at-617780835636
sarath.krishnan@slalom.com-at-617780835636
authored and
sarath.krishnan@slalom.com-at-617780835636
committed
Initial commit
1 parent df2e0fb commit 298ffd8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+8524
-2
lines changed

README.md

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,50 @@
1-
# invoke-terraform-run-api
2-
Invokes Terraform Run API and return runId
1+
# Terraform Run
2+
3+
This action invoke Terraform Runs API
4+
https://www.terraform.io/docs/cloud/api/run.html
5+
6+
## Inputs
7+
8+
### `workSpaceName`
9+
10+
**Required** The name of the workspace.
11+
12+
### `organizationName`
13+
14+
**Required** Your Organization.
15+
16+
### `terraformToken`
17+
18+
**Required** Your Terraform token. Please use secret to store your Terraform token.
19+
20+
### `terraformHost`
21+
22+
**Required** This is the Terraform Host Name. For Tarraform cloud its app.terraform.io.
23+
24+
### `isDestroy`
25+
26+
**Required** Specifies if this plan is a destroy plan, which will destroy all provisioned resources.
27+
28+
### `message`
29+
30+
**Required** Specifies the message to be associated with this run.
31+
32+
## Outputs
33+
34+
### `runId`
35+
36+
The run ID.
37+
38+
## Example usage
39+
40+
```
41+
uses: sarathkrish/invoke-terraform-run@v1.0
42+
with:
43+
workSpaceName: MyTestWorkspace
44+
organizationName: {{env.organization}}
45+
terraformToken: {{secrets.Terraform_Token}}
46+
terraformHost: 'app.terraform.io'
47+
isDestroy: false
48+
message: 'GitHub Actions'
49+
50+
```

action.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: 'Run Terraform'
2+
description: 'Invoke Terraform API to run Terraform'
3+
inputs:
4+
workSpaceName:
5+
description: 'Terraform workspace name'
6+
required: true
7+
organizationName:
8+
description: 'Terraform organization Name'
9+
required: true
10+
terraformToken:
11+
description: 'Terraform Token'
12+
required: true
13+
terraformHost:
14+
description: 'Terraform Host Name'
15+
required: true
16+
isDestroy:
17+
description: 'Specifies if this plan is a destroy plan, which will destroy all provisioned resources'
18+
required: true
19+
message:
20+
description: 'Specifies the message to be associated with this run.'
21+
required: true
22+
outputs:
23+
runId:
24+
description: 'The run ID'
25+
runs:
26+
using: 'node12'
27+
main: 'index.js'
28+
29+
branding:
30+
icon: 'play'
31+
color: 'green'

index.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
const core = require('@actions/core');
2+
const axios = require('axios');
3+
4+
async function main() {
5+
6+
try{
7+
const workSpaceName = core.getInput('workSpaceName');
8+
const organizationName = core.getInput('organizationName');
9+
const token = core.getInput('terraformToken');
10+
const terraformHost = core.getInput('terraformHost');
11+
const isDestroy = core.getInput('isDestroy');
12+
const message = core.getInput('message');
13+
14+
const options = {
15+
headers: {'Content-Type': 'application/vnd.api+json',
16+
'Authorization': 'Bearer '+token
17+
}
18+
};
19+
20+
// Fetching WorkSpaceId
21+
const terraformWorkSpaceEndpoint = "https://"+terraformHost+"/api/v2/organizations/"+organizationName+"/workspaces/"+workSpaceName;
22+
const response = await axios.get(terraformWorkSpaceEndpoint,options);
23+
const workSpaceId = response.data.data.id;
24+
console.log("workSpaceId:"+workSpaceId)
25+
26+
const terraformRunEndpoint = "https://"+terraformHost+"/api/v2/runs";
27+
let request = { data : {
28+
attributes: { "is-destroy" : isDestroy, "message" : message },
29+
type: "runs",
30+
relationships: {
31+
workspace: {
32+
data: {
33+
type: "workspaces",
34+
id: workSpaceId
35+
}
36+
}
37+
}
38+
}};
39+
console.log("run request:" + JSON.stringify(request));
40+
41+
// Invoking Terraform Run API
42+
axios.post(terraformRunEndpoint, request, options)
43+
.then((response) => {
44+
console.log("run success:"+ JSON.stringify(response.data));
45+
core.setOutput("runId", response.data.data.id);
46+
}, (error) => {
47+
console.error("run error:"+JSON.stringify(error.response.data));
48+
core.setFailed(error.message);
49+
});
50+
51+
} catch(error){
52+
core.setFailed(error.message);
53+
}
54+
}
55+
56+
main();

node_modules/@actions/core/README.md

Lines changed: 146 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.d.ts

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js

Lines changed: 78 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/@actions/core/lib/command.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)