fix: Consistent multi-tenant platform-destination resolution (+ hint on ambiguity) by disq · Pull Request #22991 · cloudquery/cloudquery · GitHub
Skip to content

fix: Consistent multi-tenant platform-destination resolution (+ hint on ambiguity)#22991

Merged
kodiakhq[bot] merged 2 commits into
mainfrom
claude/cli-detecttenant-multitenant
Jun 25, 2026
Merged

fix: Consistent multi-tenant platform-destination resolution (+ hint on ambiguity)#22991
kodiakhq[bot] merged 2 commits into
mainfrom
claude/cli-detecttenant-multitenant

Conversation

@disq

@disq disq commented Jun 25, 2026

Copy link
Copy Markdown
Member

Two related fixes to how the CLI resolves which platform tenant to act on. Follow-up to #22945.

1. Align DetectTenant with auto-injection

DetectTenant (used by init to tell the user where data lands) took the first of several active tenants, while the actual sync injection skips an ambiguous multi-tenant team with no CQ_PLATFORM_TENANT_ID. So init could point a user at a tenant a real sync would refuse. Both now share one decision (resolveTenant) and treat ambiguity identically.

2. Fail an opt-in sync with a hint on an ambiguous tenant

resolveTenant distinguishes:

  • no active tenant (errNoActiveTenant) → auto-injection skips silently (nothing to do).
  • several active, no matching CQ_PLATFORM_TENANT_ID (errAmbiguousTenant) → user-fixable.

When a source opts into platform (lists it in destinations) but the tenant is ambiguous, MaybeInjectDestination now returns the errAmbiguousTenant-wrapped error carrying an actionable Hint: (e.g. "set CQ_PLATFORM_TENANT_ID to the tenant id you want to sync to") instead of silently dropping the opt-in — sync.go surfaces it and the sync fails with a clear message. Genuine-zero-tenants still skips silently. init's DetectTenant stays informational (any error → report nothing, never fails init).

Tests

  • TestDetectTenant_MultipleActiveTenants — ambiguous → reports nothing; override → matching tenant.
  • TestInject_MultipleTenants_RequiresEnvSelection — unset / mismatched env now assert the errAmbiguousTenant + Hint: error (was: silent skip); valid env still injects.

go build / go vet / go test ./internal/platform/ clean.

DetectTenant took the first of several active tenants, while selectTenant
(used by the actual sync injection) skips an ambiguous multi-tenant team
that has no CQ_PLATFORM_TENANT_ID override. So `init` could report a tenant
a real sync would refuse to inject into.

Extract the shared, pure chooseTenant decision; selectTenant wraps it with
the operator-facing warnings, DetectTenant uses it directly. Both now skip
the ambiguous case identically.
@disq disq requested a review from a team as a code owner June 25, 2026 10:31
@disq disq requested a review from dcelasun June 25, 2026 10:31
@disq disq changed the title fix(cli): Align DetectTenant with auto-injection on multi-tenant teams fix: Align DetectTenant with auto-injection on multi-tenant teams Jun 25, 2026
resolveTenant now distinguishes 'no active tenant' (errNoActiveTenant —
auto-injection skips silently, nothing to do) from 'several active, no
CQ_PLATFORM_TENANT_ID match' (errAmbiguousTenant). When a source opts into
`platform` but the tenant is ambiguous, MaybeInjectDestination returns the
errAmbiguousTenant-wrapped error carrying an actionable Hint instead of
silently dropping the opt-in; the sync fails with a clear message. init's
DetectTenant stays informational (any error → report nothing).
@disq disq changed the title fix: Align DetectTenant with auto-injection on multi-tenant teams fix(cli): Consistent multi-tenant platform-destination resolution (+ hint on ambiguity) Jun 25, 2026
@disq disq changed the title fix(cli): Consistent multi-tenant platform-destination resolution (+ hint on ambiguity) fix: Consistent multi-tenant platform-destination resolution (+ hint on ambiguity) Jun 25, 2026
@disq disq added the automerge Automatically merge once required checks pass label Jun 25, 2026
@kodiakhq kodiakhq Bot merged commit 9157b03 into main Jun 25, 2026
18 of 19 checks passed
@kodiakhq kodiakhq Bot deleted the claude/cli-detecttenant-multitenant branch June 25, 2026 10:56
kodiakhq Bot pushed a commit that referenced this pull request Jun 25, 2026
🤖 I have created a release *beep* *boop*
---


## [6.37.0](cli-v6.36.1...cli-v6.37.0) (2026-06-25)


### Features

* Sync directly to CloudQuery Platform from the CLI ([#22945](#22945)) ([c3cefb4](c3cefb4))


### Bug Fixes

* Consistent multi-tenant platform-destination resolution (+ hint on ambiguity) ([#22991](#22991)) ([9157b03](9157b03))
* **deps:** Update go module directive to v1.26.3 ([#22869](#22869)) ([ce8d270](ce8d270))
* **deps:** Update module github.com/cloudquery/cloudquery-api-go to v1.14.10 ([#22942](#22942)) ([24ebdf1](24ebdf1))
* **deps:** Update module github.com/cloudquery/cloudquery-api-go to v1.14.11 ([#22989](#22989)) ([251a571](251a571))
* **deps:** Update module github.com/cloudquery/cloudquery-api-go to v1.14.12 ([#22990](#22990)) ([a0e78dd](a0e78dd))
* **deps:** Update module github.com/cloudquery/plugin-sdk/v4 to v4.95.3 ([#22946](#22946)) ([b9aac1f](b9aac1f))

---
This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/cli automerge Automatically merge once required checks pass

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants