Skip to content

feat: add C# Azure.Provisioning infrastructure as alternative to Bicep#16

Closed
m-nash wants to merge 2 commits intoAzure-Samples:mainfrom
m-nash:feature/azure-provisioning-cdk
Closed

feat: add C# Azure.Provisioning infrastructure as alternative to Bicep#16
m-nash wants to merge 2 commits intoAzure-Samples:mainfrom
m-nash:feature/azure-provisioning-cdk

Conversation

@m-nash
Copy link
Copy Markdown

@m-nash m-nash commented Mar 30, 2026

Summary

Adds a C# infrastructure option using Azure.Provisioning alongside the existing Bicep templates. Users can define Azure infrastructure in C# instead of Bicep, with Bicep generated as an invisible intermediate step.

Structure

infra/
+-- bicep/          # Original Bicep templates (default, unchanged)
|   +-- main.bicep
|   +-- main.parameters.json
|   +-- abbreviations.json
|   +-- app/*.bicep
+-- dotnet/         # C# Azure.Provisioning equivalent
    +-- infra.cs    # Single file, .NET 10 file-based app

How to switch

In azure.yaml, change two lines:

infra:
  # path: infra/bicep          # Comment this out
  provider: code               # Uncomment these two
  path: infra/dotnet

Then run azd up as normal. Requires .NET 10 SDK and the code provider alpha feature enabled (azd config set alpha.code on).

Resources created

The C# infra.cs creates the same resources as the Bicep templates:

  • Cosmos DB (NoSQL, serverless) with TodoList and TodoItem containers
  • App Service Plan (B3, Linux)
  • Web App (Node.js 20, React frontend with PM2)
  • API App (.NET 8, managed identity, CORS)
  • Key Vault (RBAC authorization)
  • Application Insights + Log Analytics
  • Cosmos DB RBAC via post-provision hook

Testing

  • E2E tested: azd up deployed all 7 resources + both services
  • API returns 200 with Cosmos DB connection via managed identity
  • Playwright create/delete todo test passed against the live deployment

Dependencies

This requires the provider: code feature from Azure/azure-dev#7352.

Known limitation

CosmosDBSqlRoleAssignment in Azure.Provisioning doesn't auto-generate the required name (GUID) for the sub-resource. The Cosmos DB RBAC role assignment is handled via a post-provision az CLI hook as a workaround.

Adds a C# infrastructure option using Azure.Provisioning alongside the
existing Bicep templates. Users can switch between Bicep and C# by
changing two lines in azure.yaml.

Structure:
  infra/bicep/   - Original Bicep templates (default)
  infra/dotnet/  - C# Azure.Provisioning equivalent (single file)

The C# infra.cs file creates the same resources as the Bicep templates:
- Cosmos DB (NoSQL, serverless) with TodoList and TodoItem containers
- App Service Plan (B3, Linux)
- Web App (Node.js 20, React frontend)
- API App (.NET 8, managed identity, CORS)
- Key Vault (RBAC authorization)
- Application Insights + Log Analytics
- Cosmos DB RBAC via post-provision hook

E2E tested: azd up deployed all resources, Playwright create/delete
todo test passed against the live deployment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@m-nash m-nash force-pushed the feature/azure-provisioning-cdk branch from becff66 to c3d5998 Compare March 30, 2026 22:16
Cosmos DB Data Contributor role assignment is now defined directly in
infra.cs using a reflection workaround for the read-only Name property
on CosmosDBSqlRoleAssignment. This eliminates the need for the az CLI
postprovision hook.

Also fixed guid() to use deploy-time-computable values (cosmos.id,
api.id) instead of runtime values (api.identity.principalId).

E2E tested: azd up, API 200, Playwright create/delete test passed,
azd down.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@m-nash
Copy link
Copy Markdown
Author

m-nash commented Mar 31, 2026

Closing in favor of a standalone sample repo: https://github.com/m-nash/todo-csharp-cosmos-sql-dotnet

@m-nash m-nash closed this Mar 31, 2026
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