-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathterraform.js
70 lines (56 loc) · 2.06 KB
/
terraform.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import assert from "assert"
import core from "@actions/core"
import Tool from "./tool.js"
export default class Terraform extends Tool {
static tool = "terraform"
static envVar = "TFENV_ROOT"
static installer = "tfenv"
constructor() {
super(Terraform.tool)
}
async setup(desiredVersion) {
const [checkVersion, isVersionOverridden] = this.getVersion(
desiredVersion,
".terraform-version",
)
if (!(await this.haveVersion(checkVersion))) {
return checkVersion
}
// Check if tfenv exists and can be run, and capture the version info while
// we're at it
await this.findInstaller()
// Set downstream environment variable for future steps in this Job
if (isVersionOverridden) {
core.exportVariable("TFENV_TERRAFORM_VERSION", checkVersion)
}
// Make sure we have the desired terraform version installed (may be
// pre-installed on self-hosted runners)
await this.subprocessShell("tfenv install").catch(
this.logAndExit("install failed"),
)
// Sanity check the terraform command works, and output its version
await this.validateVersion(checkVersion)
// If we got this far, we have successfully configured terraform.
core.setOutput(Terraform.tool, checkVersion)
this.info("terraform success!")
return checkVersion
}
/**
* Download and configures tfenv.
*
* @param {string} root - Directory to install tfenv into (TFENV_ROOT).
* @return {string} The value of TFENV_ROOT.
*/
async install(root) {
assert(root, "root is required")
const gh = `https://${
process.env.GITHUB_SERVER ?? "github.com"
}/tfutils`
const url = `${gh}/tfenv/archive/refs/heads/master.tar.gz`
root = await this.downloadTool(url, { dest: root, strip: 1 })
this.info(`Downloaded tfenv to ${root}`)
return root
}
}
// Register the subclass in our tool list
Terraform.register()