Add project data source - #13
Conversation
|
Firetiger deploy monitoring skipped This PR didn't match the auto-monitor filter configured on your GitHub connection:
Reason: PR repository cannot be determined from provided information; please specify which repo (kernel, infra, hypeman, or hypeship) this PR is in, or manually opt in to deploy monitoring. To monitor this PR anyway, reply with |
f315485 to
1087b8a
Compare
7f11cd1 to
87e666f
Compare
1087b8a to
99bdb13
Compare
87e666f to
2b6927d
Compare
99bdb13 to
ea97cc1
Compare
2b6927d to
999e100
Compare
ea97cc1 to
b97905c
Compare
999e100 to
026d2cf
Compare
b97905c to
21c77fa
Compare
026d2cf to
855072b
Compare
21c77fa to
a677bdf
Compare
855072b to
2324adc
Compare
a677bdf to
89d33af
Compare
2324adc to
1732b67
Compare
89d33af to
f4e8bbc
Compare
1732b67 to
ef1bca7
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.
| "Unknown Project Selector", | ||
| "Project id and name must be known before reading the data source.", | ||
| ) | ||
| return projectSelectorProvider, diags |
There was a problem hiding this comment.
Unknown selector blocks known sibling
Medium Severity
resolveProjectSelector rejects the read when either id or name is unknown, even if the other selector is a known non-empty value. A config with a fixed id and an unknown name (or the reverse) fails with “Unknown Project Selector” instead of using the known selector for GetProject or name lookup.
Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.
There was a problem hiding this comment.
Won't fix — intentional. Terraform core defers data-source reads to apply time while config values are unknown, so Read seeing an unknown here is a defensive shouldn't-happen guard, and failing loud is the safe response. Honoring the known sibling would also be wrong: if id is known and name is configured-but-unknown, both selectors are configured, so the config must fail the only-one-of conflict check once name resolves — reading with just id would mask a config that has to be rejected anyway. (This helper is replaced by the shared datasources.ResolveIDNameSelector in #14 with the same semantics.)
| if match == nil { | ||
| matched := project | ||
| match = &matched | ||
| } |
There was a problem hiding this comment.
Ambiguity counts duplicate rows
Low Severity
Name lookup increments count for every list row whose name equals the query string, without deduplicating by project id. If pagination or the API returns the same project more than once, the data source can report an ambiguous name when only one distinct project exists.
Reviewed by Cursor Bugbot for commit ef1bca7. Configure here.
There was a problem hiding this comment.
Fixed (via the stack): the project scan this points at is deleted in #14 (name lookup becomes a single server-resolved GetProject(name), no counting at all). The same hazard in the profile (#14) and proxy (#15) scans is fixed directly: matches are now deduplicated by id before counting, so a row repeated by offset-pagination skew is one match, not a false ambiguity (commits b97c471 / 88fbea9, with TestReadDeduplicatesRepeated{Profile,Proxy}LookupRows).
f4e8bbc to
f2792ef
Compare
ef1bca7 to
c05ef4a
Compare
f2792ef to
e44e04f
Compare
aa9269d to
6dda104
Compare
e44e04f to
6723f0b
Compare
6dda104 to
8e8be50
Compare
09f44a0 to
b741ad9
Compare
8e8be50 to
905f042
Compare
905f042 to
f78a750
Compare
153b98a to
ed777ad
Compare
f78a750 to
b05c00b
Compare
Add the read-only kernel_project data source as the first data-source slice. Keep exact lookup and ambiguity policy in the Terraform data source while kernelclient exposes only a durable paged project-list primitive.
ed777ad to
6f90aab
Compare
b05c00b to
7c0b29f
Compare
tnsardesai
left a comment
There was a problem hiding this comment.
reviewed — solid PR overall. one thing worth a look:
Possible bug
internal/datasources/project/datasource.go:210— name validation runs on every project in the page before theproject.Name != namefilter, so one unrelated project with a malformed/empty name (returned by the fuzzyquery) aborts the whole lookup even when a valid exact match exists. consider validating only after the name matches, or skipping (not erroring on) invalid non-matches.
|
Thanks @tnsardesai — valid finding, and it ended up improving two other data sources. For But the same pattern survived in the profile (#14) and proxy (#15) scans in a narrower form: rows with absent names were already skipped, but a row with a present-yet-inconsistent raw name JSON still aborted the whole lookup even when it wasn't the requested name — worst for Heads: #14 |


What changed
kernel_projectdata source.kernel_projectwith the provider.kernelclient.ListProjectPagewrapper for org-scoped project list pagination.internal/datasources/project.Intentionally unsupported
kernel_profile,kernel_proxy, orkernel_extensiondata sources in this PR.Tests run
GOCACHE=/private/tmp/terraform-provider-kernel-go-cache go test ./internal/datasources/project ./internal/kernelclient ./internal/providerGOCACHE=/private/tmp/terraform-provider-kernel-go-cache go test ./...GOCACHE=/private/tmp/terraform-provider-kernel-go-cache go vet ./...git diff --check browser-pool-import..HEADReview gates
All five review gates passed after fixes:
Note
Low Risk
Read-only Terraform data source and org-scoped list pagination; no resource mutations or auth changes.
Overview
Adds the read-only
kernel_projectdata source so Terraform can look up project metadata by id, exact name, or the provider’s defaultproject_id.Name lookup paginates through org project lists via a new
ListProjectPageclient wrapper that readsX-Next-Offsetand rejects non-advancing pagination. The data source enforces mutual exclusion of id/name, zero/ambiguous exact-name matches, and validates required API fields (via SDK JSON metadata) before writing state.The provider registers
kernel_projectas its first data source; unit tests cover the data source, client pagination, and provider registration.Reviewed by Cursor Bugbot for commit 7c0b29f. Bugbot is set up for automated code reviews on this repo. Configure here.