Public: anyone can read this; the crew can change it.

Infrastructure reads Azure: subscriptions, resources and costs #17924

opened this

Merged 23h 46m ago, live in production

I merged main into the branch and pushed. The merge was clean after resolving three conflicts. tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.

Notes

opened this

I merged main into the branch and pushed. The merge was clean after resolving three conflicts. tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.

Another pull had landed on main with its own Azure reader. Its src/cloud/azure_read.ts and test/cloud-azure.test.ts collided with mine, and it wired Azure into PROJECT_CLOUDS and the six-hour interval the same way I did.

  • Subscriptions and resources: I took main's azure_read.ts, its test and its projects.ts side wholesale and dropped my duplicate reader. My extra resource kind in inventory.ts is gone, since nothing uses it.
  • Cost, kept on top:
    • Cost Management read: src/cloud/azure_cost.ts is unchanged except that it now calls main's call.
    • Read-only guard: call is exported and refuses any POST except Resource Graph and the Cost Management query.
    • Wiring: projects.ts gets back my two lines, the Azure bill and the cost read after each Azure read.
  • Tests: my cost tests are now in test/cloud-azure-cost.test.ts and still cover the 1975-cent hand check, the named Cost Management role, the non-USD refusal and the write refusal.
  • Docs: my docs/CLOUD.md section is trimmed to the cost part, so it no longer repeats main's Azure paragraph.

main's reader reports a failed Resource Graph read as one gap of kind project per subscription. The resources kept from the last good read are not protected by it, as my per-kind gaps would have done. I left that as main wrote it.

Continues #17924

2 earlier comments
commented

An Azure account on /infra now shows its subscriptions as projects, with their resources and month-to-date cost. A missing role is named in the page, terminal and infra tool instead of failing the read. I haven't tried it against a real Azure account. The new tests, the existing cloud tests, tsc, the gate rules and the dead-code, hollow and doorless tests pass here; the full suite is left to the forge's check on this push.

What changed

  • Subscriptions and resources (src/cloud/azure_read.ts): GET /subscriptions makes each subscription a project. One Resource Graph query lists their resources, mapped to the existing kinds (VMs, disks, public IPs and so on). A type with no kind of its own becomes a new resource kind, with its Azure type as its size.
  • Cost (src/cloud/azure_cost.ts): one Cost Management query per subscription gives actual cost by service, for last month and this month so far. Each subscription is replaced independently, so one that fails keeps its last bill. The bill's region column holds the subscription id, so the existing per-project billing works with no schema change.
  • Missing roles:
    • A refused Resource Graph read is a gap on every subscription, with the existing rows kept beside it. The reason reads "the key needs the Reader role on the subscription".
    • A refused cost read names the Cost Management Reader role in the bill error and keeps the last bill.
    • Only Azure's error code is shown, never its message text.
  • Read-only: azureCall allows GETs and only the two query POSTs (Resource Graph and Cost Management). It refuses redirects and any link that leaves management.azure.com.
  • Reach: Azure joins PROJECT_CLOUDS and is read every six hours, and the bill is read after each resource read. The existing /infra tree, terminal Cloud resources and infra tool draw it. The commit says No door: for that reason. forge.json egress already had both Azure hosts.
  • Reused: azureToken and ARM from providers.ts (now exported), and the AWS and Cloudflare readers' gap/reasonOf model and cappedText.
  • Docs: docs/CLOUD.md and docs/features/infra.md.
  • Tests: test/cloud-azure.test.ts checks that 12.50 + 7.25 gives 1975 cents, both missing-role cases, a non-USD refusal, and that a write is refused.

Chosen not to do

  • Currency conversion: a bill that isn't in USD is refused, not converted.
  • Per-resource cost: Azure doesn't give it here, so a resource has no price of its own.
  • The infra tool's bill lines show the subscription id where AWS shows a region, because the region column holds the subscription.
  • A subscription where the principal has no role at all can't be told apart from an empty one, because Resource Graph silently filters those out.

Try it: add an Azure account in Settings with a Reader principal as TENANT:CLIENT:SECRET, press Read now on /infra, and open its tree.

🤖 Generated with Claude Code

commented

I merged main into the branch and pushed. The merge was clean after resolving three conflicts. tsc, the gate rules, the dead-code, hollow and doorless tests, and the Azure, projects and tree tests pass.

Another pull had landed on main with its own Azure reader. Its src/cloud/azure_read.ts and test/cloud-azure.test.ts collided with mine, and it wired Azure into PROJECT_CLOUDS and the six-hour interval the same way I did.

  • Subscriptions and resources: I took main's azure_read.ts, its test and its projects.ts side wholesale and dropped my duplicate reader. My extra resource kind in inventory.ts is gone, since nothing uses it.
  • Cost, kept on top:
    • Cost Management read: src/cloud/azure_cost.ts is unchanged except that it now calls main's call.
    • Read-only guard: call is exported and refuses any POST except Resource Graph and the Cost Management query.
    • Wiring: projects.ts gets back my two lines, the Azure bill and the cost read after each Azure read.
  • Tests: my cost tests are now in test/cloud-azure-cost.test.ts and still cover the 1975-cent hand check, the named Cost Management role, the non-USD refusal and the write refusal.
  • Docs: my docs/CLOUD.md section is trimmed to the cost part, so it no longer repeats main's Azure paragraph.

main's reader reports a failed Resource Graph read as one gap of kind project per subscription. The resources kept from the last good read are not protected by it, as my per-kind gaps would have done. I left that as main wrote it.

commented

All four review points are addressed and pushed to this branch. The Azure tests and tsc pass. In test/cloud-inventory.test.ts, one test, "the duty's own fetch carries redirect: error…", fails here. It gets 202 instead of 200 from the sandbox's filtering proxy. I did not touch that code. I did not run the full suite; the forge runs it on the push.

What changed

  • Tests (test/cloud-azure-cost.test.ts): one test for each behaviour you listed:
    • Partial failure: the failed subscription keeps its last lines, the good one is replaced, and the error reads "1 of 2 subscriptions…".
    • cost_read_at: a read that fails whole leaves the time of the last good read.
    • nextLink: it is followed, and a line split over two pages is summed (1.5 + 2.25 = 3.75).
    • MAX_PAGES: an endless nextLink is refused at MAX_PAGES and the old bill stays.
    • Removed subscription: the final DELETE removes the bill of a subscription the account no longer holds.
    • 429: a throttled read keeps the old bill, and the next read replaces it and clears the error.
  • Disabled subscriptions: readAzure now marks any subscription that is not Enabled with the project note "the subscription is Disabled", and readAzureCost skips those. The state was not stored anywhere, so the note carries it. A test shows the disabled SUB2 is never asked. I added a sentence to docs/CLOUD.md.
  • MAX_PAGES: exported once from azure_read.ts (100) and imported by azure_cost.ts. The 20 in the cost file is gone, so a cost read now allows up to 100 pages.
  • Header comment: reworded to "Actual cost, Azure's own figure as billed, in dollars only…".

One more fix: the partial-failure test showed the error text read "subscriptions's cost was read". It now reads "1 of 2 subscriptions had no cost read: …", and "no subscription's cost was read: …" when none was. That is a change to the user-facing message.

Not done: the two later items, the unmarked kept resources after a failed Resource Graph read and the infra tool showing the subscription id where AWS shows a region. Also, if every subscription is disabled, readAzureCost returns early and any bill lines already kept stay.

No live Azure account was available, so nothing was checked against one.

To try it: bun test test/cloud-azure-cost.test.ts.

🤖 Generated with Claude Code

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs