@powerlines/plugin-terraform 0.1.56 → 0.1.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,29 @@
1
- var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") {
10
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
+ key = keys[i];
12
+ if (!__hasOwnProp.call(to, key) && key !== except) {
13
+ __defProp(to, key, {
14
+ get: ((k) => from[k]).bind(null, key),
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ }
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+
27
+ //#endregion
28
+
29
+ exports.__toESM = __toESM;
package/dist/index.cjs CHANGED
@@ -1 +1,90 @@
1
- Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});const e=require(`./_virtual/_rolldown/runtime.cjs`);let t=require(`@stryke/string-format/kebab-case`),n=require(`@stryke/type-checks`),r=require(`defu`);r=e.__toESM(r,1);let i=require(`execa`),a=require(`powerlines/plugin-utils`),o=require(`shelljs`);const s=(e={})=>[{name:`terraform`,async config(){return{deploy:{terraform:(0,r.default)(e,{autoApproval:!1,planFile:`plan.out`,formatWrite:!1,upgrade:!1,destroy:!1,migrateState:!1,lock:!0,reconfigure:!1})}}},async configResolved(){this.terraform??={};let e=(0,o.which)(`terragrunt`)?`terragrunt`:(0,o.which)(`tofu`)?`tofu`:(0,o.which)(`terraform`)?`terraform`:null;if(!e)throw Error(`Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.`);this.terraform.command=e;let n=(0,t.kebabCase)((0,a.getOrganizationName)(this)),r=(0,t.kebabCase)(await(0,a.getWorkspaceName)(this)),i=(0,t.kebabCase)(this.config.name);this.config.terraform.stackName??=`${n||r||i}-${r&&r!==n&&r!==i?`${r}-`:``}${i}-${this.config.mode}`},async deploy(){this.info(`Creating resources for Terraform stack: ${this.config.terraform.stackName}`),await this.$$internal.callHook(`terraform:deploy`,{sequential:!0}),this.info(`Deploying Terraform stack: ${this.config.terraform.stackName}`),this.config.terraform.destroy&&await(0,i.execaCommand)([this.terraform.command,this.terraform.command===`terragrunt`?this.config.terraform.stackName:void 0,`destroy`,this.config.terraform.autoApproval&&`--auto-approve`,this.config.terraform.varFile&&`--var ${this.config.terraform.varFile}`,(0,n.isSetString)(this.config.terraform.planFile)&&this.config.terraform.planFile].filter(Boolean).join(` `),{preferLocal:!0,shell:!0,stdio:`inherit`,cwd:this.infrastructurePath,env:this.config.mode===`production`?{TF_IN_AUTOMATION:`true`,TF_INPUT:`0`}:{}}),await(0,i.execaCommand)([this.terraform.command,this.terraform.command===`terragrunt`?this.config.terraform.stackName:void 0,`apply`,this.config.terraform.autoApproval&&`--auto-approve`,this.config.terraform.varFile&&`--var ${this.config.terraform.varFile}`,(0,n.isSetString)(this.config.terraform.planFile)&&this.config.terraform.planFile].filter(Boolean).join(` `),{preferLocal:!0,shell:!0,stdio:`inherit`,cwd:this.infrastructurePath,env:this.config.mode===`production`?{TF_IN_AUTOMATION:`true`,TF_INPUT:`0`}:{}}),this.info(`Successfully deployed ${this.config.terraform.stackName}`)}}];exports.default=s,exports.plugin=s;
1
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
2
+ const require_runtime = require('./_virtual/_rolldown/runtime.cjs');
3
+ let _stryke_string_format_kebab_case = require("@stryke/string-format/kebab-case");
4
+ let _stryke_type_checks = require("@stryke/type-checks");
5
+ let defu = require("defu");
6
+ defu = require_runtime.__toESM(defu, 1);
7
+ let execa = require("execa");
8
+ let powerlines_plugin_utils = require("powerlines/plugin-utils");
9
+ let shelljs = require("shelljs");
10
+
11
+ //#region src/index.ts
12
+ /**
13
+ * A package containing a Powerlines plugin to configure infrastructure and deploy a project using Terraform IaC.
14
+ *
15
+ * @see https://www.terraform.io
16
+ *
17
+ * @param options - The Terraform plugin user configuration options.
18
+ * @returns A Powerlines plugin to configure infrastructure and deploy a project using Terraform.
19
+ */
20
+ const plugin = (options = {}) => {
21
+ return [{
22
+ name: "terraform",
23
+ async config() {
24
+ return { deploy: { terraform: (0, defu.default)(options, {
25
+ autoApproval: false,
26
+ planFile: "plan.out",
27
+ formatWrite: false,
28
+ upgrade: false,
29
+ destroy: false,
30
+ migrateState: false,
31
+ lock: true,
32
+ reconfigure: false
33
+ }) } };
34
+ },
35
+ async configResolved() {
36
+ this.terraform ??= {};
37
+ const command = (0, shelljs.which)("terragrunt") ? "terragrunt" : (0, shelljs.which)("tofu") ? "tofu" : (0, shelljs.which)("terraform") ? "terraform" : null;
38
+ if (!command) throw new Error("Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.");
39
+ this.terraform.command = command;
40
+ const organizationName = (0, _stryke_string_format_kebab_case.kebabCase)((0, powerlines_plugin_utils.getOrganizationName)(this));
41
+ const workspaceName = (0, _stryke_string_format_kebab_case.kebabCase)(await (0, powerlines_plugin_utils.getWorkspaceName)(this));
42
+ const projectName = (0, _stryke_string_format_kebab_case.kebabCase)(this.config.name);
43
+ this.config.terraform.stackName ??= `${organizationName || workspaceName || projectName}-${workspaceName && workspaceName !== organizationName && workspaceName !== projectName ? `${workspaceName}-` : ""}${projectName}-${this.config.mode}`;
44
+ },
45
+ async deploy() {
46
+ this.info(`Creating resources for Terraform stack: ${this.config.terraform.stackName}`);
47
+ await this.$$internal.callHook("terraform:deploy", { sequential: true });
48
+ this.info(`Deploying Terraform stack: ${this.config.terraform.stackName}`);
49
+ if (this.config.terraform.destroy) await (0, execa.execaCommand)([
50
+ this.terraform.command,
51
+ this.terraform.command === "terragrunt" ? this.config.terraform.stackName : void 0,
52
+ "destroy",
53
+ this.config.terraform.autoApproval && "--auto-approve",
54
+ this.config.terraform.varFile && `--var ${this.config.terraform.varFile}`,
55
+ (0, _stryke_type_checks.isSetString)(this.config.terraform.planFile) && this.config.terraform.planFile
56
+ ].filter(Boolean).join(" "), {
57
+ preferLocal: true,
58
+ shell: true,
59
+ stdio: "inherit",
60
+ cwd: this.infrastructurePath,
61
+ env: this.config.mode === "production" ? {
62
+ TF_IN_AUTOMATION: "true",
63
+ TF_INPUT: "0"
64
+ } : {}
65
+ });
66
+ await (0, execa.execaCommand)([
67
+ this.terraform.command,
68
+ this.terraform.command === "terragrunt" ? this.config.terraform.stackName : void 0,
69
+ "apply",
70
+ this.config.terraform.autoApproval && "--auto-approve",
71
+ this.config.terraform.varFile && `--var ${this.config.terraform.varFile}`,
72
+ (0, _stryke_type_checks.isSetString)(this.config.terraform.planFile) && this.config.terraform.planFile
73
+ ].filter(Boolean).join(" "), {
74
+ preferLocal: true,
75
+ shell: true,
76
+ stdio: "inherit",
77
+ cwd: this.infrastructurePath,
78
+ env: this.config.mode === "production" ? {
79
+ TF_IN_AUTOMATION: "true",
80
+ TF_INPUT: "0"
81
+ } : {}
82
+ });
83
+ this.info(`Successfully deployed ${this.config.terraform.stackName}`);
84
+ }
85
+ }];
86
+ };
87
+
88
+ //#endregion
89
+ exports.default = plugin;
90
+ exports.plugin = plugin;
package/dist/index.mjs CHANGED
@@ -1,2 +1,87 @@
1
- import{kebabCase as e}from"@stryke/string-format/kebab-case";import{isSetString as t}from"@stryke/type-checks";import n from"defu";import{execaCommand as r}from"execa";import{getOrganizationName as i,getWorkspaceName as a}from"powerlines/plugin-utils";import{which as o}from"shelljs";const s=(s={})=>[{name:`terraform`,async config(){return{deploy:{terraform:n(s,{autoApproval:!1,planFile:`plan.out`,formatWrite:!1,upgrade:!1,destroy:!1,migrateState:!1,lock:!0,reconfigure:!1})}}},async configResolved(){this.terraform??={};let t=o(`terragrunt`)?`terragrunt`:o(`tofu`)?`tofu`:o(`terraform`)?`terraform`:null;if(!t)throw Error(`Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.`);this.terraform.command=t;let n=e(i(this)),r=e(await a(this)),s=e(this.config.name);this.config.terraform.stackName??=`${n||r||s}-${r&&r!==n&&r!==s?`${r}-`:``}${s}-${this.config.mode}`},async deploy(){this.info(`Creating resources for Terraform stack: ${this.config.terraform.stackName}`),await this.$$internal.callHook(`terraform:deploy`,{sequential:!0}),this.info(`Deploying Terraform stack: ${this.config.terraform.stackName}`),this.config.terraform.destroy&&await r([this.terraform.command,this.terraform.command===`terragrunt`?this.config.terraform.stackName:void 0,`destroy`,this.config.terraform.autoApproval&&`--auto-approve`,this.config.terraform.varFile&&`--var ${this.config.terraform.varFile}`,t(this.config.terraform.planFile)&&this.config.terraform.planFile].filter(Boolean).join(` `),{preferLocal:!0,shell:!0,stdio:`inherit`,cwd:this.infrastructurePath,env:this.config.mode===`production`?{TF_IN_AUTOMATION:`true`,TF_INPUT:`0`}:{}}),await r([this.terraform.command,this.terraform.command===`terragrunt`?this.config.terraform.stackName:void 0,`apply`,this.config.terraform.autoApproval&&`--auto-approve`,this.config.terraform.varFile&&`--var ${this.config.terraform.varFile}`,t(this.config.terraform.planFile)&&this.config.terraform.planFile].filter(Boolean).join(` `),{preferLocal:!0,shell:!0,stdio:`inherit`,cwd:this.infrastructurePath,env:this.config.mode===`production`?{TF_IN_AUTOMATION:`true`,TF_INPUT:`0`}:{}}),this.info(`Successfully deployed ${this.config.terraform.stackName}`)}}];export{s as default,s as plugin};
1
+ import { kebabCase } from "@stryke/string-format/kebab-case";
2
+ import { isSetString } from "@stryke/type-checks";
3
+ import defu from "defu";
4
+ import { execaCommand } from "execa";
5
+ import { getOrganizationName, getWorkspaceName } from "powerlines/plugin-utils";
6
+ import { which } from "shelljs";
7
+
8
+ //#region src/index.ts
9
+ /**
10
+ * A package containing a Powerlines plugin to configure infrastructure and deploy a project using Terraform IaC.
11
+ *
12
+ * @see https://www.terraform.io
13
+ *
14
+ * @param options - The Terraform plugin user configuration options.
15
+ * @returns A Powerlines plugin to configure infrastructure and deploy a project using Terraform.
16
+ */
17
+ const plugin = (options = {}) => {
18
+ return [{
19
+ name: "terraform",
20
+ async config() {
21
+ return { deploy: { terraform: defu(options, {
22
+ autoApproval: false,
23
+ planFile: "plan.out",
24
+ formatWrite: false,
25
+ upgrade: false,
26
+ destroy: false,
27
+ migrateState: false,
28
+ lock: true,
29
+ reconfigure: false
30
+ }) } };
31
+ },
32
+ async configResolved() {
33
+ this.terraform ??= {};
34
+ const command = which("terragrunt") ? "terragrunt" : which("tofu") ? "tofu" : which("terraform") ? "terraform" : null;
35
+ if (!command) throw new Error("Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.");
36
+ this.terraform.command = command;
37
+ const organizationName = kebabCase(getOrganizationName(this));
38
+ const workspaceName = kebabCase(await getWorkspaceName(this));
39
+ const projectName = kebabCase(this.config.name);
40
+ this.config.terraform.stackName ??= `${organizationName || workspaceName || projectName}-${workspaceName && workspaceName !== organizationName && workspaceName !== projectName ? `${workspaceName}-` : ""}${projectName}-${this.config.mode}`;
41
+ },
42
+ async deploy() {
43
+ this.info(`Creating resources for Terraform stack: ${this.config.terraform.stackName}`);
44
+ await this.$$internal.callHook("terraform:deploy", { sequential: true });
45
+ this.info(`Deploying Terraform stack: ${this.config.terraform.stackName}`);
46
+ if (this.config.terraform.destroy) await execaCommand([
47
+ this.terraform.command,
48
+ this.terraform.command === "terragrunt" ? this.config.terraform.stackName : void 0,
49
+ "destroy",
50
+ this.config.terraform.autoApproval && "--auto-approve",
51
+ this.config.terraform.varFile && `--var ${this.config.terraform.varFile}`,
52
+ isSetString(this.config.terraform.planFile) && this.config.terraform.planFile
53
+ ].filter(Boolean).join(" "), {
54
+ preferLocal: true,
55
+ shell: true,
56
+ stdio: "inherit",
57
+ cwd: this.infrastructurePath,
58
+ env: this.config.mode === "production" ? {
59
+ TF_IN_AUTOMATION: "true",
60
+ TF_INPUT: "0"
61
+ } : {}
62
+ });
63
+ await execaCommand([
64
+ this.terraform.command,
65
+ this.terraform.command === "terragrunt" ? this.config.terraform.stackName : void 0,
66
+ "apply",
67
+ this.config.terraform.autoApproval && "--auto-approve",
68
+ this.config.terraform.varFile && `--var ${this.config.terraform.varFile}`,
69
+ isSetString(this.config.terraform.planFile) && this.config.terraform.planFile
70
+ ].filter(Boolean).join(" "), {
71
+ preferLocal: true,
72
+ shell: true,
73
+ stdio: "inherit",
74
+ cwd: this.infrastructurePath,
75
+ env: this.config.mode === "production" ? {
76
+ TF_IN_AUTOMATION: "true",
77
+ TF_INPUT: "0"
78
+ } : {}
79
+ });
80
+ this.info(`Successfully deployed ${this.config.terraform.stackName}`);
81
+ }
82
+ }];
83
+ };
84
+
85
+ //#endregion
86
+ export { plugin as default, plugin };
2
87
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { execaCommand } from \"execa\";\nimport { Plugin, PluginContext } from \"powerlines\";\nimport { getOrganizationName, getWorkspaceName } from \"powerlines/plugin-utils\";\nimport { which } from \"shelljs\";\nimport { TerraformContext } from \"./types\";\nimport { Unstable_TerraformPluginContext } from \"./types/_internal\";\nimport { TerraformPluginContext, TerraformPluginOptions } from \"./types/plugin\";\n\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n terraform?: TerraformPluginOptions;\n }\n\n interface BasePlugin<TContext extends PluginContext> {\n terraform?: {\n /**\n * Run the Terraform deployment to create or update infrastructure resources defined in the Terraform program. This hook is executed after the main build process, allowing you to manage your infrastructure as code using Terraform directly from your Powerlines plugin.\n *\n * @remarks\n * This hook will execute the Terraform program defined in the `config` hook, which should be used to define the infrastructure resources. The Terraform program will be executed sequentially, allowing you to define resources in multiple hooks if needed. The resources defined in the Terraform program will be passed to the next hook invocation, allowing you to manage dependencies between resources defined in different hooks.\n *\n * @param this - The plugin context.\n */\n deploy?: (this: TContext) => MaybePromise<void>;\n };\n }\n}\n\n/**\n * A package containing a Powerlines plugin to configure infrastructure and deploy a project using Terraform IaC.\n *\n * @see https://www.terraform.io\n *\n * @param options - The Terraform plugin user configuration options.\n * @returns A Powerlines plugin to configure infrastructure and deploy a project using Terraform.\n */\nexport const plugin = <\n TContext extends TerraformPluginContext = TerraformPluginContext\n>(\n options: TerraformPluginOptions = {}\n): Plugin<TContext>[] => {\n return [\n {\n name: \"terraform\",\n async config() {\n return {\n deploy: {\n terraform: defu(options, {\n autoApproval: false,\n planFile: \"plan.out\",\n formatWrite: false,\n upgrade: false,\n destroy: false,\n migrateState: false,\n lock: true,\n reconfigure: false\n })\n }\n };\n },\n async configResolved() {\n this.terraform ??= {} as TerraformContext;\n\n const command = which(\"terragrunt\")\n ? \"terragrunt\"\n : which(\"tofu\")\n ? \"tofu\"\n : which(\"terraform\")\n ? \"terraform\"\n : null;\n if (!command) {\n throw new Error(\n \"Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.\"\n );\n }\n\n this.terraform.command = command;\n\n const organizationName = kebabCase(getOrganizationName(this));\n const workspaceName = kebabCase(await getWorkspaceName(this));\n const projectName = kebabCase(this.config.name);\n\n this.config.terraform.stackName ??= `${organizationName || workspaceName || projectName}-${\n workspaceName &&\n workspaceName !== organizationName &&\n workspaceName !== projectName\n ? `${workspaceName}-`\n : \"\"\n }${projectName}-${this.config.mode}`;\n },\n async deploy() {\n this.info(\n `Creating resources for Terraform stack: ${this.config.terraform.stackName}`\n );\n\n await (\n this as unknown as Unstable_TerraformPluginContext\n ).$$internal.callHook(\"terraform:deploy\", {\n sequential: true\n });\n\n this.info(\n `Deploying Terraform stack: ${this.config.terraform.stackName}`\n );\n\n if (this.config.terraform.destroy) {\n await execaCommand(\n [\n this.terraform.command,\n this.terraform.command === \"terragrunt\"\n ? this.config.terraform.stackName\n : undefined,\n \"destroy\",\n this.config.terraform.autoApproval && \"--auto-approve\",\n this.config.terraform.varFile &&\n `--var ${this.config.terraform.varFile}`,\n isSetString(this.config.terraform.planFile) &&\n this.config.terraform.planFile\n ]\n .filter(Boolean)\n .join(\" \"),\n {\n preferLocal: true,\n shell: true,\n stdio: \"inherit\",\n cwd: this.infrastructurePath,\n env:\n this.config.mode === \"production\"\n ? {\n TF_IN_AUTOMATION: \"true\",\n TF_INPUT: \"0\"\n }\n : {}\n }\n );\n }\n\n await execaCommand(\n [\n this.terraform.command,\n this.terraform.command === \"terragrunt\"\n ? this.config.terraform.stackName\n : undefined,\n \"apply\",\n this.config.terraform.autoApproval && \"--auto-approve\",\n this.config.terraform.varFile &&\n `--var ${this.config.terraform.varFile}`,\n isSetString(this.config.terraform.planFile) &&\n this.config.terraform.planFile\n ]\n .filter(Boolean)\n .join(\" \"),\n {\n preferLocal: true,\n shell: true,\n stdio: \"inherit\",\n cwd: this.infrastructurePath,\n env:\n this.config.mode === \"production\"\n ? {\n TF_IN_AUTOMATION: \"true\",\n TF_INPUT: \"0\"\n }\n : {}\n }\n );\n\n this.info(`Successfully deployed ${this.config.terraform.stackName}`);\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":"4RA4DA,MAAa,GAGX,EAAkC,EAAE,GAE7B,CACL,CACE,KAAM,YACN,MAAM,QAAS,CACb,MAAO,CACL,OAAQ,CACN,UAAW,EAAK,EAAS,CACvB,aAAc,GACd,SAAU,WACV,YAAa,GACb,QAAS,GACT,QAAS,GACT,aAAc,GACd,KAAM,GACN,YAAa,GACd,CAAC,CACH,CACF,EAEH,MAAM,gBAAiB,CACrB,KAAK,YAAc,EAAE,CAErB,IAAM,EAAU,EAAM,aAAa,CAC/B,aACA,EAAM,OAAO,CACX,OACA,EAAM,YAAY,CAChB,YACA,KACR,GAAI,CAAC,EACH,MAAU,MACR,6GACD,CAGH,KAAK,UAAU,QAAU,EAEzB,IAAM,EAAmB,EAAU,EAAoB,KAAK,CAAC,CACvD,EAAgB,EAAU,MAAM,EAAiB,KAAK,CAAC,CACvD,EAAc,EAAU,KAAK,OAAO,KAAK,CAE/C,KAAK,OAAO,UAAU,YAAc,GAAG,GAAoB,GAAiB,EAAY,GACtF,GACA,IAAkB,GAClB,IAAkB,EACd,GAAG,EAAc,GACjB,KACH,EAAY,GAAG,KAAK,OAAO,QAEhC,MAAM,QAAS,CACb,KAAK,KACH,2CAA2C,KAAK,OAAO,UAAU,YAClE,CAED,MACE,KACA,WAAW,SAAS,mBAAoB,CACxC,WAAY,GACb,CAAC,CAEF,KAAK,KACH,8BAA8B,KAAK,OAAO,UAAU,YACrD,CAEG,KAAK,OAAO,UAAU,SACxB,MAAM,EACJ,CACE,KAAK,UAAU,QACf,KAAK,UAAU,UAAY,aACvB,KAAK,OAAO,UAAU,UACtB,IAAA,GACJ,UACA,KAAK,OAAO,UAAU,cAAgB,iBACtC,KAAK,OAAO,UAAU,SACpB,SAAS,KAAK,OAAO,UAAU,UACjC,EAAY,KAAK,OAAO,UAAU,SAAS,EACzC,KAAK,OAAO,UAAU,SACzB,CACE,OAAO,QAAQ,CACf,KAAK,IAAI,CACZ,CACE,YAAa,GACb,MAAO,GACP,MAAO,UACP,IAAK,KAAK,mBACV,IACE,KAAK,OAAO,OAAS,aACjB,CACE,iBAAkB,OAClB,SAAU,IACX,CACD,EAAE,CACT,CACF,CAGH,MAAM,EACJ,CACE,KAAK,UAAU,QACf,KAAK,UAAU,UAAY,aACvB,KAAK,OAAO,UAAU,UACtB,IAAA,GACJ,QACA,KAAK,OAAO,UAAU,cAAgB,iBACtC,KAAK,OAAO,UAAU,SACpB,SAAS,KAAK,OAAO,UAAU,UACjC,EAAY,KAAK,OAAO,UAAU,SAAS,EACzC,KAAK,OAAO,UAAU,SACzB,CACE,OAAO,QAAQ,CACf,KAAK,IAAI,CACZ,CACE,YAAa,GACb,MAAO,GACP,MAAO,UACP,IAAK,KAAK,mBACV,IACE,KAAK,OAAO,OAAS,aACjB,CACE,iBAAkB,OAClB,SAAU,IACX,CACD,EAAE,CACT,CACF,CAED,KAAK,KAAK,yBAAyB,KAAK,OAAO,UAAU,YAAY,EAExE,CACF"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* -------------------------------------------------------------------\n\n ⚡ Storm Software - Powerlines\n\n This code was released as part of the Powerlines project. Powerlines\n is maintained by Storm Software under the Apache-2.0 license, and is\n free for commercial and private use. For more information, please visit\n our licensing page at https://stormsoftware.com/licenses/projects/powerlines.\n\n Website: https://stormsoftware.com\n Repository: https://github.com/storm-software/powerlines\n Documentation: https://docs.stormsoftware.com/projects/powerlines\n Contact: https://stormsoftware.com/contact\n\n SPDX-License-Identifier: Apache-2.0\n\n ------------------------------------------------------------------- */\n\nimport { kebabCase } from \"@stryke/string-format/kebab-case\";\nimport { isSetString } from \"@stryke/type-checks\";\nimport { MaybePromise } from \"@stryke/types/base\";\nimport defu from \"defu\";\nimport { execaCommand } from \"execa\";\nimport { Plugin, PluginContext } from \"powerlines\";\nimport { getOrganizationName, getWorkspaceName } from \"powerlines/plugin-utils\";\nimport { which } from \"shelljs\";\nimport { TerraformContext } from \"./types\";\nimport { Unstable_TerraformPluginContext } from \"./types/_internal\";\nimport { TerraformPluginContext, TerraformPluginOptions } from \"./types/plugin\";\n\nexport type * from \"./types\";\n\ndeclare module \"powerlines\" {\n interface Config {\n terraform?: TerraformPluginOptions;\n }\n\n interface BasePlugin<TContext extends PluginContext> {\n terraform?: {\n /**\n * Run the Terraform deployment to create or update infrastructure resources defined in the Terraform program. This hook is executed after the main build process, allowing you to manage your infrastructure as code using Terraform directly from your Powerlines plugin.\n *\n * @remarks\n * This hook will execute the Terraform program defined in the `config` hook, which should be used to define the infrastructure resources. The Terraform program will be executed sequentially, allowing you to define resources in multiple hooks if needed. The resources defined in the Terraform program will be passed to the next hook invocation, allowing you to manage dependencies between resources defined in different hooks.\n *\n * @param this - The plugin context.\n */\n deploy?: (this: TContext) => MaybePromise<void>;\n };\n }\n}\n\n/**\n * A package containing a Powerlines plugin to configure infrastructure and deploy a project using Terraform IaC.\n *\n * @see https://www.terraform.io\n *\n * @param options - The Terraform plugin user configuration options.\n * @returns A Powerlines plugin to configure infrastructure and deploy a project using Terraform.\n */\nexport const plugin = <\n TContext extends TerraformPluginContext = TerraformPluginContext\n>(\n options: TerraformPluginOptions = {}\n): Plugin<TContext>[] => {\n return [\n {\n name: \"terraform\",\n async config() {\n return {\n deploy: {\n terraform: defu(options, {\n autoApproval: false,\n planFile: \"plan.out\",\n formatWrite: false,\n upgrade: false,\n destroy: false,\n migrateState: false,\n lock: true,\n reconfigure: false\n })\n }\n };\n },\n async configResolved() {\n this.terraform ??= {} as TerraformContext;\n\n const command = which(\"terragrunt\")\n ? \"terragrunt\"\n : which(\"tofu\")\n ? \"tofu\"\n : which(\"terraform\")\n ? \"terraform\"\n : null;\n if (!command) {\n throw new Error(\n \"Both OpenTofu and Terraform are not installed. Please install one of the two before running this executor.\"\n );\n }\n\n this.terraform.command = command;\n\n const organizationName = kebabCase(getOrganizationName(this));\n const workspaceName = kebabCase(await getWorkspaceName(this));\n const projectName = kebabCase(this.config.name);\n\n this.config.terraform.stackName ??= `${organizationName || workspaceName || projectName}-${\n workspaceName &&\n workspaceName !== organizationName &&\n workspaceName !== projectName\n ? `${workspaceName}-`\n : \"\"\n }${projectName}-${this.config.mode}`;\n },\n async deploy() {\n this.info(\n `Creating resources for Terraform stack: ${this.config.terraform.stackName}`\n );\n\n await (\n this as unknown as Unstable_TerraformPluginContext\n ).$$internal.callHook(\"terraform:deploy\", {\n sequential: true\n });\n\n this.info(\n `Deploying Terraform stack: ${this.config.terraform.stackName}`\n );\n\n if (this.config.terraform.destroy) {\n await execaCommand(\n [\n this.terraform.command,\n this.terraform.command === \"terragrunt\"\n ? this.config.terraform.stackName\n : undefined,\n \"destroy\",\n this.config.terraform.autoApproval && \"--auto-approve\",\n this.config.terraform.varFile &&\n `--var ${this.config.terraform.varFile}`,\n isSetString(this.config.terraform.planFile) &&\n this.config.terraform.planFile\n ]\n .filter(Boolean)\n .join(\" \"),\n {\n preferLocal: true,\n shell: true,\n stdio: \"inherit\",\n cwd: this.infrastructurePath,\n env:\n this.config.mode === \"production\"\n ? {\n TF_IN_AUTOMATION: \"true\",\n TF_INPUT: \"0\"\n }\n : {}\n }\n );\n }\n\n await execaCommand(\n [\n this.terraform.command,\n this.terraform.command === \"terragrunt\"\n ? this.config.terraform.stackName\n : undefined,\n \"apply\",\n this.config.terraform.autoApproval && \"--auto-approve\",\n this.config.terraform.varFile &&\n `--var ${this.config.terraform.varFile}`,\n isSetString(this.config.terraform.planFile) &&\n this.config.terraform.planFile\n ]\n .filter(Boolean)\n .join(\" \"),\n {\n preferLocal: true,\n shell: true,\n stdio: \"inherit\",\n cwd: this.infrastructurePath,\n env:\n this.config.mode === \"production\"\n ? {\n TF_IN_AUTOMATION: \"true\",\n TF_INPUT: \"0\"\n }\n : {}\n }\n );\n\n this.info(`Successfully deployed ${this.config.terraform.stackName}`);\n }\n }\n ] as Plugin<TContext>[];\n};\n\nexport default plugin;\n"],"mappings":";;;;;;;;;;;;;;;;AA4DA,MAAa,UAGX,UAAkC,EAAE,KACb;AACvB,QAAO,CACL;EACE,MAAM;EACN,MAAM,SAAS;AACb,UAAO,EACL,QAAQ,EACN,WAAW,KAAK,SAAS;IACvB,cAAc;IACd,UAAU;IACV,aAAa;IACb,SAAS;IACT,SAAS;IACT,cAAc;IACd,MAAM;IACN,aAAa;IACd,CAAC,EACH,EACF;;EAEH,MAAM,iBAAiB;AACrB,QAAK,cAAc,EAAE;GAErB,MAAM,UAAU,MAAM,aAAa,GAC/B,eACA,MAAM,OAAO,GACX,SACA,MAAM,YAAY,GAChB,cACA;AACR,OAAI,CAAC,QACH,OAAM,IAAI,MACR,6GACD;AAGH,QAAK,UAAU,UAAU;GAEzB,MAAM,mBAAmB,UAAU,oBAAoB,KAAK,CAAC;GAC7D,MAAM,gBAAgB,UAAU,MAAM,iBAAiB,KAAK,CAAC;GAC7D,MAAM,cAAc,UAAU,KAAK,OAAO,KAAK;AAE/C,QAAK,OAAO,UAAU,cAAc,GAAG,oBAAoB,iBAAiB,YAAY,GACtF,iBACA,kBAAkB,oBAClB,kBAAkB,cACd,GAAG,cAAc,KACjB,KACH,YAAY,GAAG,KAAK,OAAO;;EAEhC,MAAM,SAAS;AACb,QAAK,KACH,2CAA2C,KAAK,OAAO,UAAU,YAClE;AAED,SACE,KACA,WAAW,SAAS,oBAAoB,EACxC,YAAY,MACb,CAAC;AAEF,QAAK,KACH,8BAA8B,KAAK,OAAO,UAAU,YACrD;AAED,OAAI,KAAK,OAAO,UAAU,QACxB,OAAM,aACJ;IACE,KAAK,UAAU;IACf,KAAK,UAAU,YAAY,eACvB,KAAK,OAAO,UAAU,YACtB;IACJ;IACA,KAAK,OAAO,UAAU,gBAAgB;IACtC,KAAK,OAAO,UAAU,WACpB,SAAS,KAAK,OAAO,UAAU;IACjC,YAAY,KAAK,OAAO,UAAU,SAAS,IACzC,KAAK,OAAO,UAAU;IACzB,CACE,OAAO,QAAQ,CACf,KAAK,IAAI,EACZ;IACE,aAAa;IACb,OAAO;IACP,OAAO;IACP,KAAK,KAAK;IACV,KACE,KAAK,OAAO,SAAS,eACjB;KACE,kBAAkB;KAClB,UAAU;KACX,GACD,EAAE;IACT,CACF;AAGH,SAAM,aACJ;IACE,KAAK,UAAU;IACf,KAAK,UAAU,YAAY,eACvB,KAAK,OAAO,UAAU,YACtB;IACJ;IACA,KAAK,OAAO,UAAU,gBAAgB;IACtC,KAAK,OAAO,UAAU,WACpB,SAAS,KAAK,OAAO,UAAU;IACjC,YAAY,KAAK,OAAO,UAAU,SAAS,IACzC,KAAK,OAAO,UAAU;IACzB,CACE,OAAO,QAAQ,CACf,KAAK,IAAI,EACZ;IACE,aAAa;IACb,OAAO;IACP,OAAO;IACP,KAAK,KAAK;IACV,KACE,KAAK,OAAO,SAAS,eACjB;KACE,kBAAkB;KAClB,UAAU;KACX,GACD,EAAE;IACT,CACF;AAED,QAAK,KAAK,yBAAyB,KAAK,OAAO,UAAU,YAAY;;EAExE,CACF"}
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
@@ -1 +1 @@
1
- export{};
1
+ export { };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powerlines/plugin-terraform",
3
- "version": "0.1.56",
3
+ "version": "0.1.58",
4
4
  "private": false,
5
5
  "description": "A Powerlines plugin to deploy infrastructure using Terraform.",
6
6
  "keywords": [
@@ -131,14 +131,14 @@
131
131
  "@stryke/types": "^0.12.0",
132
132
  "defu": "^6.1.7",
133
133
  "execa": "^9.6.1",
134
- "powerlines": "^0.46.3",
134
+ "powerlines": "^0.46.5",
135
135
  "shelljs": "^0.10.0",
136
136
  "typescript": "^6.0.3"
137
137
  },
138
138
  "devDependencies": {
139
- "@powerlines/plugin-plugin": "^0.12.407",
139
+ "@powerlines/plugin-plugin": "^0.12.409",
140
140
  "@types/node": "^25.6.0"
141
141
  },
142
142
  "publishConfig": { "access": "public" },
143
- "gitHead": "9a51041e0817e438c49db05bb757b3bdbaf497ef"
143
+ "gitHead": "9af888c54e58a82744cc334a6b80da52429fa0ac"
144
144
  }