Skip to content

fix: ensure Terraform is available for integration tests #390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,23 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: coder/coder/.github/actions/setup-tf@main
- uses: oven-sh/setup-bun@v2
- name: Check out code
uses: actions/checkout@v4
- name: Set up Terraform
uses: coder/coder/.github/actions/setup-tf@main
- name: Set up Bun
uses: oven-sh/setup-bun@v2
with:
# We're using the latest version of Bun for now, but it might be worth
# reconsidering. They've pushed breaking changes in patch releases
# that have broken our CI.
# Our PR where issues started to pop up: https://github.com/coder/modules/pull/383
# The Bun PR that broke things: https://github.com/oven-sh/bun/pull/16067
Comment on lines +26 to +30
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to get this added to the file so that there's a paper trail in case Bun's changes suddenly cause CI to break again

bun-version: latest
- name: Setup
- name: Install dependencies
run: bun install
- run: bun test
- name: Run tests
run: bun test
pretty:
runs-on: ubuntu-latest
steps:
Expand Down
2 changes: 1 addition & 1 deletion setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const removeOldContainers = async () => {
"-a",
"-q",
"--filter",
`label=modules-test`,
"label=modules-test",
]);
let containerIDsRaw = await readableStreamToText(proc.stdout);
let exitCode = await proc.exited;
Expand Down
15 changes: 10 additions & 5 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,18 @@ export const testRequiredVariables = <TVars extends TerraformVariables>(
export const runTerraformApply = async <TVars extends TerraformVariables>(
dir: string,
vars: Readonly<TVars>,
env?: Record<string, string>,
customEnv?: Record<string, string>,
): Promise<TerraformState> => {
const stateFile = `${dir}/${crypto.randomUUID()}.tfstate`;

const combinedEnv = env === undefined ? {} : { ...env };
for (const [key, value] of Object.entries(vars)) {
combinedEnv[`TF_VAR_${key}`] = String(value);
const childEnv: Record<string, string | undefined> = {
...process.env,
...(customEnv ?? {}),
};
for (const [key, value] of Object.entries(vars) as [string, JsonValue][]) {
if (value !== null) {
childEnv[`TF_VAR_${key}`] = String(value);
}
}

const proc = spawn(
Expand All @@ -216,7 +221,7 @@ export const runTerraformApply = async <TVars extends TerraformVariables>(
],
{
cwd: dir,
env: combinedEnv,
env: childEnv,
stderr: "pipe",
stdout: "pipe",
},
Expand Down
Loading