@causa/workspace-terraform 0.2.0 → 0.3.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.
package/README.md CHANGED
@@ -33,3 +33,4 @@ The Terraform module also supports some of the project-level commands, namely:
33
33
 
34
34
  - `cs init`: Runs `terraform init`.
35
35
  - `cs lint`: Runs `terraform validate` and `terraform fmt`. The format operation is run with the `-check` argument, such that it only lints the code without fixing it. This operation applies supports the `project.additionalDirectories` configuration.
36
+ - `cs dependencies update`: Runs `terraform init` with the `-upgrade` option, allowing the update of dependencies and the lock file.
@@ -1,7 +1,8 @@
1
1
  import { InfrastructureDeployForTerraform } from './infrastructure-deploy-terraform.js';
2
2
  import { InfrastructurePrepareForTerraform } from './infrastructure-prepare-terraform.js';
3
+ import { ProjectDependenciesUpdateForTerraform } from './project-dependencies-update-terraform.js';
3
4
  import { ProjectInitForTerraform } from './project-init-terraform.js';
4
5
  import { ProjectLintForTerraform } from './project-lint-terraform.js';
5
6
  export function registerFunctions(context) {
6
- context.registerFunctionImplementations(InfrastructureDeployForTerraform, InfrastructurePrepareForTerraform, ProjectInitForTerraform, ProjectLintForTerraform);
7
+ context.registerFunctionImplementations(InfrastructureDeployForTerraform, InfrastructurePrepareForTerraform, ProjectDependenciesUpdateForTerraform, ProjectInitForTerraform, ProjectLintForTerraform);
7
8
  }
@@ -18,7 +18,7 @@ export class InfrastructurePrepareForTerraform extends InfrastructurePrepare {
18
18
  const variables = (await infrastructureConf.getAndRender('infrastructure.variables')) ?? {};
19
19
  const output = resolve(this.output ?? DEFAULT_PLAN_FILE);
20
20
  context.logger.info(`🧱 Planning Terraform deployment for project '${projectName}'.`);
21
- const isDeploymentNeeded = await terraformService.wrapWorkspaceOperation({ createWorkspaceIfNeeded: true }, () => terraformService.plan(output, { variables }));
21
+ const isDeploymentNeeded = await terraformService.wrapWorkspaceOperation({ createWorkspaceIfNeeded: !this.destroy }, () => terraformService.plan(output, { variables, destroy: this.destroy }));
22
22
  if (isDeploymentNeeded) {
23
23
  context.logger.info('🧱 Terraform plan has changes that can be deployed.');
24
24
  if (this.print) {
@@ -0,0 +1,11 @@
1
+ import { WorkspaceContext } from '@causa/workspace';
2
+ import { ProjectDependenciesUpdate } from '@causa/workspace-core';
3
+ /**
4
+ * Implements the {@link ProjectDependenciesUpdate} function for Terraform projects, by running `terraform init`.
5
+ * This uses the `-upgrade` option to fetch the latest versions of the providers allowed by configured constraints, and
6
+ * updates the lock file accordingly.
7
+ */
8
+ export declare class ProjectDependenciesUpdateForTerraform extends ProjectDependenciesUpdate {
9
+ _call(context: WorkspaceContext): Promise<void>;
10
+ _supports(context: WorkspaceContext): boolean;
11
+ }
@@ -0,0 +1,20 @@
1
+ import { ProjectDependenciesUpdate } from '@causa/workspace-core';
2
+ import { TerraformService } from '../services/index.js';
3
+ /**
4
+ * Implements the {@link ProjectDependenciesUpdate} function for Terraform projects, by running `terraform init`.
5
+ * This uses the `-upgrade` option to fetch the latest versions of the providers allowed by configured constraints, and
6
+ * updates the lock file accordingly.
7
+ */
8
+ export class ProjectDependenciesUpdateForTerraform extends ProjectDependenciesUpdate {
9
+ async _call(context) {
10
+ context.logger.info('⬆️ Updating Terraform dependencies.');
11
+ await context
12
+ .service(TerraformService)
13
+ .init({ upgrade: true, logging: 'debug' });
14
+ context.logger.info(`️✅ Successfully updated Terraform dependencies.`);
15
+ }
16
+ _supports(context) {
17
+ return (context.get('project.language') === 'terraform' &&
18
+ context.get('project.type') === 'infrastructure');
19
+ }
20
+ }
@@ -26,6 +26,7 @@ export class ProjectLintForTerraform extends ProjectLint {
26
26
  targets,
27
27
  logging: 'info',
28
28
  });
29
+ context.logger.info('✅ Terraform code passed linting.');
29
30
  }
30
31
  catch (error) {
31
32
  if (error instanceof ProcessServiceExitCodeError) {
@@ -50,7 +50,12 @@ export declare class TerraformService {
50
50
  *
51
51
  * @param options Options when initializing Terraform.
52
52
  */
53
- init(options?: SpawnOptions): Promise<void>;
53
+ init(options?: {
54
+ /**
55
+ * Upgrades the module and provider versions during initialization, instead of using the lockfile.
56
+ */
57
+ upgrade?: boolean;
58
+ } & SpawnOptions): Promise<void>;
54
59
  /**
55
60
  * Runs `terraform workspace show` and returns the currently selected workspace.
56
61
  *
@@ -65,6 +70,9 @@ export declare class TerraformService {
65
70
  * @param options Options when running the command.
66
71
  */
67
72
  workspaceSelect(workspace: string, options?: {
73
+ /**
74
+ * Creates the workspace if it does not already exists.
75
+ */
68
76
  orCreate?: boolean;
69
77
  } & SpawnOptions): Promise<void>;
70
78
  /**
@@ -44,7 +44,11 @@ export class TerraformService {
44
44
  * @param options Options when initializing Terraform.
45
45
  */
46
46
  async init(options = {}) {
47
- await this.terraform('init', ['-input=false'], options);
47
+ const args = ['-input=false'];
48
+ if (options.upgrade) {
49
+ args.push('-upgrade');
50
+ }
51
+ await this.terraform('init', args, options);
48
52
  }
49
53
  /**
50
54
  * Runs `terraform workspace show` and returns the currently selected workspace.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@causa/workspace-terraform",
3
- "version": "0.2.0",
3
+ "version": "0.3.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",
@@ -28,24 +28,24 @@
28
28
  "test:cov": "npm run test -- --coverage"
29
29
  },
30
30
  "dependencies": {
31
- "@causa/workspace": ">= 0.10.0 < 1.0.0",
32
- "@causa/workspace-core": ">= 0.7.0 < 1.0.0",
33
- "pino": "^8.14.1",
34
- "semver": "^7.5.1"
31
+ "@causa/workspace": ">= 0.12.0 < 1.0.0",
32
+ "@causa/workspace-core": ">= 0.11.0 < 1.0.0",
33
+ "pino": "^8.14.2",
34
+ "semver": "^7.5.4"
35
35
  },
36
36
  "devDependencies": {
37
- "@tsconfig/node18": "^2.0.1",
38
- "@types/jest": "^29.5.2",
39
- "@types/node": "^18.16.14",
40
- "@typescript-eslint/eslint-plugin": "^5.59.9",
41
- "eslint": "^8.42.0",
42
- "eslint-config-prettier": "^8.8.0",
43
- "eslint-plugin-prettier": "^4.2.1",
44
- "jest": "^29.5.0",
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",
43
+ "eslint-plugin-prettier": "^5.0.0",
44
+ "jest": "^29.6.2",
45
45
  "jest-extended": "^4.0.0",
46
46
  "rimraf": "^5.0.1",
47
- "ts-jest": "^29.1.0",
47
+ "ts-jest": "^29.1.1",
48
48
  "ts-node": "^10.9.1",
49
- "typescript": "^5.1.3"
49
+ "typescript": "^5.1.6"
50
50
  }
51
51
  }