feat: add C# Azure.Provisioning infrastructure as alternative to Bicep#16
Closed
m-nash wants to merge 2 commits intoAzure-Samples:mainfrom
Closed
feat: add C# Azure.Provisioning infrastructure as alternative to Bicep#16m-nash wants to merge 2 commits intoAzure-Samples:mainfrom
m-nash wants to merge 2 commits intoAzure-Samples:mainfrom
Conversation
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>
becff66 to
c3d5998
Compare
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>
Author
|
Closing in favor of a standalone sample repo: https://github.com/m-nash/todo-csharp-cosmos-sql-dotnet |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
How to switch
In
azure.yaml, change two lines:Then run
azd upas normal. Requires .NET 10 SDK and thecodeprovider alpha feature enabled (azd config set alpha.code on).Resources created
The C#
infra.cscreates the same resources as the Bicep templates:Testing
azd updeployed all 7 resources + both servicesDependencies
This requires the
provider: codefeature from Azure/azure-dev#7352.Known limitation
CosmosDBSqlRoleAssignmentin Azure.Provisioning doesn't auto-generate the requiredname(GUID) for the sub-resource. The Cosmos DB RBAC role assignment is handled via a post-provisionazCLI hook as a workaround.