{{ message }}
fix: Consistent multi-tenant platform-destination resolution (+ hint on ambiguity)#22991
Merged
Merged
Conversation
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.
erezrokah
approved these changes
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).
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Two related fixes to how the CLI resolves which platform tenant to act on. Follow-up to #22945.
1. Align
DetectTenantwith auto-injectionDetectTenant(used byinitto 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 noCQ_PLATFORM_TENANT_ID. Soinitcould 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
resolveTenantdistinguishes:errNoActiveTenant) → auto-injection skips silently (nothing to do).CQ_PLATFORM_TENANT_ID(errAmbiguousTenant) → user-fixable.When a source opts into
platform(lists it indestinations) but the tenant is ambiguous,MaybeInjectDestinationnow returns theerrAmbiguousTenant-wrapped error carrying an actionableHint:(e.g. "setCQ_PLATFORM_TENANT_IDto the tenant id you want to sync to") instead of silently dropping the opt-in —sync.gosurfaces it and the sync fails with a clear message. Genuine-zero-tenants still skips silently.init'sDetectTenantstays informational (any error → report nothing, never failsinit).Tests
TestDetectTenant_MultipleActiveTenants— ambiguous → reports nothing; override → matching tenant.TestInject_MultipleTenants_RequiresEnvSelection— unset / mismatched env now assert theerrAmbiguousTenant+Hint:error (was: silent skip); valid env still injects.go build/go vet/go test ./internal/platform/clean.