UNPKG

@storm-software/terraform-tools

Version:

Tools for managing Terraform infrastructure within a Nx workspace.

54 lines (51 loc) 2.33 kB
import { run, withRunExecutor } from "./chunk-QVS5QXGT.mjs"; import { __name } from "./chunk-2BPV2XV2.mjs"; // src/base/terraform-executor.ts import { which } from "shelljs"; var withTerraformExecutor = /* @__PURE__ */ __name((command, executorOptions = {}) => async (_options, context) => { return withRunExecutor(`Terraform \`${command}\` Command Executor`, async (options, context2, config) => { if (!which("tofu") || !which("terraform")) { throw new Error("Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor."); } if (!which("terragrunt")) { throw new Error("Terragrunt is not installed. Please install them before running this executor."); } const { backendConfig = [], planFile, autoApproval, formatWrite, upgrade, migrateState, lock, varFile, varString, reconfigure } = options; let jsonBackendConfig = backendConfig; if (typeof jsonBackendConfig === "string") { jsonBackendConfig = JSON.parse(jsonBackendConfig); } run(config, [ "terragrunt", command, ...jsonBackendConfig.map((config2) => `-backend-config="${config2.key}=${config2.name}"`), command === "plan" && planFile && `-out ${planFile}`, command === "plan" && varFile && `--var-file ${varFile}`, command === "plan" && varString && `--var ${varString}`, command === "destroy" && autoApproval && "-auto-approve", command === "apply" && autoApproval && "-auto-approve", command === "apply" && planFile, command === "apply" && varString && `--var ${varString}`, command === "fmt" && "--recursive", command === "fmt" && !formatWrite && "--check --list", command === "init" && upgrade && "-upgrade", command === "init" && migrateState && "-migrate-state", command === "init" && reconfigure && "-reconfigure", command === "providers" && lock && "lock", command === "test" && varFile && `--var-file ${varFile}`, command === "test" && varString && `--var ${varString}` ].filter(Boolean).join(" "), options.sourceRoot, "inherit", process.env.CI ? { TF_IN_AUTOMATION: "true", TF_INPUT: "0" } : {}); return null; }, executorOptions)(_options, context); }, "withTerraformExecutor"); export { withTerraformExecutor };