Skip to content

ci(runners): add terraform test for pool module type safety#5157

Open
Brend-Smits wants to merge 5 commits into
mainfrom
ci/add-terraform-test
Open

ci(runners): add terraform test for pool module type safety#5157
Brend-Smits wants to merge 5 commits into
mainfrom
ci/add-terraform-test

Conversation

@Brend-Smits

Copy link
Copy Markdown
Contributor

Problem

terraform validate cannot detect conditional type mismatches like the one introduced in #4875:

role = var.iam_overrides["override_runner_role"] ? { arn = var.iam_overrides["runner_role_arn"] } : aws_iam_role.runner[0]

This passes terraform validate but fails at plan time because the two branches produce objects with different attributes (1 vs 16).

Solution

Add a terraform test file (modules/runners/tests/pool.tftest.hcl) that uses mock providers to run a full plan of the runners module with pool enabled. This catches type errors that validate misses, without requiring AWS credentials.

Also adds a terraform_test job to the existing CI workflow. The job uses Terraform latest (requires 1.7+ for mock_provider / mock_data support) and runs terraform test on modules that have test files.

Verified locally

With the buggy code (before #5156):

Error: Inconsistent conditional result types
  on pool.tf line 54, in module "pool":
  The true and false result expressions must have consistent types.

With the fix (#5156 applied):

Success! 1 passed, 0 failed.

Future work

The terraform_test job matrix can be expanded as more modules add .tftest.hcl files. This is a starting point to catch the class of bugs that validate cannot.

The conditional for the runner role in pool.tf returned inconsistent types:
the true branch produced an object with a single 'arn' attribute while the
false branch returned the full aws_iam_role resource (16 attributes).

Terraform requires both branches to have consistent types. Move the
conditional inside the object so both branches produce a string for the
'arn' key.

Fixes type error introduced in #4875.

Signed-off-by: Brend Smits <brend.smits@philips.com>
@Brend-Smits Brend-Smits requested review from a team as code owners June 11, 2026 12:29
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment thread .github/workflows/terraform.yml Fixed
@Brend-Smits Brend-Smits force-pushed the ci/add-terraform-test branch from 250ab7c to 8cb1fef Compare June 11, 2026 12:34
Comment thread .github/workflows/terraform.yml Fixed
@Brend-Smits Brend-Smits force-pushed the ci/add-terraform-test branch from 8cb1fef to 5f2cf57 Compare June 11, 2026 12:48
Add a terraform test that exercises the pool module code path with mock
providers. This catches conditional type mismatches (like the one in #4875)
that terraform validate cannot detect.

The test uses mock_provider with mock_data to avoid needing AWS credentials
while still running a full plan that validates type consistency.

Also adds a terraform_test job to the existing CI workflow that runs
`terraform test` on modules with test files.

Signed-off-by: Brend Smits <brend.smits@philips.com>
- Add README.md explaining how to write and run terraform tests
- Pin CI container to hashicorp/terraform:1.12 (mock_provider needs >= 1.7)

Signed-off-by: Brend Smits <brend.smits@philips.com>
@Brend-Smits Brend-Smits force-pushed the ci/add-terraform-test branch from 5f2cf57 to 7df0fb9 Compare June 11, 2026 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants