Repository navigation
Add a Web App with Azure Managed Redis sample in Python and .NET, with Bicep, Terraform and passwordless Entra ID - #157
Draft
lazarkanelov wants to merge 14 commits into
Draft
lazarkanelov wants to merge 14 commits into
lazarkanelov wants to merge 14 commits into
Conversation
… sample The Vacation Planner on App Service, storing activities in an Azure Managed Redis database with redis-py, authenticating with the database's access key or, through redis-entraid and DefaultAzureCredential, as a managed identity the database's default access policy is assigned to. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…web-app-managed-redis sample Module-based: main.bicep and main.tf call the shared modules of the web-app-cosmosdb-nosql-api sample, copied byte for byte, and two new ones, managed-redis (cluster, default database, diagnostic settings) and managed-redis-access-policy-assignment (the database's default access policy for the web app's managed identity). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The ASP.NET Core Razor Pages Vacation Planner, storing activities in the same Redis hash shape as the Python app with StackExchange.Redis, and authenticating with the access key or, through Microsoft.Azure.StackExchangeRedis and DefaultAzureCredential, as the web app's managed identity. Its scripts, Bicep and Terraform differ from the Python ones only in the runtime and the build of the app. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
One entry per language, deployment path and identity type, beside the web-app-cosmosdb-nosql-api entries; no ARM64_SAMPLE_DIRS entry, as the web app is built and run on the amd64-only Oryx images. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The update read the activity with HGET and wrote it back with HSET, so a delete that ran in between was undone. Both apps now write the field with a Lua script that sets it only while it exists (HEXISTS then HSET), in one atomic step. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…edis is unreachable The store initializer ran before the server started and stopped the app after its last failed attempt. It now runs in the background, logs the failure and returns, so the app keeps serving and /health answers 503 until the connection, which keeps reconnecting with AbortOnConnectFail=false, comes up, as the Python app does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…f web-app-managed-redis
The Python app returns {id, activity, timestamp}; the .NET app left the
timestamp out. Both now return the same shape.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…managed-redis call-web-app.sh shows four ways to call the web app, not three; the screenshot of the user interface was labelled as the architecture diagram; the .NET README read "a ASP.NET"; and the Python app turned on Flask's debug mode on App Service. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…icep and Terraform deploy scripts Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…LI deploy scripts When MANAGED_IDENTITY_TYPE changed between runs, the access policy assignment of the earlier identity stayed on the database. deploy.sh now deletes every assignment whose object id is not the current principal's, and all of them when the web app uses the access key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each README now says which run-samples.sh entries were validated against the LocalStack for Azure emulator, and that the sample has not been run against real Azure yet. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… READMEs The modules use Microsoft.Cache/redisEnterprise 2026-09-01, the newest stable API version. Bicep CLI 0.49.2, the current release, has its type definitions and builds the templates without BCP081; 0.48.1 and earlier do not, so the README names 0.49.2 as the minimum. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…gnment azurerm_managed_redis_access_policy_assignment takes no name in azurerm 5.1.0 and names the assignment after the object id with its dashes, while the Azure CLI scripts and Bicep drop them. The Terraform READMEs say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Under pipefail, printf, cut and sed die of SIGPIPE once grep -q has its match early in the list of registered samples, and the match reads as a failure: run-samples.sh --list then exits with "ARM64_SAMPLE_DIRS entry ... matches no registered sample" for a sample that is registered. The longer the list, the likelier the race; adding this sample's 14 entries made CI hit it. The folders now reach grep -q as a here-string, as build-matrix.sh already does.
This branch was previously deployed
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.
Motivation
This replaces the earlier content of this PR (a single Python FastAPI voting app under
samples/managed-redis/python) with a sample built to the repository's standard, following the review feedback on the first version. The new sample issamples/web-app-managed-redis: the Vacation Planner single-page web app on Azure App Service, storing activities as the fields of a Redis hash in thedefaultdatabase of an Azure Managed Redis cluster over TLS.The sample was produced by the Emulator Factory (an automated agent pipeline), including an independent review round whose findings were fed back into a continuation run rather than edited by hand.
How each review point is addressed
samples/web-app-managed-redis/python(Flask,PYTHON:3.13) andsamples/web-app-managed-redis/dotnet(ASP.NET Core,DOTNETCORE:10.0), each with its ownREADME.md,bicep/,terraform/,scripts/andsrc/. Both apps expose the same UI and the same/api/activitiesshape ({id, activity, timestamp}).az webapp deploy --type zipwithSCM_DO_BUILD_DURING_DEPLOYMENT=trueandENABLE_ORYX_BUILD=true, as in the otherweb-app-*samples.microsoft-opentelemetry(Python) andMicrosoft.OpenTelemetry(.NET) driven byAPPLICATIONINSIGHTS_CONNECTION_STRING; every module sends diagnostic settings nameddefaultto the workspace.scripts/query-telemetry.shandscripts/query-logs-and-metrics.shquery them, and the READMEs show the queries.log-analytics,application-insights,app-service-plan,web-appandmanaged-identityare byte-identical copies ofsamples/web-app-cosmosdb-nosql-api/*/bicep/modules. Terraform:log_analytics,application_insights,app_service_plan,web_appandmanaged_identityare byte-identical copies ofsamples/web-app-managed-identity/*/terraform/modules. The Redis resources live in new modules,managed-redis/managed_redisandmanaged-redis-access-policy-assignment/managed_redis_access_policy_assignment;main.bicepandmain.tfonly compose modules.bicep/,terraform/andscripts/folders have their own READMEs, and the repository README lists the sample.MANAGED_IDENTITY_TYPEselectsNone(access key, the scripts' default),SystemAssignedorUserAssigned(the Bicep and Terraform default). With an identity, the deployment creates a database access policy assignment (Microsoft.Cache/redisEnterprise/databases/accessPolicyAssignments, policydefault) for the identity's object id, and the app authenticates with the object id as user and an Entra token as password, with no key in its settings. The Azure CLIdeploy.shremoves assignments of a previous identity when the type changes.Changes
samples/managed-redis/python.samples/web-app-managed-redis/pythonandsamples/web-app-managed-redis/dotnet, each deployable with Azure CLI scripts, Bicep or Terraform (azurerm = "=5.1.0").run-samples.shentries (below) and the sample's row inREADME.md. The sample is not inARM64_SAMPLE_DIRS, like the other code-deployedweb-app-*samples.HEXISTS, thenHSET), so a concurrent delete is not undone./healthwith 503 until it is, like the Python app.Tests
Validated against the LocalStack for Azure emulator only, built from localstack-pro branch
azure/managed-redis-tls-only, started like the samples CI (default host port mapping). It has not been run against real Azure yet.All 14
run-samples.shentries for the sample passed, each with its deploy and test commands, two at a time:The entries ran with the Emulator Factory's
run-entries.sh(each entry from its own copy of the language folder with its own name prefix, resource groups deleted afterwards), from a container with the Azure CLI, Terraform, Bicep CLI 0.45.15,jq,zipand Docker, routed to the emulator. Real requests reached the deployed apps (call-web-app.shgot HTTP 200 from every call).The scripts entries with an access key also run
call-web-app.sh,query-telemetry.shandquery-logs-and-metrics.sh; the Bicep and Terraform entries runvalidate.sh,query-telemetry.shandquery-logs-and-metrics.sh.Dependencies
The sample needs Azure Managed Redis in the emulator, which is in review in localstack/localstack-pro:
Until a released
localstack/localstack-azureimage includes them, this sample's CI jobs are expected to fail, so the PR stays a draft.Limitations
Microsoft.Cache/redisEnterprise@2026-09-01; Bicep CLI 0.49.2 or later has types for it (older CLIs warn with BCP081), as the Bicep READMEs state.azurerm_managed_redis_access_policy_assignmenthas nonameargument, so Terraform names the assignment after the object id with dashes, while the CLI scripts and Bicep use it without dashes. The Terraform READMEs note this. The emulator accepts both; whether real Azure accepts the dashed name is unverified.