@causa/workspace-terraform 0.3.0 → 0.4.0

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,4 +1,5 @@
1
1
  import { InfrastructureDeploy } from '@causa/workspace-core';
2
+ import { rm } from 'fs/promises';
2
3
  import { resolve } from 'path';
3
4
  import { TerraformService } from '../services/index.js';
4
5
  /**
@@ -14,6 +15,7 @@ export class InfrastructureDeployForTerraform extends InfrastructureDeploy {
14
15
  const plan = resolve(this.deployment);
15
16
  await terraformService.wrapWorkspaceOperation(() => terraformService.apply(plan, { logging: 'info' }));
16
17
  context.logger.info('🧱 Successfully applied Terraform plan.');
18
+ await rm(plan);
17
19
  }
18
20
  _supports(context) {
19
21
  return (context.get('project.language') === 'terraform' &&
@@ -1,13 +1,10 @@
1
1
  import { WorkspaceContext } from '@causa/workspace';
2
- import { InfrastructurePrepare } from '@causa/workspace-core';
2
+ import { InfrastructurePrepare, PrepareResult } from '@causa/workspace-core';
3
3
  /**
4
4
  * Implements the {@link InfrastructurePrepare} function for Infrastructure as Code defined using Terraform.
5
5
  * This calls the `terraform plan` command for the given project.
6
6
  */
7
7
  export declare class InfrastructurePrepareForTerraform extends InfrastructurePrepare {
8
- _call(context: WorkspaceContext): Promise<{
9
- output: string;
10
- isDeploymentNeeded: boolean;
11
- }>;
8
+ _call(context: WorkspaceContext): Promise<PrepareResult>;
12
9
  _supports(context: WorkspaceContext): boolean;
13
10
  }
@@ -1,4 +1,5 @@
1
1
  import { InfrastructurePrepare, } from '@causa/workspace-core';
2
+ import { rm } from 'fs/promises';
2
3
  import { resolve } from 'path';
3
4
  import { TerraformService } from '../services/index.js';
4
5
  /**
@@ -11,12 +12,14 @@ const DEFAULT_PLAN_FILE = 'plan.out';
11
12
  */
12
13
  export class InfrastructurePrepareForTerraform extends InfrastructurePrepare {
13
14
  async _call(context) {
14
- context.getProjectPathOrThrow();
15
+ const projectPath = context.getProjectPathOrThrow();
15
16
  const infrastructureConf = context.asConfiguration();
16
17
  const projectName = infrastructureConf.getOrThrow('project.name');
17
18
  const terraformService = context.service(TerraformService);
18
19
  const variables = (await infrastructureConf.getAndRender('infrastructure.variables')) ?? {};
19
- const output = resolve(this.output ?? DEFAULT_PLAN_FILE);
20
+ const output = this.output
21
+ ? resolve(this.output)
22
+ : resolve(projectPath, DEFAULT_PLAN_FILE);
20
23
  context.logger.info(`🧱 Planning Terraform deployment for project '${projectName}'.`);
21
24
  const isDeploymentNeeded = await terraformService.wrapWorkspaceOperation({ createWorkspaceIfNeeded: !this.destroy }, () => terraformService.plan(output, { variables, destroy: this.destroy }));
22
25
  if (isDeploymentNeeded) {
@@ -25,11 +28,11 @@ export class InfrastructurePrepareForTerraform extends InfrastructurePrepare {
25
28
  const show = await terraformService.show(output);
26
29
  console.log(show);
27
30
  }
31
+ return { output, isDeploymentNeeded };
28
32
  }
29
- else {
30
- context.logger.info('🧱 Terraform plan has no change.');
31
- }
32
- return { output, isDeploymentNeeded };
33
+ context.logger.info('🧱 Terraform plan has no change.');
34
+ await rm(output);
35
+ return { output: '', isDeploymentNeeded };
33
36
  }
34
37
  _supports(context) {
35
38
  return (context.get('project.language') === 'terraform' &&
@@ -6,6 +6,6 @@ import { ProjectDependenciesUpdate } from '@causa/workspace-core';
6
6
  * updates the lock file accordingly.
7
7
  */
8
8
  export declare class ProjectDependenciesUpdateForTerraform extends ProjectDependenciesUpdate {
9
- _call(context: WorkspaceContext): Promise<void>;
9
+ _call(context: WorkspaceContext): Promise<boolean>;
10
10
  _supports(context: WorkspaceContext): boolean;
11
11
  }
@@ -12,6 +12,7 @@ export class ProjectDependenciesUpdateForTerraform extends ProjectDependenciesUp
12
12
  .service(TerraformService)
13
13
  .init({ upgrade: true, logging: 'debug' });
14
14
  context.logger.info(`️✅ Successfully updated Terraform dependencies.`);
15
+ return true;
15
16
  }
16
17
  _supports(context) {
17
18
  return (context.get('project.language') === 'terraform' &&
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/workspace-terraform",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "The Causa workspace module providing functionalities for infrastructure projects coded in Terraform.",
5
5
  "repository": "github:causa-io/workspace-module-terraform",
6
6
  "license": "ISC",
@@ -29,23 +29,23 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "@causa/workspace": ">= 0.12.0 < 1.0.0",
32
- "@causa/workspace-core": ">= 0.11.0 < 1.0.0",
33
- "pino": "^8.14.2",
32
+ "@causa/workspace-core": ">= 0.18.0 < 1.0.0",
33
+ "pino": "^8.15.6",
34
34
  "semver": "^7.5.4"
35
35
  },
36
36
  "devDependencies": {
37
- "@tsconfig/node18": "^18.2.0",
38
- "@types/jest": "^29.5.3",
39
- "@types/node": "^18.17.1",
40
- "@typescript-eslint/eslint-plugin": "^6.2.0",
41
- "eslint": "^8.46.0",
42
- "eslint-config-prettier": "^8.9.0",
37
+ "@tsconfig/node18": "^18.2.2",
38
+ "@types/jest": "^29.5.5",
39
+ "@types/node": "^18.18.3",
40
+ "@typescript-eslint/eslint-plugin": "^6.7.4",
41
+ "eslint": "^8.50.0",
42
+ "eslint-config-prettier": "^9.0.0",
43
43
  "eslint-plugin-prettier": "^5.0.0",
44
- "jest": "^29.6.2",
45
- "jest-extended": "^4.0.0",
46
- "rimraf": "^5.0.1",
44
+ "jest": "^29.7.0",
45
+ "jest-extended": "^4.0.1",
46
+ "rimraf": "^5.0.5",
47
47
  "ts-jest": "^29.1.1",
48
48
  "ts-node": "^10.9.1",
49
- "typescript": "^5.1.6"
49
+ "typescript": "^5.2.2"
50
50
  }
51
51
  }