UNPKG

@jahed/terraform

Version:

A wrapper which downloads and runs Terraform locally via npm.

28 lines (27 loc) 1.38 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.downloadTerraformToMemory = downloadTerraformToMemory; const node_crypto_1 = __importDefault(require("node:crypto")); const download_1 = require("./download"); const getArchitecture_1 = require("./getArchitecture"); const getDownloadUrl_1 = require("./getDownloadUrl"); const getExpectedHash_1 = require("./getExpectedHash"); const getPlatform_1 = require("./getPlatform"); const getVersion_1 = require("./getVersion"); async function downloadTerraformToMemory(outputs) { const version = (0, getVersion_1.getVersion)(outputs); const platform = (0, getPlatform_1.getPlatform)(); const architecture = (0, getArchitecture_1.getArchitecture)(); const downloadArgs = { version, platform, architecture }; const url = (0, getDownloadUrl_1.getDownloadUrl)(downloadArgs); const buffer = await (0, download_1.download)(url); const expectedHash = await (0, getExpectedHash_1.getExpectedHash)(downloadArgs); const hash = node_crypto_1.default.createHash("sha256").update(buffer).digest("hex"); if (hash !== expectedHash) { throw new Error("downloaded archive hash did not match expected hash"); } return buffer; }