Skip to content

Commit

Permalink
fix: add setup-terraform step in CI as Terraform is not installed by …
Browse files Browse the repository at this point in the history
…default anymore on ubuntu-latest (#179)
  • Loading branch information
ansgarm authored Jan 6, 2025
1 parent 4b9acc3 commit 8f2020a
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .projenrc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import { JsiiProject } from "projen/lib/cdk";
import { JobStep } from "projen/lib/github/workflows-model";
import { NpmAccess, UpgradeDependenciesSchedule } from "projen/lib/javascript";
import { AutoApprove } from "./projenrc/auto-approve";
import { Automerge } from "./projenrc/automerge";
Expand All @@ -21,6 +22,7 @@ const githubActionPinnedVersions = {
"amannn/action-semantic-pull-request":
"0723387faaf9b38adef4775cd42cfd5155ed6017", // v5.5.3
"hashicorp/setup-copywrite": "32638da2d4e81d56a0764aa1547882fc4d209636", // v1.1.3
"hashicorp/setup-terraform": "b9cd54a3c349d3f38e8881555d616ced269862dd", // v3.1.2
"peter-evans/create-pull-request": "c5a7806660adbe173f04e3e038b0ccdcd758773c", // v6.1.0
};

Expand Down Expand Up @@ -123,6 +125,15 @@ project.buildWorkflow?.addPostBuildSteps(
{ name: "Add headers using Copywrite tool", run: "copywrite headers" }
);

const buildSteps = (project.buildWorkflow as any).preBuildSteps as JobStep[];
buildSteps.push({
name: "Setup Terraform",
uses: "hashicorp/setup-terraform",
with: {
terraform_wrapper: false,
},
});

// Use pinned versions of github actions
Object.entries(githubActionPinnedVersions).forEach(([action, sha]) => {
project.github?.actions.set(action, `${action}@${sha}`);
Expand Down
4 changes: 4 additions & 0 deletions examples/hybrid-module/.github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions examples/terraform-module/.github/workflows/build.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/hybrid-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import * as path from "path";
import { FileBase, IResolver, Project, SampleDir } from "projen";
import { JsiiProject, ConstructLibraryOptions } from "projen/lib/cdk";
import { JobStep } from "projen/lib/github/workflows-model";
import { defaults } from "./defaults";

export interface ConstructExamplesOption {
Expand Down Expand Up @@ -374,6 +375,15 @@ app.synth();
this.gitignore.addPatterns(`${constructExampleFolder}/cdktf.out`);
}

const buildSteps = (this.buildWorkflow as any).preBuildSteps as JobStep[];
buildSteps.push({
name: "Setup Terraform",
uses: "hashicorp/setup-terraform",
with: {
terraform_wrapper: false,
},
});

this.gitignore.addPatterns("src/.gen", "src/cdktf.out", "src/modules");
this.compileTask.prependExec("npx cdktf get", {
cwd: this.srcdir,
Expand Down
10 changes: 10 additions & 0 deletions src/terraform-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { JsonFile, SampleDir, TextFile } from "projen";
import { ConstructLibrary, ConstructLibraryOptions } from "projen/lib/cdk";
import { JobStep } from "projen/lib/github/workflows-model";

import { defaults } from "./defaults";

Expand Down Expand Up @@ -126,5 +127,14 @@ describe("MyModule", () => {
});

this.preCompileTask.exec(`npx cdktf get`, { cwd: this.srcdir });

const buildSteps = (this.buildWorkflow as any).preBuildSteps as JobStep[];
buildSteps.push({
name: "Setup Terraform",
uses: "hashicorp/setup-terraform",
with: {
terraform_wrapper: false,
},
});
}
}
4 changes: 4 additions & 0 deletions test/__snapshots__/hybrid-module.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions test/__snapshots__/terraform-module.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8f2020a

Please sign in to comment.