Skip to content

fix(runners): fix type mismatch in pool role conditional - #5156

Merged
Brend-Smits merged 2 commits into
mainfrom
fix/pool-role-type-mismatch
Jun 11, 2026
Merged

Brend-Smits merged 2 commits into
mainfrom
fix/pool-role-type-mismatch

Conversation

@Brend-Smits

Copy link
Copy Markdown
Contributor

Problem

The conditional for the runner role in modules/runners/pool.tf (introduced in #4875) returns inconsistent types:

role = var.iam_overrides["override_runner_role"] ? { arn = var.iam_overrides["runner_role_arn"] } : aws_iam_role.runner[0]
  • True branch: { arn = "..." } (1 attribute)
  • False branch: aws_iam_role.runner[0] (16 attributes including assume_role_policy, name, etc.)

Terraform requires both branches of a conditional to have consistent types. This causes a type error at plan time when override_runner_role = false (the default).

Fix

Move the conditional inside the object so both branches produce a string:

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

This is consistent with how scale-up.tf (line 123) already handles the same conditional.

Testing

  • Verified terraform plan succeeds with override_runner_role = false (default)
  • The pool module's variable type is object({ arn = string }), so only the .arn attribute is needed

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 a review from a team as a code owner June 11, 2026 12:15
@github-actions

Copy link
Copy Markdown
Contributor

Dependency Review

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

Scanned Files

None

Brend-Smits added a commit to philips-forks/terraform-aws-github-runner that referenced this pull request Jun 11, 2026
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 github-aws-runners#4875.

Upstream-PR: github-aws-runners#5156
@Brend-Smits
Brend-Smits merged commit 60de50f into main Jun 11, 2026
42 checks passed
@Brend-Smits
Brend-Smits deleted the fix/pool-role-type-mismatch branch June 11, 2026 13:07
edersonbrilhante pushed a commit that referenced this pull request Jun 11, 2026
🤖 I have created a release *beep* *boop*
---


##
[7.7.1](v7.7.0...v7.7.1)
(2026-06-11)


### Bug Fixes

* **runners:** fix type mismatch in pool role conditional
([#5156](#5156))
([60de50f](60de50f))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: runners-releaser[bot] <194412594+runners-releaser[bot]@users.noreply.github.com>
edersonbrilhante added a commit that referenced this pull request Jul 3, 2026
## Problem

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

```hcl
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.

---------

Signed-off-by: Brend Smits <[email protected]>
Co-authored-by: Niek Palm <[email protected]>
Co-authored-by: Ederson Brilhante <[email protected]>
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.

2 participants