Skip to content

Create missing Cosmos containers under managed identity - #1969

Merged
Paul Lizer (paullizer) merged 2 commits into
Developmentfrom
claude/azd-deploy-container-creation-27c40e
Nov 20, 2026
Merged

Paul Lizer (paullizer) merged 2 commits into
Developmentfrom
claude/azd-deploy-container-creation-27c40e

Conversation

@paullizer

@paullizer Paul Lizer (paullizer) commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Problem

At startup the app calls create_container_if_not_exists for every Cosmos container. With key auth that creates any container a new release adds. With managed identity, Cosmos refuses container creation on its data-plane endpoint (403, substatus 5300) whatever data-plane role the identity holds, so the app failed to start after azd deploy.

azd deploy doesn't re-run Bicep, and Bicep was missing 11 of the app's containers anyway. Terraform was missing 14.

Changes

  • ARM fallback (functions_cosmos_container_provisioning.py, config.py): when the data-plane create returns 403 under managed identity, the app creates the container through Azure Resource Manager with the same partition key, TTL and indexing policy. It uses the Contributor role the deployers already grant. If the container already exists it writes nothing, and on a 202 it waits on the container resource. Key auth is unchanged.
  • No input needed: the account's subscription and resource group come from AZURE_SUBSCRIPTION_ID / AZURE_RESOURCE_GROUP, or, when those are absent, from App Service's own WEBSITE_OWNER_NAME / WEBSITE_RESOURCE_GROUP. If the database isn't found there, the app creates nothing and logs which settings to set.
  • Deployers (version 1.0.41):
    • Bicep declares all app containers, and main.json is rebuilt with Bicep 0.44.1.
    • Terraform declares them too, including the 3 it was already missing.
    • Terraform and the Azure CLI deployer now set AZURE_SUBSCRIPTION_ID, AZURE_RESOURCE_GROUP and AZURE_COSMOS_ACCOUNT_NAME.
  • Admin script deployers/Grant-CosmosContainerCreatePermission.ps1: for an identity without Contributor on the Cosmos account. It grants a narrow custom role (container read and write only) or, with -UseBuiltInRole, DocumentDB Account Contributor. Supports -WhatIf.
  • App version 0.261.475 (Development already used 0.261.474), plus a fix doc, release notes and regenerated release-note pages.

Testing

  • functional_tests/test_cosmos_container_arm_provisioning.py (12 tests) passes. It fails if a container the app creates is missing or has a different partition key in Bicep, main.json or Terraform. It also covers the fallback paths and the deployer settings.
  • scripts/check_cosmos_response_boundaries.py: no review gaps.
  • Related deployer and functional tests: 6 fail, and the same tests fail on an unchanged copy of main (stale pinned versions and other existing gaps).
  • Not yet verified on a live managed-identity deployment.

🤖 Generated with Claude Code

Cosmos refuses data-plane container creation for Entra-authenticated callers,
so a release that added a container failed to start after azd deploy on a
managed-identity deployment. The app now creates the missing container through
Azure Resource Manager when that 403 happens, locating the account from
AZURE_SUBSCRIPTION_ID/AZURE_RESOURCE_GROUP or, when absent, from App Service's
own platform variables.

- Declare all app containers in Bicep (11 missing) and Terraform (14 missing);
  rebuild main.json
- Terraform and Azure CLI deployers set the Cosmos location settings
- Add Grant-CosmosContainerCreatePermission.ps1 for identities without
  Contributor on the Cosmos account
- Version 0.261.474, deployers 1.0.41

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paullizer
Paul Lizer (paullizer) changed the base branch from main to Development November 20, 2026 18:49
Development took 0.261.474 for the catalog publisher keys, so this change moves
to 0.261.475 with its own release-notes section, and the release note pages are
regenerated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paullizer
Paul Lizer (paullizer) merged commit 8e59e65 into Development Nov 20, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant