Repository navigation
Commit c7ddd56
cli/cloud: add
## Summary
Adds `pulumi insights resource search`, the second leaf command under
the [Cloud-Ready CLI](#22959)
epic for `pulumi insights`. Closes
[#22975](#22975).
The command wraps the
[`GetOrgResourceSearchV2Query`](https://www.pulumi.com/docs/reference/cloud-rest-api/resource-search/#get-apiorgsorgnamesearchresourcesv2)
endpoint:
```
pulumi insights resource search
[--org <org-name>] # context; defaults to the current default org
[--query, -q <pulumi-query>] # filter; empty matches all
[--sort <field>...] # repeat or comma-separate; whitelist enforced
[--asc] # flip direction; defaults to descending
[--page <n>] # 1-based, up to 10,000 total results
[--page-size <n>]
[--cursor <opaque>] # beyond 10,000 (Enterprise plans only)
[--properties] # include input/output values; 402 on unsupported subs
[--collapse] # consolidate IaC+Insights duplicates
[--output, -o default|json] # default: tab-aligned text
```
`--sort` is validated against the documented whitelist before the API
call so a typo doesn't burn a request. `--asc` defaults to descending;
the flag is only sent when set so the server's default applies
otherwise. The same is true of every other zero-valued query parameter —
they're stripped via `url:"...,omitempty"` tags on
`apitype.InsightsResourceSearchParams`.
The command follows the [CLI Command
Guidelines](https://www.notion.so/CLI-Command-Guidelines-350fdbdf1cce80b89367c16b7b421e3d)
and [CLI Option
Guidelines](https://www.notion.so/CLI-Option-Guidelines-357fdbdf1cce8043af51c13f8246b5ce):
- `search` is a leaf verb under the `resource` noun, which nests under
`insights`.
- All inputs are contextual or filters — none are required positional
arguments.
- Default output is human-readable, not JSON.
- `--output` and `--sort` are validated before the API call.
- Constructed via `newInsightsResourceSearchCmd(factory)` for
injection-based unit testing; passing `nil` installs the production
factory that wraps `cloud.ResolveContext`.
New apitypes mirror the OpenAPI response schema:
`InsightsResourceSearchParams`, `InsightsResourceSearchResponse`,
`InsightsResourceSearchResult`, `InsightsResourceSearchPagination`,
`InsightsResourceSearchAggregation`. A new
`*client.Client.SearchInsightsResources` method takes the params struct
directly — `go-querystring` handles the URL encoding via struct tags.
## Sample output
Captured by running the renderer against a representative
`InsightsResourceSearchResponse` fixture.
### Default (tab-aligned text)
```
$ pulumi insights resource search --query 'type:aws:s3/bucket:Bucket'
URN TYPE STACK ACCOUNT MODIFIED
urn:pulumi:prod::api::aws:s3/bucket:Bucket::my-bucket aws:s3/bucket:Bucket prod prod-aws 2026-05-01T14:30:00Z
aws:s3/bucket:Bucket::other-bucket aws:s3/bucket:Bucket - prod-aws -
Showing 2 of 2 resources.
More results available. Re-run with --cursor "next-token" to continue.
```
Rows without a URN (Insights-only records that weren't deployed via
Pulumi) fall back to `<type>::<id>` in the URN column so every row stays
identifiable. Empty columns render as `-` to keep alignment.
Empty result set:
```
$ pulumi insights resource search --query 'type:aws:nonexistent'
No resources found.
```
Last page (no `pagination.next`):
```
$ pulumi insights resource search --query 'type:aws:s3'
URN TYPE STACK ACCOUNT MODIFIED
urn:pulumi:prod::api::aws:s3/bucket:Bucket::my-bucket aws:s3/bucket:Bucket prod prod-aws 2026-05-01T14:30:00Z
…
Showing 12 of 12 resources.
```
### `--output json`
```
$ pulumi insights resource search --query 'type:aws:s3/bucket:Bucket' --output json
{
"total": 2,
"resources": [
{
"account": "prod-aws",
"custom": true,
"id": "my-bucket",
"modified": "2026-05-01T14:30:00Z",
"project": "api",
"stack": "prod",
"type": "aws:s3/bucket:Bucket",
"urn": "urn:pulumi:prod::api::aws:s3/bucket:Bucket::my-bucket"
},
{
"account": "prod-aws",
"id": "other-bucket",
"type": "aws:s3/bucket:Bucket"
}
],
"pagination": {
"next": "/api/orgs/acme/search/resourcesv2?query=foo&cursor=next-token&size=2",
"cursor": "bookmark"
}
}
```
### Errors
Invalid `--sort` is caught before the API call:
```
$ pulumi insights resource search --sort bogus
error: invalid --sort value "bogus" (allowed: category, created, custom, delete, dependencies, id, managed, modified, module, name, package, parentUrn, project, protected, providerUrn, stack, type, urn)
```
Invalid `--output` is caught before the API call:
```
$ pulumi insights resource search --output yaml
error: invalid --output value "yaml" (must be 'default' or 'json')
```
Server-side errors propagate via the existing API client error path,
e.g. `--properties=true` against an unsupported subscription:
```
$ pulumi insights resource search --properties
error: searching insights resources: [402] Payment Required: …
```
## Test plan
- [x] Added appropriate unit tests - For all changes
- [ ] Added a test in `pkg/engine/lifecycletest` - For all
engine/protocol changes
- [ ] Added a conformance test in `pkg/testing/pulumi-test-language` -
For language protocol changes
- [ ] Added a golden test in `pkg/backend/display` - For changes to the
output renderers
`pkg/cmd/pulumi/insights/insights_resource_search_test.go` covers:
- Default text output, including URN fallback for rows without a URN,
the `-` filler for empty cells, and the pagination-hint that surfaces
the cursor extracted from `pagination.next`
- Empty result set ("No resources found.")
- Last page (no `pagination.next` → no hint)
- JSON output (`assert.Equal` against the fixture)
- Default org vs `--org` override propagation
- Full param propagation (`--query`, `--sort` repeated, `--asc`,
`--page`, `--page-size`, `--cursor`, `--properties`, `--collapse`)
- Invalid `--sort` rejected with a message listing allowed values
- Invalid `--output` rejected before the API call
- Client error propagation (e.g. 402) and factory error propagation (not
logged in)
- Full cobra-level flag binding through
`newInsightsResourceSearchCmd(factory).Execute`
- `newInsightsResourceSearchCmd(nil)` installs the production factory
- `cursorFromNextLink` extracts the cursor from both relative and
absolute URLs, and degrades gracefully when the link is empty or has no
cursor
`pkg/backend/httpstate/client/client_insights_test.go` covers
`SearchInsightsResources` against a `httptest.NewServer`:
- Round-trip of a populated response (including `Custom *bool`,
pagination, etc.)
- Query parameter encoding — confirms `query`, `sort` (repeated), `asc`,
`page`, `size`, `properties`, `collapse` all reach the server
- Zero-valued parameters are omitted (empty query string)
- HTTP error propagation (402 Payment Required)
## Validation
- [x] `make lint` — clean (`golangci-lint run --tests` over the affected
packages reports 0 issues)
- [x] `make test_fast` — relevant package tests pass (`insightscmd`,
`httpstate/client`, plus the broader `./cmd/pulumi/...` sweep)
- [x] `make tidy_fix` — clean (no `go.mod` changes; only existing
in-tree imports)
- [x] `make format` — clean (`gofmt -l` reports no diffs on touched
files)
- [x] Relevant SDK tests pass (if SDK changes) — `sdk/go/common/apitype`
tests pass
- [ ] `make check_proto` — n/a, no proto changes
## Changelog
- [x] Changelog entry added: `cli/cloud: Add \`pulumi insights resource
search\` to search for resources discovered by Pulumi Insights`
## Risk
Strictly additive: new apitypes in `sdk/go/common/apitype/insights.go`,
a new `*client.Client.SearchInsightsResources` method, a new endpoint
registration in `pkg/backend/httpstate/client/api_endpoints.go`, and the
full `pulumi insights resource search` command replacing the previous
stub. The stub was already wired in via `newInsightsResourceCmd` (added
in #23077), so the wiring lines in `pkg/cmd/pulumi/pulumi.go` don't
change.
The `pulumi insights` tree is still marked `[EXPERIMENTAL]` in `--help`
text, matching the get command added in #23077.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>pulumi insights resource search (#23087)1 parent 3b02eb9 commit c7ddd56
8 files changed
Lines changed: 1099 additions & 40 deletions
File tree
- changelog/pending
- pkg
- backend/httpstate/client
- cmd/pulumi/insights
- sdk/go/common/apitype
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
137 | 137 | | |
138 | 138 | | |
139 | 139 | | |
| 140 | + | |
140 | 141 | | |
141 | 142 | | |
142 | 143 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2322 | 2322 | | |
2323 | 2323 | | |
2324 | 2324 | | |
| 2325 | + | |
| 2326 | + | |
| 2327 | + | |
| 2328 | + | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
99 | 100 | | |
100 | 101 | | |
101 | 102 | | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | 18 | | |
21 | 19 | | |
22 | 20 | | |
| |||
34 | 32 | | |
35 | 33 | | |
36 | 34 | | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 35 | + | |
75 | 36 | | |
76 | 37 | | |
77 | 38 | | |
0 commit comments