Skip to content

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

Merged
edersonbrilhante merged 6 commits into
mainfrom
ci/add-terraform-test
Jul 3, 2026
Merged

edersonbrilhante merged 6 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 <[email protected]>
@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.

OpenSSF Scorecard

PackageVersionScoreDetails
actions/actions/checkout df4cb1c069e1874edd31b4311f1884172cec0e10 🟢 6.9
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Maintained🟢 1016 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Binary-Artifacts🟢 10no binaries found in the repo
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies🟢 3dependency not pinned by hash detected -- score normalized to 3
Signed-Releases⚠️ -1no releases found
Security-Policy🟢 9security policy file detected
Branch-Protection🟢 5branch protection is not maximal on development and all release branches
SAST🟢 10SAST tool is run on all commits
actions/step-security/harden-runner f808768d1510423e83855289c910610ca9b43176 🟢 7.9
Details
CheckScoreReason
Binary-Artifacts🟢 10no binaries found in the repo
Branch-Protection🟢 8branch protection is not maximal on development and all release branches
CI-Tests🟢 1016 out of 16 merged PRs checked by a CI test -- score normalized to 10
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Code-Review🟢 10all changesets reviewed
Contributors🟢 6project has 2 contributing companies or organizations -- score normalized to 6
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Dependency-Update-Tool🟢 10update tool detected
Fuzzing⚠️ 0project is not fuzzed
License🟢 10license file detected
Maintained🟢 1014 commit(s) and 4 issue activity found in the last 90 days -- score normalized to 10
Packaging⚠️ -1packaging workflow not detected
Pinned-Dependencies🟢 6dependency not pinned by hash detected -- score normalized to 6
SAST🟢 10SAST tool is run on all commits
Security-Policy🟢 10security policy file detected
Signed-Releases⚠️ -1no releases found
Token-Permissions🟢 10GitHub workflow tokens follow principle of least privilege
Vulnerabilities⚠️ 016 existing vulnerabilities detected

Scanned Files

  • .github/workflows/terraform.yml

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 <[email protected]>
- 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 <[email protected]>
@Brend-Smits
Brend-Smits force-pushed the ci/add-terraform-test branch from 5f2cf57 to 7df0fb9 Compare June 11, 2026 13:05
@edersonbrilhante
edersonbrilhante merged commit db92e55 into main Jul 3, 2026
47 checks passed
@edersonbrilhante
edersonbrilhante deleted the ci/add-terraform-test branch July 3, 2026 14:19
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.

4 participants