Skip to content

fix(workload-identity): resolve inconsistent conditional result types in output#2582

Open
raman1236 wants to merge 3 commits into
terraform-google-modules:mainfrom
raman1236:fix/workload-identity-output-type-1112
Open

fix(workload-identity): resolve inconsistent conditional result types in output#2582
raman1236 wants to merge 3 commits into
terraform-google-modules:mainfrom
raman1236:fix/workload-identity-output-type-1112

Conversation

@raman1236

Copy link
Copy Markdown

Description

Fixes #1112

When use_existing_gcp_sa is unknown at plan time (e.g., comes from another resource's output), Terraform fails with:

Error: Inconsistent conditional result types

  on .../modules/workload-identity/output.tf line 44, in output "gcp_service_account":
    value = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0] : google_service_account.cluster_service_account[0]

The true and false result expressions must have consistent types.

Root Cause

The data.google_service_account data source and google_service_account resource return objects with slightly different attribute schemas. When Terraform can't determine which branch to evaluate at plan time, it requires both branches to have identical types.

Solution

Replace the conditional expression with one(concat(...)):

# Before
value = var.use_existing_gcp_sa ? data.google_service_account.cluster_service_account[0] : google_service_account.cluster_service_account[0]

# After
value = one(concat(
  data.google_service_account.cluster_service_account,
  google_service_account.cluster_service_account
))

This works because:

  • Only one list will ever have elements (based on the mutually exclusive count conditions)
  • concat() doesn't require type comparison between the list elements
  • one() extracts the single element from the concatenated list

Backward Compatibility

The output value is identical - it still returns the full GCP service account object. Only the implementation changes to avoid the type mismatch error.

@google-cla

google-cla Bot commented Apr 30, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the gcp_service_account output in the workload-identity module to use one(concat(...)) instead of a conditional ternary operator. This change is intended to prevent potential type mismatch issues between the data source and the resource. I have no feedback to provide as there were no review comments.

@raman1236 raman1236 force-pushed the fix/workload-identity-output-type-1112 branch from 7083802 to 26d218b Compare May 16, 2026 21:39
… in output

When use_existing_gcp_sa is unknown at plan time, Terraform fails with
"Inconsistent conditional result types" because the data source and resource
have slightly different object schemas. Replace the ternary with
one(concat(...)) so Terraform never needs to type-check across the two
branches — only one list ever has elements based on their mutually exclusive
count conditions.

Fixes terraform-google-modules#1112
@raman1236 raman1236 force-pushed the fix/workload-identity-output-type-1112 branch from 8d584d5 to 2f8abeb Compare May 20, 2026 03:49
@raman1236

Copy link
Copy Markdown
Author

@apeabody @ayushmjain could one of you run /gcbrun to trigger the integration tests? The fix is ready for review.

@apeabody

Copy link
Copy Markdown
Contributor

/gcbrun

@apeabody

Copy link
Copy Markdown
Contributor

/gcbrun

@raman1236

Copy link
Copy Markdown
Author

@apeabody @ayushmjain could one of you review the PR the fix is ready for review.

@apeabody apeabody left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the contribution @raman1236!

@apeabody

apeabody commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

/gcbrun

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.

Inconsistent conditional result types in kubernetes-engine_workload-identity output

2 participants