Skip to content

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
mainfrom
managed-redis-sample
Draft

lazarkanelov wants to merge 14 commits into
mainfrom
managed-redis-sample

Conversation

@lazarkanelov

@lazarkanelov lazarkanelov commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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 is samples/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 the default database 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

Review point Where
Python and .NET Two self-contained sibling folders, samples/web-app-managed-redis/python (Flask, PYTHON:3.13) and samples/web-app-managed-redis/dotnet (ASP.NET Core, DOTNETCORE:10.0), each with its own README.md, bicep/, terraform/, scripts/ and src/. Both apps expose the same UI and the same /api/activities shape ({id, activity, timestamp}).
Azure App Service Both apps run on an App Service plan and web app; code reaches App Service as an unbuilt zip via az webapp deploy --type zip with SCM_DO_BUILD_DURING_DEPLOYMENT=true and ENABLE_ORYX_BUILD=true, as in the other web-app-* samples.
Log Analytics and Application Insights A Log Analytics workspace and a workspace-based Application Insights component in every deployment path. Telemetry uses microsoft-opentelemetry (Python) and Microsoft.OpenTelemetry (.NET) driven by APPLICATIONINSIGHTS_CONNECTION_STRING; every module sends diagnostic settings named default to the workspace. scripts/query-telemetry.sh and scripts/query-logs-and-metrics.sh query them, and the READMEs show the queries.
Dedicated Bicep and Terraform modules, reusing the existing ones Bicep: log-analytics, application-insights, app-service-plan, web-app and managed-identity are byte-identical copies of samples/web-app-cosmosdb-nosql-api/*/bicep/modules. Terraform: log_analytics, application_insights, app_service_plan, web_app and managed_identity are byte-identical copies of samples/web-app-managed-identity/*/terraform/modules. The Redis resources live in new modules, managed-redis / managed_redis and managed-redis-access-policy-assignment / managed_redis_access_policy_assignment; main.bicep and main.tf only compose modules.
Mermaid diagram and README Each language README has an Architecture section with a mermaid diagram, plus Prerequisites, Deployment, Microsoft Entra ID authentication, Test, Application Insights, Logs and metrics, Azure Managed Redis tooling and References. The bicep/, terraform/ and scripts/ folders have their own READMEs, and the repository README lists the sample.
Passwordless Microsoft Entra ID through a managed identity MANAGED_IDENTITY_TYPE selects None (access key, the scripts' default), SystemAssigned or UserAssigned (the Bicep and Terraform default). With an identity, the deployment creates a database access policy assignment (Microsoft.Cache/redisEnterprise/databases/accessPolicyAssignments, policy default) 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 CLI deploy.sh removes assignments of a previous identity when the type changes.

Changes

  • Removes samples/managed-redis/python.
  • Adds samples/web-app-managed-redis/python and samples/web-app-managed-redis/dotnet, each deployable with Azure CLI scripts, Bicep or Terraform (azurerm = "=5.1.0").
  • Adds 14 run-samples.sh entries (below) and the sample's row in README.md. The sample is not in ARM64_SAMPLE_DIRS, like the other code-deployed web-app-* samples.
  • Updates are atomic: an activity update is one Lua script (HEXISTS, then HSET), so a concurrent delete is not undone.
  • The .NET app starts even when Redis is not reachable yet and answers /health with 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.sh entries for the sample passed, each with its deploy and test commands, two at a time:

# Language Path Identity
1 Python Azure CLI scripts None (access key)
2 .NET Azure CLI scripts None (access key)
3 Python Azure CLI scripts SystemAssigned
4 Python Azure CLI scripts UserAssigned
5 .NET Azure CLI scripts SystemAssigned
6 .NET Azure CLI scripts UserAssigned
7 Python Terraform SystemAssigned
8 Python Terraform UserAssigned
9 .NET Terraform SystemAssigned
10 .NET Terraform UserAssigned
11 Python Bicep SystemAssigned
12 Python Bicep UserAssigned
13 .NET Bicep SystemAssigned
14 .NET Bicep UserAssigned

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, zip and Docker, routed to the emulator. Real requests reached the deployed apps (call-web-app.sh got HTTP 200 from every call).

The scripts entries with an access key also run call-web-app.sh, query-telemetry.sh and query-logs-and-metrics.sh; the Bicep and Terraform entries run validate.sh, query-telemetry.sh and query-logs-and-metrics.sh.

Dependencies

The sample needs Azure Managed Redis in the emulator, which is in review in localstack/localstack-pro:

  • localstack/localstack-pro#11545
  • localstack/localstack-pro#11546
  • localstack/localstack-pro#11547
  • localstack/localstack-pro#11549
  • localstack/localstack-pro#11550

Until a released localstack/localstack-azure image includes them, this sample's CI jobs are expected to fail, so the PR stays a draft.

Limitations

  • Not yet deployed to real Azure.
  • The Bicep modules use 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.
  • In azurerm 5.1.0, azurerm_managed_redis_access_policy_assignment has no name argument, 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.
  • Two concurrent updates of the same activity are still last-writer-wins.

lazarkanelov and others added 14 commits December 3, 2026 15:48
… 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

1 inactive deployment
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