Skip to content

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

Open
raman1236 wants to merge 1 commit 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 1 commit 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.

… in output

Fixes terraform-google-modules#1112

When use_existing_gcp_sa is unknown at plan time, Terraform fails with
'Inconsistent conditional result types' because data.google_service_account
and google_service_account.cluster_service_account have different object types.

The fix uses one(concat(...)) instead of a conditional expression:
- Only one list will ever have elements (based on count conditions)
- concat() avoids type comparison between the two different resource types
- one() extracts the single element from the concatenated list

This approach is type-safe and works regardless of when use_existing_gcp_sa
is known.
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Apr 30, 2026

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.

Copy link
Copy Markdown
Contributor

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

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.

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