UNPKG

@storm-software/terraform-tools

Version:

Tools for managing Terraform infrastructure within a Nx workspace.

54 lines (45 loc) 2.58 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); var _chunkOFLYCEQVjs = require('./chunk-OFLYCEQV.js'); var _chunk3GQAWCBQjs = require('./chunk-3GQAWCBQ.js'); // src/base/terraform-executor.ts var _shelljs = require('shelljs'); var withTerraformExecutor = /* @__PURE__ */ _chunk3GQAWCBQjs.__name.call(void 0, (command, executorOptions = {}) => async (_options, context) => { return _chunkOFLYCEQVjs.withRunExecutor.call(void 0, `Terraform \`${command}\` Command Executor`, async (options, context2, config) => { if (!_shelljs.which.call(void 0, "tofu") || !_shelljs.which.call(void 0, "terraform")) { throw new Error("Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor."); } if (!_shelljs.which.call(void 0, "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); } _chunkOFLYCEQVjs.run.call(void 0, 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"); exports.withTerraformExecutor = withTerraformExecutor;