<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martin Oehlert</title>
    <description>The latest articles on DEV Community by Martin Oehlert (@martin_oehlert).</description>
    <link>https://dev.to/martin_oehlert</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1661015%2Fd0bdf508-0244-49d8-8655-aea054d71b86.png</url>
      <title>DEV Community: Martin Oehlert</title>
      <link>https://dev.to/martin_oehlert</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/martin_oehlert"/>
    <language>en</language>
    <item>
      <title>Azure Functions Integration Tests with Testcontainers and Azurite</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 20 Nov 2026 09:39:09 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-functions-integration-tests-with-testcontainers-and-azurite-44e6</link>
      <guid>https://dev.to/martin_oehlert/azure-functions-integration-tests-with-testcontainers-and-azurite-44e6</guid>
      <description>&lt;p&gt;Which bugs in a queue-triggered Azure Function can a test with a mocked &lt;code&gt;QueueClient&lt;/code&gt; never catch? Every bug that lives in the storage service or in the trigger binding instead of in your code: the encoding of the queue message, a blob container that doesn't exist yet, the naming rules for containers and blobs, and the JSON the worker has to deserialize. A test against a real Azurite container catches all four. With one container for the whole test run, the sample's six tests, two of them through a running Functions host, finish in under ten seconds on my machine.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://dev.to/martin_oehlert/testing-azure-functions-unit-integration-and-local-1cml"&gt;unit testing article&lt;/a&gt; from earlier this year is the baseline: business logic in a service class, the function class tested with fakes, and a first look at Testcontainers. This series picks up where it stopped. Part 1 stays with Azure Storage, queues in and blobs out; the later parts cover Cosmos DB, Service Bus, architecture rules, contracts, load and CI. The code is in the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/OrderPipelineDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;, on .NET 10 with the isolated worker, xUnit v3 and Testcontainers 4.16. The repo moved to those versions after the unit testing article, so that article's code no longer matches it line for line.&lt;/p&gt;

&lt;h2&gt;
  
  
  The order pipeline under test
&lt;/h2&gt;

&lt;p&gt;An API puts orders on the &lt;code&gt;orders&lt;/code&gt; queue. A queue-triggered function picks each one up and, for a paid order, writes an invoice as JSON into the &lt;code&gt;invoices&lt;/code&gt; blob container:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;ILogger&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;QueueTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Status&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"order-{order.Id}.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UploadAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;BinaryData&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromObjectAsJson&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;overwrite&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Invoice written for order {OrderId}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The container client comes from DI, registered once in &lt;code&gt;Program.cs&lt;/code&gt; against the same storage account the trigger uses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;AddSingleton&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"AzureWebJobsStorage"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"invoices"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The producer side is a small &lt;code&gt;OrderApi&lt;/code&gt; class that serializes the order and sends it, plus an &lt;code&gt;OrderQueue.Create&lt;/code&gt; factory for its &lt;code&gt;QueueClient&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderQueue&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The queue trigger expects Base64; the SDK default (None) sends plain text that the trigger can't decode.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;QueueClient&lt;/span&gt; &lt;span class="nc"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueueClientOptions&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nc"&gt;MessageEncoding&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;QueueMessageEncoding&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Base64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;QueueClient&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The public API contract writes enums as names, like most ASP.NET Core APIs configured for JSON.&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;JsonSerializerOptions&lt;/span&gt; &lt;span class="nc"&gt;Json&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JsonSerializerDefaults&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Web&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Converters&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;JsonStringEnumConverter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;PlaceAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SendMessageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JsonSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Serialize&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The unit tests most code bases have for this pipeline look like this, written with NSubstitute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;PlaceAsync_sends_the_order_to_the_queue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Substitute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;For&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;QueueClient&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlaceAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaidOrder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="cp"&gt;#pragma warning disable xUnit1051 // Received() checks a recorded call; there is nothing to cancel&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Received&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SendMessageAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="cp"&gt;#pragma warning restore xUnit1051&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Run_uploads_the_invoice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Substitute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;For&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Substitute&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;For&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BlobClient&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Returns&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NullLogger&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaidOrder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Received&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UploadAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Arg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;BinaryData&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;Arg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(The pragma is for &lt;strong&gt;xUnit1051&lt;/strong&gt;, a v3 analyzer that wants &lt;code&gt;TestContext.Current.CancellationToken&lt;/code&gt; passed to every call that accepts a token. &lt;code&gt;Received()&lt;/code&gt; only checks a call that already happened, so there is nothing to cancel.)&lt;/p&gt;

&lt;p&gt;Both tests are green, and both stay green with every bug below put back into the code. A mock verifies that you called &lt;code&gt;SendMessageAsync&lt;/code&gt; and &lt;code&gt;UploadAsync&lt;/code&gt;. It can't tell you whether the message is readable by the trigger, or whether the upload would succeed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four bugs the mock passes
&lt;/h2&gt;

&lt;h3&gt;
  
  
  The queue message the trigger can't read
&lt;/h3&gt;

&lt;p&gt;Remove the &lt;code&gt;QueueClientOptions&lt;/code&gt; from &lt;code&gt;OrderQueue.Create&lt;/code&gt; and you have the producer most people write first:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueueClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;connectionString&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It compiles, it sends, and &lt;code&gt;SendMessageAsync&lt;/code&gt; returns a receipt. The &lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-trigger" rel="noopener noreferrer"&gt;queue trigger documentation&lt;/a&gt; says "Functions expect a &lt;em&gt;base64&lt;/em&gt; encoded string", and the &lt;a href="https://learn.microsoft.com/dotnet/api/azure.storage.queues.queueclientoptions.messageencoding" rel="noopener noreferrer"&gt;&lt;code&gt;MessageEncoding&lt;/code&gt;&lt;/a&gt; option of the v12 SDK says "The default is None". So the client puts the JSON on the queue as plain text, the trigger fails to decode it on every attempt, and after five attempts (the default &lt;code&gt;maxDequeueCount&lt;/code&gt;) the host moves it to &lt;code&gt;orders-poison&lt;/code&gt;. The log line you get is about the dequeue count, along the lines of "Message has reached MaxDequeueCount of 5. Moving message to queue 'orders-poison'" (&lt;a href="https://github.com/Azure/azure-sdk-for-net/issues/21449" rel="noopener noreferrer"&gt;azure-sdk-for-net #21449&lt;/a&gt;), not about the encoding. No exception reaches the producer, and nothing in the function's own code runs, so there is nothing for its logs to say.&lt;/p&gt;

&lt;p&gt;The mocked &lt;code&gt;QueueClient&lt;/code&gt; in &lt;code&gt;PlaceAsync_sends_the_order_to_the_queue&lt;/code&gt; records the call and passes. It never encodes anything, and no trigger reads from it.&lt;/p&gt;

&lt;p&gt;There are two fixes. Set &lt;code&gt;MessageEncoding = QueueMessageEncoding.Base64&lt;/code&gt; on every producer, as &lt;code&gt;OrderQueue.Create&lt;/code&gt; does, or tell the Functions host to accept plain text with &lt;code&gt;"messageEncoding": "none"&lt;/code&gt; under &lt;code&gt;extensions.queues&lt;/code&gt; in &lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-bindings-storage-queue#hostjson-settings" rel="noopener noreferrer"&gt;&lt;code&gt;host.json&lt;/code&gt;&lt;/a&gt; (valid values are &lt;code&gt;base64&lt;/code&gt; and &lt;code&gt;none&lt;/code&gt;; the isolated worker needs version 5.x or later of the Storage Queues extension). The host setting fixes it for every producer at once, including ones in other languages, but it also changes what the trigger expects from producers that already send Base64. In a code base where one team owns both sides, keep the default and fix the client in one shared factory.&lt;/p&gt;

&lt;p&gt;Only a test that runs the trigger catches this bug. Calling &lt;code&gt;OrderProcessor.Run&lt;/code&gt; directly hands it an &lt;code&gt;Order&lt;/code&gt; object, which skips the decoding, so this one needs the round trip through &lt;code&gt;func start&lt;/code&gt; further down.&lt;/p&gt;

&lt;h3&gt;
  
  
  The container that Bicep created
&lt;/h3&gt;

&lt;p&gt;The second bug is the one line in &lt;code&gt;Run&lt;/code&gt; that looks optional: &lt;code&gt;CreateIfNotExistsAsync&lt;/code&gt;. Without it, the function uploads into a container it assumes exists. In production it does, because the Bicep template created it. In a new environment, a renamed container, or a storage account someone recreated, the upload fails with &lt;code&gt;404 ContainerNotFound&lt;/code&gt; ("The specified container does not exist."), and every paid order retries into the poison queue.&lt;/p&gt;

&lt;p&gt;The mocked &lt;code&gt;BlobContainerClient&lt;/code&gt; has no idea which containers exist, so &lt;code&gt;Run_uploads_the_invoice&lt;/code&gt; passes either way. Whether to create the container in code or keep it in infrastructure is a real choice: &lt;code&gt;CreateIfNotExistsAsync&lt;/code&gt; costs a request per message, and with a locked-down identity the function may not have permission to create containers at all. Either way the test that catches the missing container has to run against storage that starts empty.&lt;/p&gt;

&lt;h3&gt;
  
  
  Names: lowercase containers, case-sensitive blobs
&lt;/h3&gt;

&lt;p&gt;Azure Storage has two casing rules, and a mock enforces neither. From the &lt;a href="https://learn.microsoft.com/rest/api/storageservices/naming-and-referencing-containers--blobs--and-metadata" rel="noopener noreferrer"&gt;naming reference&lt;/a&gt;: "All letters in a container name must be lowercase", and "Blob names are case-sensitive".&lt;/p&gt;

&lt;p&gt;The first one bites when someone writes &lt;code&gt;"Invoices"&lt;/code&gt; in the &lt;code&gt;Program.cs&lt;/code&gt; registration. The service rejects it with a 400 and the error code &lt;code&gt;InvalidResourceName&lt;/code&gt;. Azurite checks the same pattern on every request.&lt;/p&gt;

&lt;p&gt;The second one is quieter. If the function writes &lt;code&gt;Order-42.json&lt;/code&gt; and the service that serves invoices asks for &lt;code&gt;order-42.json&lt;/code&gt;, the upload succeeds and the read gets a 404. Both sides look correct on their own, and both sides' unit tests pass.&lt;/p&gt;

&lt;h3&gt;
  
  
  The enum that arrives as a string
&lt;/h3&gt;

&lt;p&gt;The isolated worker deserializes the queue message with System.Text.Json, and the &lt;a href="https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/customize-properties#enums-as-strings" rel="noopener noreferrer"&gt;serialization docs&lt;/a&gt; are clear about enums: "By default, enums are serialized as numbers." &lt;code&gt;OrderApi&lt;/code&gt; follows its public JSON contract and writes &lt;code&gt;"status":"Paid"&lt;/code&gt;. A worker that expects a number can't bind that to &lt;code&gt;OrderStatus&lt;/code&gt;, the function never runs, and the message retries into the poison queue. The fix sits on the enum, so every serializer that touches the type agrees:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;decimal&lt;/span&gt; &lt;span class="nc"&gt;Total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt; &lt;span class="nc"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Producers send the name ("Paid"); System.Text.Json reads enums as numbers unless told otherwise.&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;JsonConverter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;JsonStringEnumConverter&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderStatus&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nc"&gt;Pending&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One serialization difference that is &lt;strong&gt;not&lt;/strong&gt; a bug: property name casing. &lt;code&gt;OrderApi&lt;/code&gt; writes camelCase (&lt;code&gt;"customerId"&lt;/code&gt;) and the record has &lt;code&gt;CustomerId&lt;/code&gt;. The worker's defaults ignore casing on property names, so this binds fine, and the round-trip test below proves it on every run.&lt;/p&gt;

&lt;p&gt;The mocked test calls &lt;code&gt;Run&lt;/code&gt; with an &lt;code&gt;Order&lt;/code&gt; object, so nothing gets serialized and the enum never meets a string.&lt;/p&gt;

&lt;p&gt;Two of the four bugs live in the storage service, two in the binding. The container and the blob names fail on the first real request, so calling &lt;code&gt;OrderProcessor.Run&lt;/code&gt; with a real &lt;code&gt;BlobContainerClient&lt;/code&gt; is enough to catch them. The encoding and the enum fail before &lt;code&gt;Run&lt;/code&gt; is ever called, inside the host and the worker, so only a test that puts a message on a real queue and lets the Functions host pick it up will see them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Azurite in a container, per test run
&lt;/h2&gt;

&lt;p&gt;The test project needs xUnit v3, the Azurite module and the runner packages. With central package management the versions live in &lt;code&gt;Directory.Packages.props&lt;/code&gt;, and the test project only names them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Microsoft.NET.Test.Sdk"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"NSubstitute"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"Testcontainers.Azurite"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"xunit.v3"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s"&gt;"xunit.runner.visualstudio"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;PrivateAssets&amp;gt;&lt;/span&gt;all&lt;span class="nt"&gt;&amp;lt;/PrivateAssets&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;IncludeAssets&amp;gt;&lt;/span&gt;runtime; build; native; contentfiles; analyzers&lt;span class="nt"&gt;&amp;lt;/IncludeAssets&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/PackageReference&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The sample pins &lt;code&gt;Testcontainers.Azurite&lt;/code&gt; 4.16.0, &lt;code&gt;xunit.v3&lt;/code&gt; 4.0.3 and &lt;code&gt;xunit.runner.visualstudio&lt;/code&gt; 4.0.1. An xUnit v3 test project is an executable, so it also sets &lt;code&gt;&amp;lt;OutputType&amp;gt;Exe&amp;lt;/OutputType&amp;gt;&lt;/code&gt;. On the .NET 10 SDK, &lt;code&gt;dotnet test&lt;/code&gt; no longer runs these projects through the VSTest target; it stops with "Testing with VSTest target is no longer supported by Microsoft.Testing.Platform on .NET 10 SDK and later". The repo opts into the new test runner in &lt;code&gt;global.json&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"runner"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Microsoft.Testing.Platform"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that, a single project runs with &lt;code&gt;dotnet test --project OrderPipelineDemo.Tests&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The container itself takes four lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;AzuriteContainer&lt;/span&gt; &lt;span class="n"&gt;_azurite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AzuriteBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mcr.microsoft.com/azure-storage/azurite:3.37.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithInMemoryPersistence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;// Azure.Storage.Blobs 12.30 and Queues 12.28 send API version 2026-10-06; Azurite 3.37.0 stops at 2026-06-06.&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--skipApiVersionCheck"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pin the image in the constructor.&lt;/strong&gt; In Testcontainers 4.16 the parameterless &lt;code&gt;new AzuriteBuilder()&lt;/code&gt; is marked obsolete ("Use the constructor with the image parameter instead"), and its default is still &lt;code&gt;azurite:3.28.0&lt;/code&gt;. With &lt;code&gt;TreatWarningsAsErrors&lt;/code&gt; the obsolete constructor doesn't even compile. Even without that setting, 3.28.0 is the image the unit testing article ran into: Core Tools sent a storage service version it didn't know.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pinning the newest image isn't enough either.&lt;/strong&gt; 3.37.0 is the latest Azurite release, and it supports service versions up to 2026-06-06. The current storage SDKs are already past that: the first run of the sample failed with "The API version 2026-10-06 is not supported by Azurite. Please upgrade Azurite to latest version and retry." There is no newer Azurite to upgrade to, so the sample passes &lt;code&gt;--skipApiVersionCheck&lt;/code&gt;, a flag Azurite has for this case (the &lt;code&gt;AZURITE_SKIP_API_VERSION_CHECK=true&lt;/code&gt; environment variable does the same). The alternative is to pin each client to an older service version through its options, which you would then have to do in the function code as well. The gotchas below cover when the flag can go.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;WithInMemoryPersistence()&lt;/code&gt; keeps the blobs and queues in memory instead of on the container's disk; nothing outlives the test run anyway. The builder maps Azurite's three ports (10000 to 10002) to random host ports, so two test runs on the same CI agent don't collide, and &lt;code&gt;GetConnectionString()&lt;/code&gt; returns a connection string with those mapped ports filled in. Pass it straight to &lt;code&gt;BlobContainerClient&lt;/code&gt;, &lt;code&gt;QueueClient&lt;/code&gt; or the Functions host.&lt;/p&gt;

&lt;h2&gt;
  
  
  One container, many tests: xUnit v3 fixtures
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkehk5x7zdevlqij4lg1k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkehk5x7zdevlqij4lg1k.png" alt="Test project, Testcontainers, Azurite container and the function code" width="799" height="136"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Starting a container takes seconds, and the tests themselves take milliseconds, so the real decision is how many containers you start. xUnit v3 gives you three places to put one:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A &lt;strong&gt;class fixture&lt;/strong&gt; (&lt;code&gt;IClassFixture&amp;lt;T&amp;gt;&lt;/code&gt;) is created once per test class. Every class that touches storage pays for its own container.&lt;/li&gt;
&lt;li&gt;A &lt;strong&gt;collection fixture&lt;/strong&gt; is shared by every class in a &lt;code&gt;[Collection]&lt;/code&gt;. One container, but "tests within a single test collection will not be run in parallel against each other" (&lt;a href="https://xunit.net/docs/running-tests-in-parallel" rel="noopener noreferrer"&gt;xUnit docs&lt;/a&gt;), so you trade the container cost for parallelism.&lt;/li&gt;
&lt;li&gt;An &lt;strong&gt;assembly fixture&lt;/strong&gt;, new in v3, is created once for the whole test assembly and shared by every test, with parallelism left as it is.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The sample uses the assembly fixture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assembly&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;AssemblyFixture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;typeof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;namespace&lt;/span&gt; &lt;span class="nc"&gt;OrderPipelineDemo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Tests&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IAsyncLifetime&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;AzuriteContainer&lt;/span&gt; &lt;span class="n"&gt;_azurite&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;AzuriteBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"mcr.microsoft.com/azure-storage/azurite:3.37.0"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithInMemoryPersistence&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="c1"&gt;// Azure.Storage.Blobs 12.30 and Queues 12.28 send API version 2026-10-06; Azurite 3.37.0 stops at 2026-06-06.&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WithCommand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"--skipApiVersionCheck"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;_azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// Lowercase hex, so it's valid for queue and container names.&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;UniqueName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;prefix&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; $&lt;span class="s2"&gt;"{prefix}-{Guid.NewGuid():N}"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;ValueTask&lt;/span&gt; &lt;span class="nc"&gt;InitializeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;StartAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;ValueTask&lt;/span&gt; &lt;span class="nc"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;_azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are coming from xUnit 2, two things changed in &lt;code&gt;IAsyncLifetime&lt;/code&gt;: &lt;code&gt;InitializeAsync&lt;/code&gt; and &lt;code&gt;DisposeAsync&lt;/code&gt; return &lt;code&gt;ValueTask&lt;/code&gt; instead of &lt;code&gt;Task&lt;/code&gt;, and the interface now inherits &lt;code&gt;IAsyncDisposable&lt;/code&gt;. A class that implements it without being &lt;code&gt;sealed&lt;/code&gt; gets CA1816 from the .NET analyzers, which wants &lt;code&gt;GC.SuppressFinalize&lt;/code&gt; in &lt;code&gt;DisposeAsync&lt;/code&gt;; sealing the fixture is the shorter fix.&lt;/p&gt;

&lt;p&gt;A test class asks for the fixture in its constructor, the same way it would ask for a class fixture:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessorStorageTests&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt; &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One shared container means the isolation between tests has to come from the data. A storage test that needs its own blob container gets a name from &lt;code&gt;UniqueName&lt;/code&gt;, such as &lt;code&gt;invoices-3f2a9c...&lt;/code&gt;. &lt;code&gt;Guid.ToString("N")&lt;/code&gt; is 32 lowercase hex characters, so the name passes the lowercase rule from bug three and stays well under the 63-character limit. The round-trip tests can't do that, because the queue name is fixed in the trigger attribute; they share &lt;code&gt;orders&lt;/code&gt; and &lt;code&gt;invoices&lt;/code&gt; and stay apart through a unique order ID per test. Nothing gets cleaned up between tests, because the container is gone at the end of the run.&lt;/p&gt;

&lt;p&gt;The round-trip test needs a second fixture on top: the Functions host. In v3 a class fixture &lt;a href="https://github.com/xunit/xunit/blob/main/src/xunit.v3.core/IClassFixture.cs" rel="noopener noreferrer"&gt;can take assembly and collection fixtures&lt;/a&gt; as constructor parameters, so &lt;code&gt;FuncHostFixture(AzuriteFixture azurite)&lt;/code&gt; points &lt;code&gt;func start&lt;/code&gt; at the same Azurite instance the tests write to. That fixture and the test that uses it are the next two sections.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the function class against real storage
&lt;/h2&gt;

&lt;p&gt;The fast half of the suite skips the host entirely. It builds &lt;code&gt;OrderProcessor&lt;/code&gt; by hand, with a real &lt;code&gt;BlobContainerClient&lt;/code&gt; pointed at Azurite, and calls &lt;code&gt;Run&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessorStorageTests&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt; &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt; &lt;span class="nc"&gt;PaidOrder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"A-42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"c-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;99.50m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Run_writes_the_invoice_into_a_container_that_does_not_exist_yet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UniqueName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"invoices"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NullLogger&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaidOrder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"order-A-42.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;DownloadContentAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;99.50m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;blob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Content&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToObjectFromJson&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Invoice&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Run_fails_on_an_uppercase_container_name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Invoices"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NullLogger&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;OrderProcessor&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Instance&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ThrowsAsync&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;RequestFailedException&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;processor&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;PaidOrder&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Equal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"InvalidResourceName"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ErrorCode&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first test is the one that matters day to day. The container name is new for every run, so the storage starts out without it, like a fresh environment. Delete &lt;code&gt;CreateIfNotExistsAsync&lt;/code&gt; from &lt;code&gt;Run&lt;/code&gt; and the test fails with &lt;code&gt;ContainerNotFound&lt;/code&gt;. Change the blob name to &lt;code&gt;Order-{order.Id}.json&lt;/code&gt; and the upload succeeds, but &lt;code&gt;DownloadContentAsync("order-A-42.json")&lt;/code&gt; gets a 404. The test reads the blob back under the name its consumer uses, which is the only way to catch the casing half of bug three. Reading the amount back also proves the invoice is valid JSON in the shape the reader expects.&lt;/p&gt;

&lt;p&gt;The second test pins the container rule. It asserts on &lt;code&gt;ErrorCode&lt;/code&gt;, not on the exception message, for a reason that comes up again in the gotchas: Azurite's status codes and error codes match Azure Storage, its messages don't always.&lt;/p&gt;

&lt;p&gt;Both tests take milliseconds once the container is up. What they can't see is everything before &lt;code&gt;Run&lt;/code&gt;: they hand the method a finished &lt;code&gt;Order&lt;/code&gt;, so the Base64 decoding and the enum binding never happen. Bugs one and four stay green here.&lt;/p&gt;

&lt;h2&gt;
  
  
  The full round trip: enqueue, wait for the blob
&lt;/h2&gt;

&lt;p&gt;To get the trigger and the worker into the test, the test has to run the Functions host. There is no in-process test host for the isolated worker; the request for a TestServer-style host (&lt;a href="https://github.com/Azure/azure-functions-dotnet-worker/issues/1196" rel="noopener noreferrer"&gt;azure-functions-dotnet-worker #1196&lt;/a&gt;) was closed as not planned. So the fixture starts &lt;code&gt;func start&lt;/code&gt; as a child process, the same way the &lt;a href="https://dev.to/martin_oehlert/testing-azure-functions-unit-integration-and-local-1cml"&gt;unit testing article&lt;/a&gt; did for an HTTP function. Trimmed to the parts that matter:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;FuncHostFixture&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt; &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IAsyncLifetime&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="nc"&gt;Process&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;_func&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;ValueTask&lt;/span&gt; &lt;span class="nc"&gt;InitializeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nc"&gt;CoreToolsInstalled&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueueClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;startInfo&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ProcessStartInfo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"func"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; $&lt;span class="s2"&gt;"start --port {FreeTcpPort()}"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nc"&gt;WorkingDirectory&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetFullPath&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Combine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AppContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BaseDirectory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"../../../../OrderPipelineDemo"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;RedirectStandardOutput&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;UseShellExecute&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;startInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"AzureWebJobsStorage"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;startInfo&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"FUNCTIONS_WORKER_RUNTIME"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"dotnet-isolated"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ready&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TaskCompletionSource&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_func&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;Process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Start&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;startInfo&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;OutputDataReceived&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Data&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Worker process started and initialized"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringComparison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="n"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TrySetResult&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_func&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;BeginOutputReadLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// func start builds the app first, so allow for a cold build.&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;ready&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;WaitAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="nc"&gt;ValueTask&lt;/span&gt; &lt;span class="nc"&gt;DisposeAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;_func&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Kill&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;entireProcessTree&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;_func&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Dispose&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nc"&gt;ValueTask&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CompletedTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three details in that fixture matter. &lt;code&gt;AzureWebJobsStorage&lt;/code&gt; is set on the process, so the host and the &lt;code&gt;BlobContainerClient&lt;/code&gt; registered in &lt;code&gt;Program.cs&lt;/code&gt; both talk to the test's Azurite container instead of whatever &lt;code&gt;local.settings.json&lt;/code&gt; says. The fixture waits for the line "Worker process started and initialized" on stdout, because a host that has started but has no worker yet would leave the first message sitting on the queue. And &lt;code&gt;DisposeAsync&lt;/code&gt; kills the whole process tree: &lt;code&gt;func&lt;/code&gt; starts the worker as a separate process, and killing only the parent leaves a .NET process running after the tests finish.&lt;/p&gt;

&lt;p&gt;The test itself is short:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;OrderRoundTripTests&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;AzuriteFixture&lt;/span&gt; &lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nc"&gt;IClassFixture&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;FuncHostFixture&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nc"&gt;NoCoreTools&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Azure Functions Core Tools (func) is not on PATH"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Placed_order_comes_out_as_an_invoice_blob&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SkipUnless&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FuncHostFixture&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CoreToolsInstalled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NoCoreTools&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"N"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"c-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;99.50m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;BlobContainerClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"invoices"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;queue&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;OrderQueue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Create&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlaceAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;invoices&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetBlobClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"order-{order.Id}.json"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;WaitUntilAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;invoice&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;30&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;OrderQueue.Create&lt;/code&gt; and &lt;code&gt;OrderApi&lt;/code&gt; are the classes the API uses, not test doubles, so the message on the queue has the encoding and the JSON that production sends. Take the Base64 option out of &lt;code&gt;OrderQueue.Create&lt;/code&gt;, or the converter off &lt;code&gt;OrderStatus&lt;/code&gt;, and this test fails with a &lt;code&gt;TimeoutException&lt;/code&gt; after 30 seconds. Put them back and it passes well inside the deadline.&lt;/p&gt;

&lt;p&gt;There is no &lt;code&gt;Task.Delay(5000)&lt;/code&gt; followed by an assert. The host polls the queue on its own schedule, and in local development that interval backs off to at most two seconds (&lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-bindings-storage-queue-trigger" rel="noopener noreferrer"&gt;queue trigger docs&lt;/a&gt;), so a fixed sleep is either too short on a slow agent or wastes time on a fast one. &lt;code&gt;WaitUntilAsync&lt;/code&gt; checks every 250 ms and gives up at a deadline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Poll&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;WaitUntilAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Response&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="nc"&gt;WaitUntilAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;WaitUntilAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Func&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TimeSpan&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UtcNow&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;timeout&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;condition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;DateTime&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;UtcNow&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;deadline&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;TimeoutException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;$&lt;span class="s2"&gt;"Condition not met within {timeout}."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

            &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Delay&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromMilliseconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;250&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first overload exists because &lt;code&gt;ExistsAsync&lt;/code&gt; returns &lt;code&gt;Response&amp;lt;bool&amp;gt;&lt;/code&gt;, which converts to &lt;code&gt;bool&lt;/code&gt; but doesn't fit a &lt;code&gt;Func&amp;lt;Task&amp;lt;bool&amp;gt;&amp;gt;&lt;/code&gt;. The delay takes the test's cancellation token, so a cancelled run stops polling right away instead of sitting out the 30 seconds.&lt;/p&gt;

&lt;p&gt;The second round-trip test proves the failure path instead of assuming it. It sends the same order with a plain &lt;code&gt;QueueClient&lt;/code&gt;, the SDK default, and waits for it in the poison queue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nc"&gt;Fact&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nc"&gt;Task&lt;/span&gt; &lt;span class="nc"&gt;Plain_text_message_ends_up_in_the_poison_queue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nc"&gt;Assert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;SkipUnless&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;FuncHostFixture&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CoreToolsInstalled&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;NoCoreTools&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TestContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Current&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CancellationToken&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nc"&gt;Guid&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;NewGuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"N"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"c-7"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;99.50m&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Paid&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;poison&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueueClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"orders-poison"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;poison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;CreateIfNotExistsAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="c1"&gt;// The SDK default: MessageEncoding.None, so the trigger receives plain text.&lt;/span&gt;
        &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="n"&gt;plainText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;QueueClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;azurite&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;GetConnectionString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;OrderApi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;plainText&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PlaceAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nc"&gt;WaitUntilAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;poison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;PeekMessagesAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ct&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;m&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;m&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;ToString&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;StringComparison&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;Ordinal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nc"&gt;TimeSpan&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;FromSeconds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Locally, the message reaches &lt;code&gt;orders-poison&lt;/code&gt; in well under a second; the 60-second deadline is headroom for a slow CI agent. The test pins down the behaviour from bug one, and it turns red the day someone sets &lt;code&gt;"messageEncoding": "none"&lt;/code&gt; in &lt;code&gt;host.json&lt;/code&gt;, and that is the day every Base64 producer needs a second look.&lt;/p&gt;

&lt;p&gt;Both round-trip tests start with &lt;code&gt;Assert.SkipUnless&lt;/code&gt;, the dynamic skip that is new in xUnit v3. Without Core Tools on the &lt;code&gt;PATH&lt;/code&gt;, the fixture does nothing, the two tests show up as skipped with the reason, and the other four still run. A contributor without &lt;code&gt;func&lt;/code&gt; gets a green run with two visible skips instead of a 90-second timeout.&lt;/p&gt;

&lt;h2&gt;
  
  
  Gotchas
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Startup time is the container, not the tests.&lt;/strong&gt; The whole run, six tests including both trips through &lt;code&gt;func start&lt;/code&gt;, takes about seven seconds on my machine with the image already pulled and the function app already built. The first run on a new machine pays for the image pull, and the first &lt;code&gt;func start&lt;/code&gt; builds the function app, which is why the fixture allows 90 seconds before it gives up. On a CI agent every run is a first run unless you cache.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;One assembly fixture, but the host is per class.&lt;/strong&gt; &lt;code&gt;AzuriteFixture&lt;/code&gt; is created once for the assembly. &lt;code&gt;FuncHostFixture&lt;/code&gt; is a class fixture, so if the round-trip tests get split across two classes, two &lt;code&gt;func&lt;/code&gt; processes start against the same &lt;code&gt;orders&lt;/code&gt; queue. Each message then goes to whichever host polls first. The tests still pass, since they look for their own order ID, but you pay for a second host start and lose any clue which host processed what. Keep the round-trip tests in one class, or move the host to an assembly fixture too. Inside that one class, xUnit runs the tests one after another (a class is its own test collection by default), which is what you want when two tests share one queue and one host.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ports.&lt;/strong&gt; Azurite's ports are random, but the &lt;code&gt;func&lt;/code&gt; host needs one too, and its default is 7071, the same port the &lt;code&gt;func start&lt;/code&gt; in your other terminal is probably using. &lt;code&gt;FreeTcpPort&lt;/code&gt; asks the OS for an unused one. There is a small window between releasing that port and &lt;code&gt;func&lt;/code&gt; binding it; I've never hit it, but it is a race, not a guarantee.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The API version check comes back with every SDK update.&lt;/strong&gt; The &lt;code&gt;--skipApiVersionCheck&lt;/code&gt; flag from earlier hides a real mismatch: the SDK speaks a newer storage service version than Azurite knows. Today that's harmless for blobs and queues. To find out when the flag can go, remove it after each Azurite release and run the suite; if the tests pass without it, Azurite has caught up.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What Azurite doesn't emulate.&lt;/strong&gt; The &lt;a href="https://learn.microsoft.com/azure/storage/common/storage-use-azurite#differences-between-azurite-and-azure-storage" rel="noopener noreferrer"&gt;Azurite docs&lt;/a&gt; list the differences. Three matter for tests like these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Only Blob, Queue and Table. Azure Files and Data Lake Storage Gen2 aren't there.&lt;/li&gt;
&lt;li&gt;No scale or performance. Azurite "doesn't support large numbers of connected clients" and gives "no performance guarantee", so throttling and timeouts under load are Part 5's job, not this suite's.&lt;/li&gt;
&lt;li&gt;Error messages can differ while status codes match, which is why the uppercase test checks &lt;code&gt;ErrorCode&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tests also authenticate with the emulator's well-known account key. A function that uses a managed identity in production has role assignments that no test here ever checks; the locked-down identity from bug two that can't create containers only shows up in a deployed environment.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Colima and other non-default Docker sockets.&lt;/strong&gt; On a Mac with Colima, &lt;code&gt;DOCKER_HOST&lt;/code&gt; points at a socket under your home folder. Testcontainers starts its cleanup container, Ryuk, with that path mounted, and Docker inside the Colima VM can't find it: the run fails with "invalid mount config for type bind". Setting &lt;code&gt;TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE=/var/run/docker.sock&lt;/code&gt; tells Testcontainers the socket path inside the VM, and the run goes through. Docker Desktop and the CI runners don't need it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Running it in CI
&lt;/h2&gt;

&lt;p&gt;GitHub Actions &lt;code&gt;ubuntu-latest&lt;/code&gt; runners ship with Docker, so the Azurite tests run there with no extra setup: Testcontainers finds the daemon, pulls the image and maps the ports. The round-trip tests are the ones with a decision attached, because the runner has no Core Tools.&lt;/p&gt;

&lt;p&gt;The companion repo installs them in the job, so all six tests run. This is the whole workflow, &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/orderpipeline-tests.yml" rel="noopener noreferrer"&gt;&lt;code&gt;orderpipeline-tests.yml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;OrderPipelineDemo tests&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'OrderPipelineDemo/**'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'OrderPipelineDemo.Tests/**'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'Directory.Build.props'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'Directory.Packages.props'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'global.json'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'.github/workflows/orderpipeline-tests.yml'&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'OrderPipelineDemo/**'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'OrderPipelineDemo.Tests/**'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'Directory.Build.props'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'Directory.Packages.props'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'global.json'&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="s1"&gt;'.github/workflows/orderpipeline-tests.yml'&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v7&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/setup-dotnet@v6&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;global-json-file&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;global.json&lt;/span&gt;

      &lt;span class="c1"&gt;# Without Core Tools the two func start round-trip tests skip instead of running.
&lt;/span&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npm install -g azure-functions-core-tools@4 --unsafe-perm true&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dotnet test --project OrderPipelineDemo.Tests&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The paths filter keeps it from running on changes to the other samples in the repo, but it still fires when the shared build files change, since a package bump in &lt;code&gt;Directory.Packages.props&lt;/code&gt; is the kind of change these tests exist for.&lt;/p&gt;

&lt;p&gt;Leave the Core Tools step out and &lt;code&gt;Assert.SkipUnless&lt;/code&gt; reports the two round-trip tests as skipped and the four storage tests still guard the container and naming bugs. That is a reasonable trade for a pull request build, as long as some pipeline runs the round trip before a release, because the skipped tests are the only ones that catch the encoding and the enum.&lt;/p&gt;

&lt;p&gt;Two more points before this goes into a real pipeline. &lt;code&gt;dotnet test&lt;/code&gt; only works here because &lt;code&gt;global.json&lt;/code&gt; selects Microsoft.Testing.Platform; a runner with an older SDK than the one in &lt;code&gt;global.json&lt;/code&gt; fails before any test runs, which &lt;code&gt;setup-dotnet&lt;/code&gt; with &lt;code&gt;global-json-file&lt;/code&gt; prevents. And the sample keeps the mocked tests in the same project as the container tests for brevity. In a real code base, put the Docker-dependent tests in their own project, so the unit tests still run on a machine without Docker.&lt;/p&gt;

&lt;p&gt;Caching the Azurite image between runs, splitting slow tests from fast ones, and dealing with the flaky test that a shared queue eventually produces are Part 6 of this series, "Tests in CI".&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Each of the four bugs sits at a boundary the code under test doesn't own. The SDK's default encoding, the trigger's expectations, the storage naming rules and the worker's JSON settings are all decided somewhere else, and a mock replaces exactly that somewhere else with something that agrees with you. Mocks stay the right tool for the logic in your own classes. For the contract with the storage service and the Functions host, a container that starts once per test run costs a few seconds and answers questions a mock can't.&lt;/p&gt;

&lt;p&gt;If you only add one test from this article, add the round trip. The storage tests catch two bugs that also fail loudly in the first deployment; the round trip catches the two that fail quietly, with a full poison queue and a log line about dequeue counts.&lt;/p&gt;

&lt;p&gt;Part 2 does the same for Cosmos DB and Service Bus, where the emulators are heavier, slower to start and further from the real service than Azurite.&lt;/p&gt;

&lt;p&gt;Does your test suite ever put a real message on a real queue, or does every queue in it come from &lt;code&gt;Substitute.For&lt;/code&gt;?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>dotnet</category>
      <category>testing</category>
      <category>azurefunctions</category>
    </item>
    <item>
      <title>Azure API Management CI/CD: APIOps Pipelines with GitHub Actions</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 13 Nov 2026 07:11:13 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-api-management-cicd-apiops-pipelines-with-github-actions-ajk</link>
      <guid>https://dev.to/martin_oehlert/azure-api-management-cicd-apiops-pipelines-with-github-actions-ajk</guid>
      <description>&lt;p&gt;What has to pass before a merged pull request may change the production API Management instance without anyone opening the portal? Part 5's publish workflow already ran a dry run on every pull request and published on merge, but nothing required the dry run to pass, it signed in with the same identity that published to dev, and nothing read the spec or the policies before the CLI did. A pipeline you can trust with prod needs four gates, each catching something the others can't: checks that need no Azure at all, a dry run that can only read, a publish to dev that API Management itself validates, and a person who approves prod.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt; keeps Part 5's layout: &lt;code&gt;apiops/&lt;/code&gt; holds the artifact tree, the extract filter and &lt;code&gt;configuration.prod.yaml&lt;/code&gt;, and the APIOps CLI is still pinned at &lt;code&gt;@azure-tools/apiops-cli@1.0.5&lt;/code&gt;. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-publish.yml" rel="noopener noreferrer"&gt;publish workflow&lt;/a&gt; is what changes. The dry run becomes a required check that runs on every pull request and can only read, dev gets the merged commit, prod gets it after an approval, and a manual run publishes the full tree when prod has fallen behind. Each stage signs in through OIDC with its own user-assigned managed identity, so the repository holds no Azure secret. As in Part 5, nothing is deployed. Both workflows pass actionlint, the three &lt;code&gt;validate&lt;/code&gt; steps ran locally against the sample, the claim that the dry run only reads comes from the CLI's 1.0.5 source, and no workflow has run on GitHub or exchanged a token with Entra ID. Where a step depends on how GitHub or Azure behaves at run time, I link the documentation it rests on.&lt;/p&gt;

&lt;h2&gt;
  
  
  From a local change to production
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnq1hyyb5ap45lmg68hgh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnq1hyyb5ap45lmg68hgh.png" alt="The APIOps pipeline for the order API: pull request checks, publish to dev on merge, approval, publish to prod" width="800" height="737"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A change starts on a branch that edits something under &lt;code&gt;ApimOrdersDemo/apiops/&lt;/code&gt;. Its pull request gets two checks. &lt;code&gt;validate&lt;/code&gt; lints the specs, checks the policy files and compares each spec with the base branch, without signing in to Azure. &lt;code&gt;dry-run&lt;/code&gt; signs in as &lt;code&gt;id-apiops-plan&lt;/code&gt;, which can only read, and plans the change against dev, then against prod with the prod overrides. Both are required, so a merge waits for them. The merge lands one commit on &lt;code&gt;main&lt;/code&gt;. &lt;code&gt;publish-dev&lt;/code&gt; publishes that commit to dev as &lt;code&gt;id-apiops-dev&lt;/code&gt;, then &lt;code&gt;publish-prod&lt;/code&gt; waits in the &lt;code&gt;prod&lt;/code&gt; environment until a reviewer approves and publishes the same commit to prod as &lt;code&gt;id-apiops-prod&lt;/code&gt;. The nightly extract from Part 5 keeps running on the side and turns portal edits into drift pull requests, which pass through the same two checks as every other change.&lt;/p&gt;

&lt;p&gt;The rule behind the identities: only a job running on &lt;code&gt;main&lt;/code&gt; can reach one that writes.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-publish.yml" rel="noopener noreferrer"&gt;workflow&lt;/a&gt; is about 200 lines, most of them checkout, Node setup and CLI flags. Here is its job graph, with steps, runners, permissions and concurrency left out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'pull_request'&lt;/span&gt;

  &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;      &lt;span class="c1"&gt;# required check, no Azure sign-in
&lt;/span&gt;    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;changes&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;needs.changes.outputs.validate == 'true'&lt;/span&gt;

  &lt;span class="na"&gt;dry-run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;       &lt;span class="c1"&gt;# required check, id-apiops-plan (Reader), no environment
&lt;/span&gt;    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;changes&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;needs.changes.outputs.apiops == 'true'&lt;/span&gt;

  &lt;span class="na"&gt;publish-dev&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;   &lt;span class="c1"&gt;# id-apiops-dev
&lt;/span&gt;    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name != 'pull_request'&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dev&lt;/span&gt;

  &lt;span class="na"&gt;publish-prod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;  &lt;span class="c1"&gt;# id-apiops-prod, after a reviewer approves
&lt;/span&gt;    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;publish-dev&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a pull request, the run takes &lt;code&gt;changes&lt;/code&gt; and then &lt;code&gt;validate&lt;/code&gt; and &lt;code&gt;dry-run&lt;/code&gt; side by side. On a push to &lt;code&gt;main&lt;/code&gt; or a manual run, it takes &lt;code&gt;publish-dev&lt;/code&gt; and then &lt;code&gt;publish-prod&lt;/code&gt;. Every job has an &lt;code&gt;if:&lt;/code&gt; or a &lt;code&gt;needs:&lt;/code&gt; that ties it to one of the two paths, so no run does both. The sections below show the parts of each job that matter.&lt;/p&gt;

&lt;h2&gt;
  
  
  Triggers: pull requests, pushes to main, and a manual full publish
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# No paths filter on pull_request: a required check from a path-filtered workflow stays Pending
&lt;/span&gt;  &lt;span class="c1"&gt;# on every PR that doesn't match. The changes job decides instead, and a skipped job counts as passed.
&lt;/span&gt;  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;main&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'ApimOrdersDemo/apiops/**'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="c1"&gt;# Full publish without --commit-id, to reconcile prod after a rejected or cancelled run.
&lt;/span&gt;  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pull_request&lt;/code&gt; has no &lt;code&gt;paths&lt;/code&gt; filter, on purpose. GitHub's &lt;a href="https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax" rel="noopener noreferrer"&gt;workflow syntax reference&lt;/a&gt; spells out what a path filter does to a required check: when a workflow is skipped by path filtering, its checks "will remain in a 'Pending' state", and a pull request that requires them "will be blocked from merging." The samples repo has two dozen folders next to &lt;code&gt;ApimOrdersDemo&lt;/code&gt;. With Part 5's &lt;code&gt;paths: ['ApimOrdersDemo/apiops/**']&lt;/code&gt; and &lt;code&gt;dry-run&lt;/code&gt; marked as required, every pull request that touched only a Functions demo would wait forever for a check that never starts.&lt;/p&gt;

&lt;p&gt;So the workflow starts on every pull request and decides inside. A &lt;a href="https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-jobs-with-conditions" rel="noopener noreferrer"&gt;skipped job reports Success&lt;/a&gt;, even when it is a required check, which makes a job-level &lt;code&gt;if:&lt;/code&gt; the answer: green for pull requests that don't touch &lt;code&gt;apiops/&lt;/code&gt;, a real dry run for those that do. The &lt;code&gt;changes&lt;/code&gt; job computes it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="na"&gt;changes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'pull_request'&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;apiops&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.diff.outputs.apiops }}&lt;/span&gt;
      &lt;span class="na"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ steps.diff.outputs.validate }}&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# A change to the policy script alone runs validate against the unchanged artifacts. It plans
&lt;/span&gt;      &lt;span class="c1"&gt;# nothing, so dry-run stays skipped.
&lt;/span&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;diff&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;changed() { if git diff --quiet HEAD~1 HEAD -- "$@"; then echo false; else echo true; fi; }&lt;/span&gt;
          &lt;span class="s"&gt;echo "apiops=$(changed ApimOrdersDemo/apiops)" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;
          &lt;span class="s"&gt;echo "validate=$(changed ApimOrdersDemo/apiops ApimOrdersDemo/scripts/check-policies.mjs)" &amp;gt;&amp;gt; "$GITHUB_OUTPUT"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a pull request, &lt;code&gt;actions/checkout&lt;/code&gt; checks out the merge commit GitHub builds for it, and that commit's first parent is the tip of the base branch. &lt;code&gt;HEAD~1..HEAD&lt;/code&gt; is everything the pull request changes. It's also the range &lt;code&gt;--commit-id&lt;/code&gt; diffs in the dry run (Part 5: &lt;code&gt;&amp;lt;sha&amp;gt;~1&lt;/code&gt; against &lt;code&gt;&amp;lt;sha&amp;gt;&lt;/code&gt;), so the two can't disagree about whether &lt;code&gt;apiops/&lt;/code&gt; changed, and a checkout with &lt;code&gt;fetch-depth: 2&lt;/code&gt; is all the history either needs. A paths-filter action from the Marketplace does the same with more options, but a &lt;code&gt;git diff --quiet&lt;/code&gt; doesn't add a third-party action to a workflow that signs in to Azure. The price is a runner start, a few seconds, on every pull request in the repository.&lt;/p&gt;

&lt;p&gt;There are two outputs because the two checks read different files. &lt;code&gt;dry-run&lt;/code&gt; plans the artifacts, so &lt;code&gt;apiops/&lt;/code&gt; is all it cares about. &lt;code&gt;validate&lt;/code&gt; also runs &lt;code&gt;scripts/check-policies.mjs&lt;/code&gt;, which lives outside &lt;code&gt;apiops/&lt;/code&gt;, and with one output a pull request that changed only the script would merge without the new script running once. That pull request now gets &lt;code&gt;validate&lt;/code&gt; against the unchanged artifacts and a skipped &lt;code&gt;dry-run&lt;/code&gt;, which would have nothing to plan.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;push&lt;/code&gt; keeps its path filter. Nothing requires a check on a push, so a push that doesn't touch &lt;code&gt;apiops/&lt;/code&gt; can skip the whole workflow. Per-commit publishing still assumes one commit per merge: a rebase merge of three commits lands three commits on &lt;code&gt;main&lt;/code&gt;, and the run publishes only the last one. Allow merge commits or squash merges in the repository settings and turn rebase merging off.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;workflow_dispatch&lt;/code&gt; takes no inputs. A manual run follows the same &lt;code&gt;publish-dev&lt;/code&gt; and &lt;code&gt;publish-prod&lt;/code&gt; path as a push, with one difference in the publish command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;          &lt;span class="s"&gt;${{ github.event_name == 'push' &amp;amp;&amp;amp; format('--commit-id {0}', github.sha) || '' }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a push, the expression becomes &lt;code&gt;--commit-id &amp;lt;sha&amp;gt;&lt;/code&gt;. On a manual run it's empty, and the CLI publishes the full tree. That's the reconcile path. When a reviewer rejects a prod approval or a waiting run gets cancelled, that commit's change never reaches prod, and the next per-commit run only publishes its own diff. A full publish PUTs every artifact (Part 5: safe to re-run, not free) and brings prod back to what &lt;code&gt;main&lt;/code&gt; says. Start it from &lt;code&gt;main&lt;/code&gt;: the &lt;code&gt;dev&lt;/code&gt; and &lt;code&gt;prod&lt;/code&gt; environments only accept the &lt;code&gt;main&lt;/code&gt; branch, so a manual run from anywhere else fails at &lt;code&gt;publish-dev&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validation that needs no Azure
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;validate&lt;/code&gt; has no &lt;code&gt;permissions&lt;/code&gt; block, so it gets the workflow's &lt;code&gt;contents: read&lt;/code&gt; and no &lt;code&gt;id-token&lt;/code&gt;. It couldn't sign in to Azure if it tried, which also makes it the one check that passes on a fork's pull request. It needs &lt;code&gt;changes&lt;/code&gt; like &lt;code&gt;dry-run&lt;/code&gt; does but reads its own output, so both start when &lt;code&gt;apiops/&lt;/code&gt; changed, &lt;code&gt;validate&lt;/code&gt; alone starts when only the policy script did, and both count as passed when neither changed. After checkout (&lt;code&gt;fetch-depth: 2&lt;/code&gt;, which gives it the base version of each spec) and Node setup, it runs three steps from &lt;code&gt;ApimOrdersDemo/apiops&lt;/code&gt;, like every job that touches the artifacts. Each one reads what is inside a file, which the dry run never does: it plans calls, and a valid policy plans the same &lt;code&gt;PUT&lt;/code&gt; as a broken one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Linting the OpenAPI specs
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Lint the OpenAPI specs&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;npx --yes @stoplight/spectral-cli@6.17.1 lint --ruleset .spectral.yaml 'apim-artifacts/apis/*/specification.yaml'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/stoplightio/spectral" rel="noopener noreferrer"&gt;Spectral&lt;/a&gt; is pinned like the CLI, and the glob is quoted so Spectral expands it instead of the shell. The ruleset sits next to the artifacts in &lt;code&gt;apiops/.spectral.yaml&lt;/code&gt;, so editing it is a change under &lt;code&gt;apiops/&lt;/code&gt; and runs the check that uses it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;extends&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;spectral:oas&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;recommended&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="na"&gt;rules&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# API Management names each operation after its operationId, and operations/&amp;lt;name&amp;gt;/policy.xml hangs off
&lt;/span&gt;  &lt;span class="c1"&gt;# that name. Without one, the import generates a name from method and path.
&lt;/span&gt;  &lt;span class="na"&gt;operation-operationId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;error&lt;/span&gt;
  &lt;span class="c1"&gt;# Partners find the contact in the developer portal, not in the spec.
&lt;/span&gt;  &lt;span class="na"&gt;info-contact&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;off&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two edits fit &lt;code&gt;spectral:oas&lt;/code&gt; to API Management. &lt;code&gt;operation-operationId&lt;/code&gt; goes from warning to error, because the import &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-api-import-restrictions" rel="noopener noreferrer"&gt;names each operation after its &lt;code&gt;operationId&lt;/code&gt;&lt;/a&gt; and the operation policies in this repo hang off that name: &lt;code&gt;apis/orders/operations/get-order/policy.xml&lt;/code&gt; belongs to whatever operation is called &lt;code&gt;get-order&lt;/code&gt;. On the sample the step reports 0 errors and 8 warnings (six missing &lt;code&gt;tags&lt;/code&gt;, and &lt;code&gt;get-order&lt;/code&gt; has no &lt;code&gt;description&lt;/code&gt; in either version), and warnings don't fail it. Delete &lt;code&gt;operationId: get-order&lt;/code&gt; from the v1 spec, and it does:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  59:9    error  operation-operationId  Operation must have "operationId".                             paths./orders/{orderId}.get
✖ 5 problems (1 error, 4 warnings, 0 infos, 0 hints)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: the linter has to know where the gateway enforces security.&lt;/strong&gt; &lt;a href="https://github.com/Redocly/redocly-cli" rel="noopener noreferrer"&gt;Redocly CLI&lt;/a&gt; 2.76.0 with its recommended config fails both specs with six errors, one &lt;code&gt;security-defined&lt;/code&gt; per operation, because neither spec declares a security scheme. That's deliberate: the subscription key and the Entra token are checked in policy (Parts 2 and 3), not described in the spec. Turn the rule off in &lt;code&gt;redocly.yaml&lt;/code&gt;, or declare the key header and the bearer scheme in the spec so the developer portal shows them too. Spectral's &lt;code&gt;oas&lt;/code&gt; rules only check that a scheme an operation references exists, so they stay quiet.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  Checking policies when they aren't quite XML
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apis/orders/policy.xml:27: parser error : attributes construct error
      &amp;lt;when condition="@(context.Request.Method == "POST")"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's &lt;code&gt;xmllint --noout&lt;/code&gt; on a policy API Management accepts. For XML, the quote before &lt;code&gt;POST&lt;/code&gt; ends the attribute. API Management doesn't mind, because the CLI sends policies as &lt;code&gt;rawxml&lt;/code&gt;, which the &lt;a href="https://learn.microsoft.com/javascript/api/@azure/arm-apimanagement/knownpolicycontentformat" rel="noopener noreferrer"&gt;ARM API calls&lt;/a&gt; "a non XML encoded policy document". The next tool to reach for would be a schema, and there isn't one: I found no official XSD for policies on Learn, in the VS Code extension or in the policy snippets repo. So the check is a &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/scripts/check-policies.mjs" rel="noopener noreferrer"&gt;script&lt;/a&gt; of about 140 lines, Node built-ins only. It's JavaScript because the job already has Node for &lt;code&gt;npx&lt;/code&gt;. The script never runs the C# in the expressions; it only finds where each one starts and ends.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Check the policies&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;node ../scripts/check-policies.mjs apim-artifacts&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It blanks every policy expression and parses what's left as XML. It then requires one &lt;code&gt;inbound&lt;/code&gt;, &lt;code&gt;backend&lt;/code&gt;, &lt;code&gt;outbound&lt;/code&gt; and &lt;code&gt;on-error&lt;/code&gt; section in every API, operation and product policy, each with a &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; directly inside, and compares &lt;code&gt;apis/orders/policy.xml&lt;/code&gt; with &lt;code&gt;apis/orders-v2/policy.xml&lt;/code&gt; byte for byte. The blanking is what makes the parse possible:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Expressions are C#, and policies travel as rawxml, so condition="@(x == "POST")" is a valid policy&lt;/span&gt;
&lt;span class="c1"&gt;// and invalid XML. Replace each @(...) and @{...} with spaces, keeping line breaks for line numbers.&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;blankExpressions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;close&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'@'&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;'('&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;')'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'{'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'}'&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;close&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="k"&gt;continue&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;length&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s1"&gt;'"'&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="s2"&gt;"'"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;skipLiteral&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;depth&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;
      &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="n"&gt;close&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="n"&gt;depth&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;PolicyError&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'unclosed policy expression'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;out&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;src&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;^&lt;/span&gt;\&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;end&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;out&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scan counts brackets and skips C# string and char literals, so a &lt;code&gt;)&lt;/code&gt; inside &lt;code&gt;"..."&lt;/code&gt; doesn't end the expression. Spaces instead of an empty string keep every tag on its original line, which is the line the error message reports.&lt;/p&gt;

&lt;p&gt;On the sample's six policy files it prints &lt;code&gt;6 policy files OK&lt;/code&gt;. On a copy with three typical mistakes, it exits &lt;code&gt;1&lt;/code&gt;: the &lt;code&gt;get-order&lt;/code&gt; operation policy without &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; in &lt;code&gt;inbound&lt;/code&gt;, an unquoted attribute in the partner product's policy, and Part 5's &lt;code&gt;Orders.Read&lt;/code&gt; role added to v1 only:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apis/orders/operations/get-order/policy.xml: &amp;lt;inbound&amp;gt; has no &amp;lt;base /&amp;gt;, so the broader scope's inbound section never runs
products/orders-partners/policy.xml: line 4: malformed markup (unquoted attribute, or &amp;lt; in an attribute value?)
apis/orders/policy.xml: differs from apis/orders-v2/policy.xml; change both
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; rule is the reason the script exists. An operation policy without it skips the product rate limit, the token check and the backend route, and nothing reports an error. In this sample the call reaches the function without the managed identity token or the function key and gets a 401 from the backend instead of the gateway. The comparison is the sample-specific part: replace the pair in &lt;code&gt;MUST_MATCH&lt;/code&gt; with yours, or delete it.&lt;/p&gt;

&lt;p&gt;What the script can't know is which policy elements exist. &lt;code&gt;&amp;lt;rate-limt&amp;gt;&lt;/code&gt; parses and passes, and so does a &lt;code&gt;{{named-value}}&lt;/code&gt; nobody created. Without a schema, only API Management can reject those, and its first chance is the &lt;code&gt;PUT&lt;/code&gt; in &lt;code&gt;publish-dev&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Catching breaking changes before they become a new version
&lt;/h3&gt;

&lt;p&gt;Copy the v2 spec over the v1 spec, commit, and the third step fails:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;1 changes: 1 error, 0 warning, 0 info
error   [response-body-type-changed] at /head/apim-artifacts/apis/orders/specification.yaml
    in API GET /orders
        the response's body `type` changed from `array&amp;lt;object&amp;gt;` to `object` for status `200`
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's Part 4's change: &lt;code&gt;GET /orders&lt;/code&gt; going from a bare array to a page with &lt;code&gt;items&lt;/code&gt; and &lt;code&gt;nextLink&lt;/code&gt;. Part 4 made it a new version for exactly this reason, and now a check says so when someone forgets.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="c1"&gt;# A spec the base branch doesn't have is a new API or version: nothing to break.
&lt;/span&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Breaking changes against the base branch&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;for spec in apim-artifacts/apis/*/specification.yaml; do&lt;/span&gt;
            &lt;span class="s"&gt;if ! git cat-file -e "HEAD~1:./$spec" 2&amp;gt;/dev/null; then&lt;/span&gt;
              &lt;span class="na"&gt;echo "$spec&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;new, skipped"&lt;/span&gt;
              &lt;span class="s"&gt;continue&lt;/span&gt;
            &lt;span class="s"&gt;fi&lt;/span&gt;
            &lt;span class="s"&gt;git show "HEAD~1:./$spec" &amp;gt; "$RUNNER_TEMP/base.yaml"&lt;/span&gt;
            &lt;span class="s"&gt;docker run --rm -v "$PWD:/head:ro" -v "$RUNNER_TEMP:/base:ro" tufin/oasdiff:v1.35.0 \&lt;/span&gt;
              &lt;span class="s"&gt;breaking /base/base.yaml "/head/$spec" --fail-on ERR&lt;/span&gt;
          &lt;span class="s"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/oasdiff/oasdiff" rel="noopener noreferrer"&gt;oasdiff&lt;/a&gt; v1.35.0 runs from its Docker image, pinned to the release, and compares each spec with its version on &lt;code&gt;HEAD~1&lt;/code&gt;, the base branch tip, the same parent &lt;code&gt;changes&lt;/code&gt; diffs against. &lt;code&gt;--fail-on ERR&lt;/code&gt; fails on breaking changes and prints warnings without failing. There's an &lt;code&gt;oasdiff/oasdiff-action&lt;/code&gt; too; when its &lt;code&gt;breaking&lt;/code&gt; action finds changes, it uploads the comparison (encrypted) to oasdiff.com unless you set &lt;code&gt;review: false&lt;/code&gt;. Running the image directly keeps the specs on the runner.&lt;/p&gt;

&lt;p&gt;Skipping new specs is deliberate. A breaking change to a spec that exists on the base branch fails the check, because existing callers depend on it. A spec the base branch doesn't have passes unchecked, because nobody calls it yet: &lt;code&gt;apis/orders-v3/&lt;/code&gt; can take any shape it likes. That's Part 4's rule as a required check: the old contract doesn't change, the new one gets a new version. When breaking v1 really is the plan, because it's past its sunset and the logs show no callers, the check stays red and someone on the ruleset's bypass list merges it, with the reason in the pull request.&lt;/p&gt;

&lt;p&gt;The loop only looks at specs that exist on the pull request's side, so deleting a version's folder passes. Part 5 showed that the publish doesn't delete the API either, so that one is for the reviewer.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dry run as a required check
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# Required check, next to validate. No environment, so the token subject is pull_request and the identity
&lt;/span&gt;  &lt;span class="c1"&gt;# has only Reader. With dev and prod limited to main, a PR that edits this file can't publish before review.
&lt;/span&gt;  &lt;span class="na"&gt;dry-run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;changes&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;needs.changes.outputs.apiops == 'true'&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The job names no &lt;code&gt;environment&lt;/code&gt;, and that missing line decides which identity it can get. GitHub writes the trigger into the subject claim of the OIDC token, and for a pull request run without an environment the subject is &lt;code&gt;repo:&amp;lt;owner&amp;gt;/&amp;lt;repo&amp;gt;:pull_request&lt;/code&gt;. The only identity whose federated credential trusts that subject is &lt;code&gt;id-apiops-plan&lt;/code&gt;, with &lt;strong&gt;Reader&lt;/strong&gt; on both instances and nothing else.&lt;/p&gt;

&lt;p&gt;Part 5's dry run had &lt;code&gt;environment: dev&lt;/code&gt; and the dev publisher's client ID. Its token carried &lt;code&gt;environment:dev&lt;/code&gt;, the same subject &lt;code&gt;publish-dev&lt;/code&gt; presents, and a &lt;code&gt;pull_request&lt;/code&gt; run uses the workflow file from the pull request's merge commit, not the one on &lt;code&gt;main&lt;/code&gt;. Anyone who could push a branch could open a pull request that deleted &lt;code&gt;--dry-run&lt;/code&gt; from that step and published to dev before a reviewer had opened the diff. Without the environment, the same edit gets a Reader token, and Reader has no write actions, so Azure should refuse the PUT with a 403; I haven't run that edit against an instance. Putting &lt;code&gt;environment: dev&lt;/code&gt; back into the pull request's copy of the workflow doesn't get around it, as long as the &lt;code&gt;dev&lt;/code&gt; environment's deployment branch rule allows only &lt;code&gt;main&lt;/code&gt;: a job running for &lt;code&gt;refs/pull/&amp;lt;n&amp;gt;/merge&lt;/code&gt; can't enter it. You need both settings. The workflow file alone proves nothing, because the pull request can change it.&lt;/p&gt;

&lt;p&gt;Reader is enough because of how 1.0.5 implements &lt;code&gt;--dry-run&lt;/code&gt;. Before the dry-run branch returns, &lt;code&gt;publish&lt;/code&gt; GETs the resource group and the instance (a pre-flight check) and each resource it plans to write, the last only to mark new ones as &lt;code&gt;(new)&lt;/code&gt;. Every PUT, PATCH and DELETE comes after that branch. That's from reading the CLI's &lt;code&gt;publish-service.js&lt;/code&gt;, &lt;code&gt;dry-run-reporter.js&lt;/code&gt; and &lt;code&gt;apim-client.js&lt;/code&gt; in the published 1.0.5 package; no dry run has run against a live instance with a Reader token, so the first real pull request is the test.&lt;/p&gt;

&lt;p&gt;The steps after checkout and Node setup sign in and plan twice. &lt;code&gt;$APIOPS_CLI&lt;/code&gt; is a workflow-level variable set to &lt;code&gt;@azure-tools/apiops-cli@1.0.5&lt;/code&gt;. The dev plan is the same command with the dev instance and without &lt;code&gt;--overrides&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;azure/login@v3&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;client-id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.APIOPS_PLAN_CLIENT_ID }}&lt;/span&gt;
          &lt;span class="na"&gt;tenant-id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.AZURE_TENANT_ID }}&lt;/span&gt;
          &lt;span class="na"&gt;subscription-id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.AZURE_SUBSCRIPTION_ID }}&lt;/span&gt;

      &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Dry run against prod with the prod overrides&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="s"&gt;npx --yes "$APIOPS_CLI" publish&lt;/span&gt;
          &lt;span class="s"&gt;--subscription-id ${{ vars.AZURE_SUBSCRIPTION_ID }}&lt;/span&gt;
          &lt;span class="s"&gt;--resource-group ${{ vars.APIM_PROD_RESOURCE_GROUP }}&lt;/span&gt;
          &lt;span class="s"&gt;--service-name ${{ vars.APIM_PROD_SERVICE_NAME }}&lt;/span&gt;
          &lt;span class="s"&gt;--source apim-artifacts&lt;/span&gt;
          &lt;span class="s"&gt;--overrides configuration.prod.yaml&lt;/span&gt;
          &lt;span class="s"&gt;--commit-id ${{ github.sha }}&lt;/span&gt;
          &lt;span class="s"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The prod plan is new. It runs the plan against prod with &lt;code&gt;configuration.prod.yaml&lt;/code&gt;, the file Part 5 called the change dev never tested. An override that names a product the artifacts don't have now fails on the pull request instead of in &lt;code&gt;publish-prod&lt;/code&gt; after someone approved it. Both plans sit in one job so the ruleset has a single check name to require.&lt;/p&gt;

&lt;p&gt;A job without an environment only sees repository variables, so &lt;code&gt;APIOPS_PLAN_CLIENT_ID&lt;/code&gt; and both instances' names and resource groups are repository variables. That isn't a leak, for reasons the sign-in section below covers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Required&lt;/strong&gt; means a branch ruleset on &lt;code&gt;main&lt;/code&gt; (Settings, Rules, Rulesets) with "Require status checks to pass" and the job names &lt;code&gt;dry-run&lt;/code&gt; and &lt;code&gt;validate&lt;/code&gt; as the checks; &lt;a href="https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-rulesets/available-rules-for-rulesets" rel="noopener noreferrer"&gt;available rules for rulesets&lt;/a&gt; lists the options. Add "Require a pull request before merging" in the same ruleset, or the checks only guard the people who chose to open one, and give it at least one required approval. The checks run from the pull request's copy of this file, so a pull request that sets &lt;code&gt;if: false&lt;/code&gt; on both jobs gets two skipped checks, which count as passed. Only a reviewer reading the workflow diff stops that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: pull requests from forks fail the dry run.&lt;/strong&gt; For &lt;code&gt;pull_request&lt;/code&gt; runs from forks, the &lt;code&gt;permissions&lt;/code&gt; key &lt;a href="https://docs.github.com/en/actions/reference/workflows-and-actions/workflow-syntax#using-the-permissions-key-for-forked-repositories" rel="noopener noreferrer"&gt;can't grant write access&lt;/a&gt; unless an admin turned on "Send write tokens to workflows from pull requests", so &lt;code&gt;id-token: write&lt;/code&gt; isn't granted and &lt;code&gt;azure/login&lt;/code&gt; has nothing to exchange. The check goes red, and it should: a fork has no business signing in to your subscription. A maintainer reads the diff, pushes the branch to the repository, and the check runs there. Don't "fix" it with &lt;code&gt;pull_request_target&lt;/code&gt;: that event runs with the base repository's permissions, and checking out the fork's code in it hands your identity to whoever opened the pull request. I haven't watched a fork run fail on the samples repo; this follows from GitHub's documentation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What the dry run can't tell you is whether API Management accepts the policies. It lists &lt;code&gt;PUT ApiPolicy/orders&lt;/code&gt; whether the XML is valid or not, because the instance only parses a policy when the real PUT arrives. A policy it rejects fails in &lt;code&gt;publish-dev&lt;/code&gt;, after the merge. The policy check in &lt;code&gt;validate&lt;/code&gt; catches part of that before the merge; the rest is why dev always comes before prod.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing to dev on merge
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="na"&gt;publish-dev&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name != 'pull_request'&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dev&lt;/span&gt;
    &lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apiops-publish-dev&lt;/span&gt;
      &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This job names &lt;code&gt;environment: dev&lt;/code&gt;, so its token's subject is &lt;code&gt;repo:&amp;lt;owner&amp;gt;/&amp;lt;repo&amp;gt;:environment:dev&lt;/code&gt;, and &lt;code&gt;vars.AZURE_CLIENT_ID&lt;/code&gt; in its &lt;code&gt;azure/login&lt;/code&gt; step resolves to the one variable the &lt;code&gt;dev&lt;/code&gt; environment holds, the client ID of &lt;code&gt;id-apiops-dev&lt;/code&gt;. Set the environment's deployment branches to &lt;code&gt;main&lt;/code&gt; only. That rule is what stops a pull request from borrowing this job's identity, as described above, and it costs nothing, because nothing but &lt;code&gt;main&lt;/code&gt; should publish to dev.&lt;/p&gt;

&lt;p&gt;The publish step is Part 5's, with the expression from the triggers section in place of a fixed &lt;code&gt;--commit-id&lt;/code&gt;. Part 5's prod job ran a dry run right before the publish. The plan now runs on the pull request against both instances, so the publish jobs go straight to &lt;code&gt;publish&lt;/code&gt;. If dev fails, &lt;code&gt;publish-prod&lt;/code&gt; never starts, because it &lt;code&gt;needs: publish-dev&lt;/code&gt;. Exit code &lt;code&gt;1&lt;/code&gt; means a partial publish; rerunning the job PUTs the same commit's artifacts again, which Part 5 showed is safe.&lt;/p&gt;

&lt;p&gt;Dev is the first place anything validates a policy for real. API Management parses the XML on the PUT, and a policy that references a named value the instance doesn't have should fail there; Learn doesn't spell that out, and this pipeline hasn't published yet. On the order API those references (&lt;code&gt;tenant-id&lt;/code&gt; and the three app IDs) are all Bicep-owned, so a policy that mentions a named value nobody created yet passes the dry run, passes review, and fails here, on an instance where failing is cheap.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;concurrency&lt;/code&gt; group is new too. Part 5's publish had none, so two merges a minute apart published to dev in parallel, and the second PUT of a shared file could land before the first. With &lt;code&gt;cancel-in-progress: false&lt;/code&gt;, the second run waits for the first. It's not a queue, though. By default, &lt;a href="https://docs.github.com/en/actions/how-tos/write-workflows/choose-when-workflows-run/control-workflow-concurrency" rel="noopener noreferrer"&gt;GitHub's concurrency docs&lt;/a&gt; allow one running and one pending run per group, and a third arrival cancels the pending one. Three merges inside one publish and the middle commit's change never reaches dev. In dev, the next commit to the same file or a manual full publish repairs that. In prod, the same rule meets an approval that can take hours, and that's a problem for the approval gate section.&lt;/p&gt;

&lt;h2&gt;
  
  
  Signing in without secrets: OIDC and a user-assigned managed identity
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faxtkodzgalqujdl4n71a.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Faxtkodzgalqujdl4n71a.png" alt="The three APIOps identities: id-apiops-plan with Reader for the PR dry run and nightly prod extract, id-apiops-dev and id-apiops-prod with API Management Service Contributor on their instance, each trusting only its own subject" width="799" height="206"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Each identity is a &lt;strong&gt;user-assigned managed identity&lt;/strong&gt; with one &lt;strong&gt;federated credential&lt;/strong&gt; per subject it trusts. The &lt;code&gt;azure/login&lt;/code&gt; step trades GitHub's OIDC token for an Entra ID token for that identity, and &lt;code&gt;client-id&lt;/code&gt; is the managed identity's client ID; there's no client secret and no &lt;code&gt;creds&lt;/code&gt; JSON anywhere. The CLI then signs in through &lt;code&gt;DefaultAzureCredential&lt;/code&gt;, which picks up the Azure CLI session &lt;code&gt;azure/login&lt;/code&gt; left behind, so nothing in the &lt;code&gt;npx&lt;/code&gt; steps knows about OIDC. &lt;a href="https://learn.microsoft.com/azure/developer/github/connect-from-azure-openid-connect" rel="noopener noreferrer"&gt;Learn's OIDC page for &lt;code&gt;azure/login&lt;/code&gt;&lt;/a&gt; documents both options, an app registration or a user-assigned managed identity, and the workflow is identical for either. The &lt;a href="https://github.com/Azure/apiops-cli/tree/main/docs/ci-cd" rel="noopener noreferrer"&gt;apiops-cli docs&lt;/a&gt; assume an app registration throughout.&lt;/p&gt;

&lt;p&gt;The managed identity wins on one practical point: it's an Azure resource, created by anyone with Contributor on the resource group. App registrations are a tenant-wide object, and the tenant this sample was built in doesn't let users create them. If yours does the same, a managed identity is the only way OIDC works at all.&lt;/p&gt;

&lt;p&gt;Creating the plan identity's pull request credential (the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo#apiops-the-api-surface-in-git" rel="noopener noreferrer"&gt;sample's README&lt;/a&gt; has the other credentials, the role assignments and the GitHub settings):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az identity federated-credential create -g &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;rg&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; --identity-name id-apiops-plan -n github-pull-request \
  --issuer https://token.actions.githubusercontent.com \
  --subject repo:&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;owner&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;repo&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;:pull_request --audiences api://AzureADTokenExchange
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://docs.github.com/en/actions/reference/security/oidc" rel="noopener noreferrer"&gt;GitHub OIDC reference&lt;/a&gt; decides which subject a job presents, and one rule shapes the whole table: &lt;strong&gt;the environment wins over the branch.&lt;/strong&gt; A job on &lt;code&gt;main&lt;/code&gt; that names &lt;code&gt;environment: dev&lt;/code&gt; presents &lt;code&gt;environment:dev&lt;/code&gt;, not &lt;code&gt;ref:refs/heads/main&lt;/code&gt;. A federated credential for the &lt;code&gt;main&lt;/code&gt; branch would never match &lt;code&gt;publish-dev&lt;/code&gt;, which is a common reason an OIDC login that "should work" fails with &lt;code&gt;AADSTS70021&lt;/code&gt;. The branch subject only applies to jobs with no environment that aren't pull request runs. &lt;a href="https://learn.microsoft.com/entra/workload-id/workload-identity-federation-create-trust-user-assigned-managed-identity" rel="noopener noreferrer"&gt;Microsoft Entra&lt;/a&gt; adds its own rules: the subject must match exactly, wildcards aren't supported, and one identity holds at most 20 federated credentials. Create them one at a time; &lt;a href="https://learn.microsoft.com/entra/workload-id/workload-identity-federation-considerations" rel="noopener noreferrer"&gt;creating several on the same identity concurrently fails with a 409&lt;/a&gt;, and a new credential takes a moment to propagate before the first login works.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;permissions&lt;/code&gt; block sits on each job that signs in, not on the workflow. &lt;code&gt;id-token: write&lt;/code&gt; is what lets a job request the OIDC token at all, and &lt;code&gt;changes&lt;/code&gt; has no reason to. The workflow-level default is &lt;code&gt;contents: read&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The variables split along the same line. Repository variables hold what every job may know: tenant, subscription, both instances' names and resource groups, and the plan identity's client ID. Each environment holds one variable, &lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt;, and an environment variable overrides a repository variable of the same name inside that environment's jobs. None of these values is a secret, the client IDs included. A pull request can paste &lt;code&gt;id-apiops-dev&lt;/code&gt;'s client ID into a job without an environment, and Entra ID will refuse the exchange, because that identity only trusts &lt;code&gt;environment:dev&lt;/code&gt;. The protection is the subject on the credential, not the secrecy of the ID.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-extract.yml" rel="noopener noreferrer"&gt;extract workflow&lt;/a&gt; needed only the follow-up changes: the same action versions, instance names from the repository variables, and &lt;code&gt;prod-read&lt;/code&gt; now pointing at &lt;code&gt;id-apiops-plan&lt;/code&gt;. That leaves one Reader identity for everything that only reads prod, the pull request plan and the nightly drift check, and two writers that only &lt;code&gt;main&lt;/code&gt; can reach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prod overrides, briefly
&lt;/h2&gt;

&lt;p&gt;Nothing about overrides changed since &lt;a href="https://dev.to/martin_oehlert/apiops-for-azure-api-management-extract-review-and-publish-with-the-apiops-cli-1gl6#one-set-of-files-several-environments"&gt;Part 5's environments section&lt;/a&gt;. The artifacts describe dev, &lt;code&gt;configuration.prod.yaml&lt;/code&gt; sets &lt;code&gt;subscriptionsLimit: 1&lt;/code&gt; on &lt;code&gt;orders-partners&lt;/code&gt;, and only the prod commands pass &lt;code&gt;--overrides&lt;/code&gt;. What's different is when you find out the file is wrong. In Part 5, the first command that applied it to prod ran inside &lt;code&gt;publish-prod&lt;/code&gt;, after the approval. Now the prod dry run reads it on every pull request that touches &lt;code&gt;apiops/&lt;/code&gt;, so a broken override is a red check next to the diff that introduced it, and the reviewer of a change to &lt;code&gt;configuration.prod.yaml&lt;/code&gt; sees the prod plan in the same pull request.&lt;/p&gt;

&lt;h2&gt;
  
  
  The prod approval gate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;  &lt;span class="c1"&gt;# The prod environment has required reviewers, so this job waits for an approval after dev succeeded.
&lt;/span&gt;  &lt;span class="na"&gt;publish-prod&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;publish-dev&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prod&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gate isn't in the YAML. &lt;code&gt;environment: prod&lt;/code&gt; only names it; the &lt;code&gt;prod&lt;/code&gt; environment's settings (Settings, Environments, &lt;code&gt;prod&lt;/code&gt;) decide what it does, and a pull request can't change them. The sample uses two: &lt;strong&gt;required reviewers&lt;/strong&gt; and &lt;strong&gt;deployment branches&lt;/strong&gt;. &lt;a href="https://docs.github.com/en/actions/reference/workflows-and-actions/deployments-and-environments" rel="noopener noreferrer"&gt;GitHub's environments reference&lt;/a&gt; allows up to six users or teams as reviewers, and one approval releases the job. The branch rule is &lt;code&gt;main&lt;/code&gt; only, as on &lt;code&gt;dev&lt;/code&gt;, so the job can't run for any other ref, approval or not.&lt;/p&gt;

&lt;p&gt;A third setting is worth turning on in a team and is off in the sample: &lt;strong&gt;prevent self-review&lt;/strong&gt;. With it, "users who initiate a deployment cannot approve the deployment job, even if they are a required reviewer." On a push to &lt;code&gt;main&lt;/code&gt;, the one who initiated the deployment is whoever merged (the push's actor), so the merger can't wave their own merge into prod; the pull request's author can, if someone else merged, and so can any other reviewer on the list. That turns "a second person approved prod" from a habit into a rule. The samples repo has one maintainer, who would have to bypass the rule on every run, and a rule that's bypassed every time records nothing.&lt;/p&gt;

&lt;p&gt;Bypass is the fourth setting. By default, administrators can push a waiting job past its protection rules, with a comment; "Allow administrators to bypass configured protection rules" turns that off. The emergency section below is about when you'd want it.&lt;/p&gt;

&lt;p&gt;None of this exists everywhere. On GitHub Free, Pro and Team, required reviewers and the bypass setting are only available for public repositories, and a private repository on Free gets no environments at all. The samples repo is public. On a private repository on Team, &lt;code&gt;environment: prod&lt;/code&gt; still resolves its variables and its OIDC subject, and waits for nobody. Open the environment's settings once and check that the reviewer list is there.&lt;/p&gt;

&lt;p&gt;A job &lt;a href="https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#using-required-reviews-in-workflows" rel="noopener noreferrer"&gt;waits up to 30 days&lt;/a&gt; for an approval and then fails; a rejection fails it at once. Either way, that commit's change isn't in prod, and the next merge's run only publishes its own diff. The concurrency rule from the dev section makes it worse, because a third arrival cancels the pending run. Whether a job waiting for approval holds the group or is the pending run isn't documented, and I haven't tested it, but the worst case is the same: a cancelled run whose commit never reaches prod. &lt;code&gt;queue: max&lt;/code&gt; on the group would keep up to 100 pending runs instead; I left it out, because a line of unapproved prod runs that each publish one old diff is its own problem, and I haven't seen how it behaves behind an approval. The repair is the manual run from the triggers section: start it from &lt;code&gt;main&lt;/code&gt;, approve it, and prod gets the full tree.&lt;/p&gt;

&lt;p&gt;What a reviewer reads before approving is the pull request, not the approval dialog. The dialog shows the run and its commit. The plan against prod with the prod overrides is on the pull request that produced that commit, in the &lt;code&gt;dry-run&lt;/code&gt; check, and that's the thing to open.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: every job that names &lt;code&gt;prod&lt;/code&gt; waits for its reviewers.&lt;/strong&gt; A job that only reads, a job with &lt;code&gt;deployment: false&lt;/code&gt;, a nightly schedule: &lt;a href="https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#using-environments-without-deployments" rel="noopener noreferrer"&gt;required reviewers apply to all of them&lt;/a&gt;. That's why Part 5's extract signs in to prod through a separate &lt;code&gt;prod-read&lt;/code&gt; environment with no reviewers and the Reader identity. Add a job that reads prod, a smoke test or a report, and give it &lt;code&gt;prod-read&lt;/code&gt;, or it waits for an approval every time it runs.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  When production is on fire
&lt;/h2&gt;

&lt;p&gt;Part 5 started with an incident: the biggest partner gets 429s, and the fix is 60 to 300 in &lt;code&gt;products/orders-partners/policy.xml&lt;/code&gt;. There are four ways to get that into prod, best first.&lt;/p&gt;

&lt;p&gt;The first is a pull request. One line, on a branch, through the same pipeline: &lt;code&gt;validate&lt;/code&gt;, &lt;code&gt;dry-run&lt;/code&gt;, a review, a merge, &lt;code&gt;publish-dev&lt;/code&gt;, an approval, &lt;code&gt;publish-prod&lt;/code&gt;. The checks run without a person; what takes time is the two people, one to review and one to approve (the same one, if you left prevent self-review off). Practice that path on quiet days, so the only new thing on the bad day is the pressure.&lt;/p&gt;

&lt;p&gt;The second is &lt;code&gt;git revert&lt;/code&gt; of the merge commit, on a branch, through the same pull request. The per-commit publish then PUTs the files as they were before. It undoes changes, not additions: reverting a commit that added an API removes its folder, and Part 5 showed that the CLI without &lt;code&gt;--delete-unmatched&lt;/code&gt; leaves that API live in API Management.&lt;/p&gt;

&lt;p&gt;Third, an administrator skips the gates. Someone on the ruleset's bypass list merges without waiting for the checks, and the prod job gets pushed past its reviewers with &lt;a href="https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/review-deployments#bypassing-deployment-protection-rules" rel="noopener noreferrer"&gt;"Start all waiting jobs"&lt;/a&gt; and a comment. It's still the pipeline: the change is a commit, &lt;code&gt;id-apiops-prod&lt;/code&gt; publishes it, and the run shows who bypassed and why. Decide whether you keep this before you need it. Turning bypass off means an incident waits for a reviewer. Leaving it on means an administrator can skip the gate on any ordinary Tuesday, too.&lt;/p&gt;

&lt;p&gt;The fourth is the portal, and someone will use it. &lt;code&gt;id-apiops-prod&lt;/code&gt; is the only identity the pipeline writes with, but people with API Management Service Contributor on prod can still click save, and the 300 is live within a minute. The pipeline can't prevent that; it notices. The next nightly extract reads prod through &lt;code&gt;prod-read&lt;/code&gt;, finds &lt;code&gt;calls="300"&lt;/code&gt;, and puts that line into the &lt;code&gt;apiops-extract/prod&lt;/code&gt; pull request (Part 5). That pull request also always shows the prod override, so it isn't the one to merge: copy the 300 into a branch of its own and send it through the pipeline, which publishes it to dev and then, after an approval, to prod, where it's already live. Do it within a day. Until then, two things put the 60 back: the next per-commit publish that touches that policy file, and any manual full publish. The second is the trap, because it's exactly what someone starts on the quiet morning after an incident to reconcile a rejected run.&lt;/p&gt;

&lt;h2&gt;
  
  
  One change end to end
&lt;/h2&gt;

&lt;p&gt;Part 5's role change, carried all the way to prod. A partner wants a read-only client, so someone adds &lt;code&gt;&amp;lt;value&amp;gt;Orders.Read&amp;lt;/value&amp;gt;&lt;/code&gt; to the token check.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The branch edits &lt;code&gt;apis/orders/policy.xml&lt;/code&gt; and opens a pull request. &lt;code&gt;changes&lt;/code&gt; sees &lt;code&gt;apiops/&lt;/code&gt; and starts both checks. &lt;code&gt;validate&lt;/code&gt; fails in the policy step with &lt;code&gt;differs from apis/orders-v2/policy.xml; change both&lt;/code&gt;: the file Part 5 found missing by reading the file list, now found without anyone reading.&lt;/li&gt;
&lt;li&gt;A second commit adds the line to &lt;code&gt;apis/orders-v2/policy.xml&lt;/code&gt;. &lt;code&gt;validate&lt;/code&gt; passes: the specs didn't change, so Spectral prints the same 8 warnings and oasdiff reports no changes. &lt;code&gt;dry-run&lt;/code&gt; plans &lt;code&gt;ApiPolicy/orders&lt;/code&gt; and &lt;code&gt;ApiPolicy/orders-v2&lt;/code&gt; against dev, then the same two against prod.&lt;/li&gt;
&lt;li&gt;The reviewer reads the diff and asks Part 5's question. With &lt;code&gt;match="any"&lt;/code&gt;, a token with only &lt;code&gt;Orders.Read&lt;/code&gt; now passes the token check for &lt;code&gt;POST /orders&lt;/code&gt; too. No check here can answer that, because it's a design decision, not a syntax error. The author adds a &lt;code&gt;create-order&lt;/code&gt; operation policy to both versions that requires &lt;code&gt;Orders.ReadWrite&lt;/code&gt;. &lt;code&gt;validate&lt;/code&gt; holds the new files to a &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; in every section, so they can't drop the API's token check by accident, and the dry run lists them as &lt;code&gt;(new)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The pull request is squash-merged, one commit on &lt;code&gt;main&lt;/code&gt;. &lt;code&gt;publish-dev&lt;/code&gt; publishes its four policy files to dev as &lt;code&gt;id-apiops-dev&lt;/code&gt;. API Management parses them for the first time here.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;publish-prod&lt;/code&gt; waits. A second person opens the run, checks it's the commit whose prod plan they read on the pull request, and approves. &lt;code&gt;id-apiops-prod&lt;/code&gt; publishes the same four files with the prod overrides.&lt;/li&gt;
&lt;li&gt;The next nightly prod extract finds nothing beyond the standing override line.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Every check passed, and the change still doesn't work. &lt;code&gt;Orders.Read&lt;/code&gt; has to exist as an app role on the API's app registration, which is &lt;code&gt;infra/entra.bicep&lt;/code&gt;, and that file only defines &lt;code&gt;Orders.ReadWrite&lt;/code&gt;. Nobody can assign a role that doesn't exist, and with &lt;code&gt;appRoleAssignmentRequired&lt;/code&gt; set (Part 3), Entra ID won't issue the read-only client a token for the API at all. Bicep owns that half of the change, and it has to ship first.&lt;/p&gt;

&lt;h2&gt;
  
  
  What each stage catches, and what it can't
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkabsbkpb98x8r9fcngjo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkabsbkpb98x8r9fcngjo.png" alt="What each stage catches and can't see: validate, dry-run, publish-dev, the prod approval, publish-prod and the nightly extract" width="800" height="455"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The misses have one cause. Nothing in this pipeline sends a request through the gateway, so everything it can't see shows up at run time: the role nobody defined, the limit that's too tight, the response a client didn't expect. A smoke test after &lt;code&gt;publish-dev&lt;/code&gt; would be the next gate; &lt;code&gt;scripts/verify.sh&lt;/code&gt; in the sample is most of one, and it needs a client secret the pipeline doesn't have.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Part 1 put a gateway in front of one Azure Function. Six parts later, the same order API has policies at four scopes, an Entra token check, two versions, two products, and one way to change any of it: a commit that passed two checks, ran on dev, and got a second person's approval for prod. When someone uses the portal anyway, the next morning's pull request says so.&lt;/p&gt;

&lt;p&gt;Keeping that costs something: three identities with exact-match subjects, three environments whose reviewers and branch rules live outside the YAML, a ruleset, a policy script with a list of files that must match, and pinned versions that each need a bump eventually. For an API with one policy and one caller, it's too much. For an API that partners depend on, it's what lets you answer "who changed the rate limit, and who approved it" from Git instead of from memory.&lt;/p&gt;

&lt;p&gt;Does a pull request in your API repo need a passing dry run before it can merge: yes or no?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>devops</category>
      <category>azureapimanagement</category>
      <category>cicd</category>
    </item>
    <item>
      <title>APIOps for Azure API Management: Extract, Review and Publish with the APIOps CLI</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 06 Nov 2026 06:52:32 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/apiops-for-azure-api-management-extract-review-and-publish-with-the-apiops-cli-1gl6</link>
      <guid>https://dev.to/martin_oehlert/apiops-for-azure-api-management-extract-review-and-publish-with-the-apiops-cli-1gl6</guid>
      <description>&lt;p&gt;Who wins when Bicep and the Azure portal disagree about a policy on the same API Management instance, and how do you find out before a partner does? In the order API from Parts 1 to 4, Bicep deploys every API, policy and product, so a fix someone makes in the portal's policy editor lasts exactly until the next &lt;code&gt;azd up&lt;/code&gt;, and nothing records that it was ever there. APIOps moves the API surface into files that a pull request can review: extract what is live, commit it, and publish only approved commits. It only works if each resource has one owner, so the answer for the order API is a split: Bicep keeps the platform, APIOps takes the APIs, policies and products.&lt;/p&gt;

&lt;p&gt;Part 4 ended with the products and the version set in Bicep and everything clicked in the portal living only in the instance. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt; now has an &lt;code&gt;apiops/&lt;/code&gt; folder: both order APIs, their version set and both products as files in the layout the APIOps tooling reads and writes, a filter that limits extraction to exactly those resources, and two GitHub Actions workflows: one extracts into a pull request every night, the other publishes what a merge approves. A new Bicep parameter, &lt;code&gt;apiSurfaceOwner&lt;/code&gt;, decides whether Bicep or the publisher deploys that surface. It defaults to &lt;code&gt;bicep&lt;/code&gt;, so everything from Parts 1 to 4 still deploys the way it did. The tool is the &lt;strong&gt;APIOps CLI&lt;/strong&gt; (&lt;code&gt;@azure-tools/apiops-cli&lt;/code&gt;, version 1.0.5), a single Node.js command that &lt;a href="https://learn.microsoft.com/azure/api-management/how-to-manage-apiops-cli" rel="noopener noreferrer"&gt;Microsoft Learn now documents&lt;/a&gt; and the &lt;a href="https://learn.microsoft.com/azure/architecture/example-scenario/devops/automated-api-deployments-apiops" rel="noopener noreferrer"&gt;Architecture Center recommends&lt;/a&gt; over the older APIOps Toolkit and its two binaries; its &lt;code&gt;extract&lt;/code&gt; and &lt;code&gt;publish&lt;/code&gt; commands are the extractor and publisher in the title. As in Part 4, nothing has been deployed. The Bicep builds, the workflows lint clean, the CLI's own filter code was run against the sample's filter, and the artifact tree was written by hand to match the Bicep. Where the article depends on how a live instance behaves, it says so.&lt;/p&gt;

&lt;h2&gt;
  
  
  The portal hotfix Git never saw
&lt;/h2&gt;

&lt;p&gt;During an incident, someone opens the &lt;code&gt;orders-partners&lt;/code&gt; product in the Azure portal, because the biggest partner is getting 429s. The committed product policy says:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;    &lt;span class="nt"&gt;&amp;lt;rate-limit&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They change 60 to 300, save, and the throttling stops. The next &lt;code&gt;azd up&lt;/code&gt; deploys &lt;code&gt;apim.bicep&lt;/code&gt;, which loads the product policy from the repo, and the limit is 60 again. The partner is throttled again, and whoever debugs it reads a repo that says 60 and has always said 60.&lt;/p&gt;

&lt;p&gt;Neither tool did anything wrong. Bicep deployed what the file said; the portal saved what the operator typed. Two writers own the same resource, the last one wins, and neither knows the other exists.&lt;/p&gt;

&lt;p&gt;APIOps attacks this from both ends. &lt;strong&gt;Extraction&lt;/strong&gt; turns the portal edit into a diff: the 300 shows up in a pull request instead of being overwritten without a trace. &lt;strong&gt;Publishing&lt;/strong&gt; makes the repo the only way the API surface changes, so the incident fix gets merged or reverted on purpose. Neither end helps while Bicep still deploys the same policy, which is why the sample splits ownership before it extracts anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  Extract a baseline from the instance you already have
&lt;/h2&gt;

&lt;p&gt;From &lt;code&gt;ApimOrdersDemo/apiops&lt;/code&gt;, signed in with &lt;code&gt;az login&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @azure-tools/apiops-cli@1.0.5 extract &lt;span class="nt"&gt;--resource-group&lt;/span&gt; &amp;lt;rg&amp;gt; &lt;span class="nt"&gt;--service-name&lt;/span&gt; &amp;lt;APIM_NAME&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--filter&lt;/span&gt; configuration.extractor.yaml &lt;span class="nt"&gt;--no-transitive&lt;/span&gt; &lt;span class="nt"&gt;--output&lt;/span&gt; apim-artifacts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI needs Node.js 22 or later and signs in through &lt;code&gt;DefaultAzureCredential&lt;/code&gt;: your Azure CLI session locally, whatever &lt;code&gt;azure/login&lt;/code&gt; set up in a workflow. If the instance isn't in your default subscription, add the global &lt;code&gt;--subscription-id&lt;/code&gt;. Extraction only reads, and &lt;a href="https://learn.microsoft.com/azure/api-management/how-to-manage-apiops-cli#prerequisites" rel="noopener noreferrer"&gt;Learn&lt;/a&gt; recommends separate, least-privilege identities for production: read access for the one that extracts, and only what publishing needs for the one that publishes. &lt;strong&gt;Reader&lt;/strong&gt; on the instance and &lt;strong&gt;API Management Service Contributor&lt;/strong&gt;, the two roles Learn lists, cover those. Pin the version (&lt;code&gt;@1.0.5&lt;/code&gt;), as Learn recommends for CI; &lt;code&gt;npx&lt;/code&gt; without one takes whatever is latest that morning.&lt;/p&gt;

&lt;p&gt;Without &lt;code&gt;--filter&lt;/code&gt;, &lt;code&gt;extract&lt;/code&gt; writes everything the instance holds: the service-level policy, every API with its specification, operations, policies, diagnostics, tags, schemas and releases, every product with its policy and its API and group links, plus backends, named values, loggers, diagnostics, groups, subscriptions, version sets, policy fragments and gateways. For an instance one team owns end to end, that is the right first run. For the order API it would put half of what Bicep deploys into a second repo folder, with a second writer attached.&lt;/p&gt;

&lt;p&gt;The &lt;a href="https://github.com/Azure/apiops-cli/blob/main/docs/commands/extract.md#exit-codes" rel="noopener noreferrer"&gt;exit code&lt;/a&gt; tells you how it went: &lt;code&gt;0&lt;/code&gt; success, &lt;code&gt;1&lt;/code&gt; partial (some resources failed, the rest were written), &lt;code&gt;2&lt;/code&gt; fatal (authentication, invalid configuration, or nothing extracted). A pipeline step that fails on anything non-zero treats a partial extract as a failure, which is what you want from a baseline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Filtering to what the repo owns
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/apiops/configuration.extractor.yaml" rel="noopener noreferrer"&gt;&lt;code&gt;configuration.extractor.yaml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/apiops-cli/main/schemas/v1/extractor-config.schema.json&lt;/span&gt;
&lt;span class="c1"&gt;# The API surface this repo owns. An omitted key means "extract everything of that type",&lt;/span&gt;
&lt;span class="c1"&gt;# so every Bicep-owned type is set to [] explicitly.&lt;/span&gt;
&lt;span class="na"&gt;apis&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;orders&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;diagnostics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;orders-v2&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;diagnostics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;versionSets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;orders&lt;/span&gt;
&lt;span class="na"&gt;products&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;orders-free&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;orders-partners&lt;/span&gt;
&lt;span class="na"&gt;backends&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;namedValues&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;loggers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;diagnostics&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;groups&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;subscriptions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;policies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;tags&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;policyFragments&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;gateways&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;schemas&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;policyRestrictions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;documentations&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;span class="na"&gt;workspaces&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each top-level key is independent, and a key you leave out means &lt;strong&gt;all resources of that type&lt;/strong&gt; (the &lt;a href="https://github.com/Azure/apiops-cli/blob/main/docs/commands/extract.md" rel="noopener noreferrer"&gt;extract reference&lt;/a&gt; says so in a note that's easy to scroll past). A filter that lists only &lt;code&gt;apis&lt;/code&gt;, &lt;code&gt;versionSets&lt;/code&gt; and &lt;code&gt;products&lt;/code&gt; looks right and still extracts every backend, named value, logger, group and subscription on the instance. That's why the file is mostly empty lists: every type Bicep owns is switched off by name. &lt;code&gt;policies: []&lt;/code&gt; is the service-level policy, which stays in &lt;code&gt;infra/policies/global.xml&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;diagnostics: []&lt;/code&gt; under each API is easy to miss. The Application Insights diagnostic on &lt;code&gt;orders&lt;/code&gt; stays with Bicep in this split, and the top-level &lt;code&gt;diagnostics&lt;/code&gt; key doesn't reach it: API diagnostics are children of the API and follow the API's own entry. Running the CLI's filter function from 1.0.5 against this file gives the expected answer for each case: &lt;code&gt;orders&lt;/code&gt;, its operation policies and the product-to-group links are in; the &lt;code&gt;orders/applicationinsights&lt;/code&gt; diagnostic, the &lt;code&gt;orders-func&lt;/code&gt; backend, the &lt;code&gt;tenant-id&lt;/code&gt; named value, the &lt;code&gt;partners&lt;/code&gt; group, the global policy and the &lt;code&gt;contoso-shop&lt;/code&gt; subscription are out.&lt;/p&gt;

&lt;p&gt;The filter still isn't enough on its own. With a filter, the CLI follows &lt;strong&gt;transitive dependencies&lt;/strong&gt;: it reads the selected APIs' policies and also extracts the backends, named values, policy fragments, tags and version sets they reference, even when that type's key is &lt;code&gt;[]&lt;/code&gt;. The template &lt;code&gt;apiops init&lt;/code&gt; generates says so, and suggests &lt;code&gt;--no-transitive&lt;/code&gt; to turn it off. The order API's policy references &lt;code&gt;orders-func&lt;/code&gt; and four named values (&lt;code&gt;tenant-id&lt;/code&gt; and the three app IDs from Part 3). Without &lt;code&gt;--no-transitive&lt;/code&gt;, the first extract writes all of them into the repo, and the first publish PUTs them back over the values Bicep set from the Entra and Function outputs. In this layout, &lt;code&gt;--no-transitive&lt;/code&gt; is what holds the boundary.&lt;/p&gt;

&lt;p&gt;For every extract after the first, add &lt;code&gt;--remove-stale&lt;/code&gt;. It deletes local files for resources inside the filter's scope that no longer exist on the instance, and only after a fully successful extraction. Without it, an API deleted in the portal keeps its folder in Git, and the next full publish recreates it. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-extract.yml" rel="noopener noreferrer"&gt;extract workflow&lt;/a&gt; always passes it.&lt;/p&gt;

&lt;h3&gt;
  
  
  What lands on disk
&lt;/h3&gt;

&lt;p&gt;The sample's &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo/apiops/apim-artifacts" rel="noopener noreferrer"&gt;&lt;code&gt;apim-artifacts/&lt;/code&gt;&lt;/a&gt; tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apim-artifacts
├── apis
│   ├── orders
│   │   ├── apiInformation.json
│   │   ├── operations
│   │   │   └── get-order
│   │   │       └── policy.xml
│   │   ├── policy.xml
│   │   └── specification.yaml
│   └── orders-v2
│       ├── apiInformation.json
│       ├── operations
│       │   └── list-orders
│       │       └── policy.xml
│       ├── policy.xml
│       └── specification.yaml
├── products
│   ├── orders-free
│   │   ├── apis.json
│   │   ├── groups.json
│   │   ├── policy.xml
│   │   └── productInformation.json
│   └── orders-partners
│       ├── apis.json
│       ├── groups.json
│       ├── policy.xml
│       └── productInformation.json
└── versionSets
    └── orders
        └── versionSetInformation.json
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Folder names are resource names.&lt;/strong&gt; &lt;code&gt;apis/orders-v2/&lt;/code&gt; is the API whose ARM name is &lt;code&gt;orders-v2&lt;/code&gt;, and the JSON inside doesn't repeat it. Renaming the folder doesn't rename the API; to the publisher it's a new API next to the old one.&lt;/p&gt;

&lt;p&gt;Each &lt;code&gt;*Information.json&lt;/code&gt; file holds the resource's ARM &lt;code&gt;properties&lt;/code&gt; and nothing else: no &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;type&lt;/code&gt; or &lt;code&gt;name&lt;/code&gt;. Here is &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/apiops/apim-artifacts/apis/orders-v2/apiInformation.json" rel="noopener noreferrer"&gt;&lt;code&gt;apis/orders-v2/apiInformation.json&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"properties"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"displayName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Orders API"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"apiVersionSetId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"/apiVersionSets/orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"apiVersion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"v2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"apiVersionDescription"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"list-orders returns a page of orders ({ items, nextLink }) instead of an array."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"path"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"sales"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"protocols"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"https"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"subscriptionRequired"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are the same values &lt;code&gt;apim.bicep&lt;/code&gt; sets on &lt;code&gt;ordersApiV2&lt;/code&gt;. &lt;code&gt;apiVersionSetId&lt;/code&gt; is a reference by name: before the PUT, the publisher keeps the last segment of the ID and rebuilds it for the target instance, so the same file publishes to dev and to prod. A live extract writes the source instance's full resource ID there; the hand-written file uses the short form, which the 1.0.5 source handles the same way.&lt;/p&gt;

&lt;p&gt;One property is missing on purpose: &lt;code&gt;serviceUrl&lt;/code&gt;. Bicep sets it to the function's URL, but no call ever uses it, because the API policy routes every request with &lt;code&gt;set-backend-service backend-id="orders-func"&lt;/code&gt;. It is also the one value that differs per environment. Leaving it out keeps a dev URL out of a prod publish. A live extract from the Bicep-deployed instance will write it back in, and that is the first line to look at in the baseline diff.&lt;/p&gt;

&lt;p&gt;The spec sits next to the policy. &lt;code&gt;specification.yaml&lt;/code&gt; is the OpenAPI file from Part 1, moved into the API's folder, and &lt;code&gt;policy.xml&lt;/code&gt; beside it is the API-scope policy from Parts 2 and 3. Operation policies go one level down, in &lt;code&gt;operations/&amp;lt;operationId&amp;gt;/policy.xml&lt;/code&gt;. The sample only has folders for the two operations that have a policy. A live extract also writes an &lt;code&gt;operationInformation.json&lt;/code&gt; for every operation, all three per API; the sample leaves those out, because importing the spec creates the operations, and the first real extract will add them.&lt;/p&gt;

&lt;p&gt;Products carry their policy (the 60-call limit lives in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/apiops/apim-artifacts/products/orders-partners/policy.xml" rel="noopener noreferrer"&gt;&lt;code&gt;products/orders-partners/policy.xml&lt;/code&gt;&lt;/a&gt; now) and two link files. &lt;code&gt;apis.json&lt;/code&gt; is the same for both products:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"orders-v2"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;groups.json&lt;/code&gt; decides who sees the product in the developer portal: &lt;code&gt;developers&lt;/code&gt; for the free product, &lt;code&gt;partners&lt;/code&gt; for the partner one. The link is APIOps-owned; the groups aren't. &lt;code&gt;partners&lt;/code&gt; comes from Bicep and &lt;code&gt;developers&lt;/code&gt; is built in, so the publisher only connects the product to a group that must already exist.&lt;/p&gt;

&lt;p&gt;What's missing is just as deliberate. A full extract would add a root &lt;code&gt;policy.xml&lt;/code&gt; and the folders &lt;code&gt;namedValues/&lt;/code&gt;, &lt;code&gt;backends/&lt;/code&gt;, &lt;code&gt;loggers/&lt;/code&gt;, &lt;code&gt;diagnostics/&lt;/code&gt;, &lt;code&gt;groups/&lt;/code&gt; and &lt;code&gt;subscriptions/&lt;/code&gt;, plus &lt;code&gt;diagnostics/&lt;/code&gt; inside &lt;code&gt;apis/orders/&lt;/code&gt;. All of that is Bicep's in this split, and the filter keeps it out.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: Toolkit trees look different.&lt;/strong&gt; The legacy APIOps Toolkit (v7) writes &lt;code&gt;named values/&lt;/code&gt;, &lt;code&gt;version sets/&lt;/code&gt; and &lt;code&gt;policy fragments/&lt;/code&gt; with spaces, and stores product links as folders (&lt;code&gt;products/&amp;lt;product&amp;gt;/apis/&amp;lt;api&amp;gt;/productApiInformation.json&lt;/code&gt;) instead of &lt;code&gt;apis.json&lt;/code&gt;. The CLI's &lt;a href="https://github.com/Azure/apiops-cli/blob/main/docs/guides/migration-from-v1.md" rel="noopener noreferrer"&gt;migration guide&lt;/a&gt; says Toolkit artifacts "should work as-is", but the 1.0.5 source only knows the camel-case names. Don't merge a Toolkit-era tree into this layout by hand; the Toolkit section below covers how to check an existing tree.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Laying out the repository
&lt;/h2&gt;

&lt;p&gt;The CLI's defaults (&lt;code&gt;./apim-artifacts&lt;/code&gt;, &lt;code&gt;configuration.extractor.yaml&lt;/code&gt;, &lt;code&gt;configuration.&amp;lt;env&amp;gt;.yaml&lt;/code&gt; next to it) assume a repository that holds nothing but API Management configuration; &lt;code&gt;apiops init&lt;/code&gt; scaffolds exactly that, workflows included. The order API's repo also holds the function code and the Bicep, so the APIOps files get their own folder inside the sample and the CLI runs from there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;apiops/
  configuration.extractor.yaml   the filter: the APIOps-owned names, [] for every Bicep-owned type
  configuration.prod.yaml        prod overrides (orders-partners: one subscription per partner)
  apim-artifacts/                apis/, versionSets/, products/ in the APIOps CLI layout
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;apiops/&lt;/code&gt; sits next to &lt;code&gt;infra/&lt;/code&gt; and &lt;code&gt;src/&lt;/code&gt;. The defaults still hold relative to it, and the workflows can trigger on &lt;code&gt;ApimOrdersDemo/apiops/**&lt;/code&gt; without reacting to a change in the function code. There's no &lt;code&gt;configuration.dev.yaml&lt;/code&gt;: dev is the lowest environment, and the artifacts already describe it.&lt;/p&gt;

&lt;p&gt;Before this part, the spec lived in &lt;code&gt;openapi/&lt;/code&gt; and the policies in &lt;code&gt;infra/policies/&lt;/code&gt;, one file per scope. Moving each API's contract and rules into one folder has two effects. A reviewer sees a removed operation and the operation policy that pointed at it in the same diff. And Bicep had to follow, because two deployable copies of one policy would drift. &lt;code&gt;apim.bicep&lt;/code&gt; now loads them from the artifact tree:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;    &lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;loadTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'../apiops/apim-artifacts/apis/orders/specification.yaml'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is one copy of each spec and policy that anything deploys, read by Bicep while &lt;code&gt;apiSurfaceOwner&lt;/code&gt; is &lt;code&gt;bicep&lt;/code&gt; and by the publisher once it is &lt;code&gt;apiops&lt;/code&gt;. The files moved with &lt;code&gt;git mv&lt;/code&gt;, so &lt;code&gt;git log --follow&lt;/code&gt; still shows their history from Part 2 on. The old paths hold read-only mirrors, so links from Parts 1 to 4 still open a file; nothing deploys from them, and &lt;code&gt;MIRRORS_ONLY=1 scripts/verify.sh&lt;/code&gt; fails if one drifts from the artifact tree.&lt;/p&gt;

&lt;p&gt;One duplicate exists on purpose. In Part 4, &lt;code&gt;orders&lt;/code&gt; and &lt;code&gt;orders-v2&lt;/code&gt; both loaded &lt;code&gt;api-orders.xml&lt;/code&gt;. APIOps has one &lt;code&gt;policy.xml&lt;/code&gt; per API folder, so that became two identical files. A change to the token check now has to touch both, and a pull request that only touches one shows it. &lt;code&gt;global.xml&lt;/code&gt; stays in &lt;code&gt;infra/policies/&lt;/code&gt;, because the global policy is platform: its CORS rule reads the &lt;code&gt;portal-origin&lt;/code&gt; named value that Bicep computes from the instance name.&lt;/p&gt;

&lt;h3&gt;
  
  
  Committing the baseline
&lt;/h3&gt;

&lt;p&gt;The first commit of &lt;code&gt;apim-artifacts/&lt;/code&gt; is the &lt;strong&gt;baseline&lt;/strong&gt;, and it should contain nothing else: no fixes, no renames, no reformatting. Every pull request after it is then a diff of intent against what was live.&lt;/p&gt;

&lt;p&gt;Extract from dev. The artifacts describe dev, and everything prod does differently goes through &lt;code&gt;configuration.prod.yaml&lt;/code&gt;, so a baseline taken from prod would bake prod's values (&lt;code&gt;subscriptionsLimit: 1&lt;/code&gt;, for one) into the files every environment publishes. Before &lt;code&gt;git add&lt;/code&gt;, search the tree for secrets. The CLI redacts secret fields and policy patterns it recognizes and writes &lt;code&gt;*** REDACTED ***&lt;/code&gt; in their place, but &lt;a href="https://learn.microsoft.com/azure/api-management/how-to-manage-apiops-cli" rel="noopener noreferrer"&gt;Learn is explicit&lt;/a&gt; that it "might not detect every embedded secret": a key someone pasted into a &lt;code&gt;set-header&lt;/code&gt; value is still a key. In this layout the risk is small, because no named values are extracted, but the grep takes seconds. A marker that does slip through can't reach an instance: 1.0.5's publish refuses to run while any &lt;code&gt;*** REDACTED ***&lt;/code&gt; is left in the source.&lt;/p&gt;

&lt;p&gt;Then open the baseline as a pull request and review it as a question: is this what we think is live in dev? Prod gets the same question from the nightly extract, which compares the prod instance against these files. That's where the 300 from the incident turns up, and where you decide whether it goes back to 60 or stays.&lt;/p&gt;

&lt;p&gt;The sample's baseline is the hand-written tree, so its first live extract from dev will produce a diff anyway: &lt;code&gt;serviceUrl&lt;/code&gt;, the &lt;code&gt;operationInformation.json&lt;/code&gt; files, and whatever formatting the instance applies to the policy XML it returns. Commit that as its own change, labelled as the extract, before anything else touches the folder. From then on, the &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-extract.yml" rel="noopener noreferrer"&gt;extract workflow&lt;/a&gt; runs the same extract against dev and prod every night and opens a pull request with whatever drifted.&lt;/p&gt;

&lt;h2&gt;
  
  
  Named values and secrets: what extraction leaves out
&lt;/h2&gt;

&lt;p&gt;The order API has one secret, the function key the &lt;code&gt;orders-func&lt;/code&gt; backend sends as &lt;code&gt;x-functions-key&lt;/code&gt;. It sits in the secret named value &lt;code&gt;orders-function-key&lt;/code&gt;, which Bicep fills from the function app's output at deploy time. In this split it never touches the repo: the filter lists &lt;code&gt;namedValues: []&lt;/code&gt; and &lt;code&gt;backends: []&lt;/code&gt;, and &lt;code&gt;--no-transitive&lt;/code&gt; stops the extract from following the API policy to them. The &lt;code&gt;apim-artifacts/&lt;/code&gt; tree contains no secret, no redacted placeholder and no override that has to supply one. That is the strongest argument for the split, and it costs nothing: the values that differ per environment are exactly the ones Bicep already computes from other resources.&lt;/p&gt;

&lt;p&gt;A repo that owns its named values needs a plan for every secret among them. An extract replaces the value with &lt;code&gt;*** REDACTED ***&lt;/code&gt;, and, as above, publish stops on that marker. The CLI's &lt;a href="https://github.com/Azure/apiops-cli/blob/main/docs/guides/environment-overrides.md" rel="noopener noreferrer"&gt;environment overrides guide&lt;/a&gt; describes two ways to supply the real value per environment: a Key Vault reference in the environment's override file (the target instance's managed identity then needs read access to the vault, which is infrastructure again), or a &lt;code&gt;{#[TOKEN]#}&lt;/code&gt; placeholder that the pipeline replaces from a GitHub environment secret before it publishes. Both work. Neither is needed while Bicep keeps the secret.&lt;/p&gt;

&lt;h2&gt;
  
  
  Publish: dry run first, then the approved commit
&lt;/h2&gt;

&lt;p&gt;From the same folder, against the same instance:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx @azure-tools/apiops-cli@1.0.5 publish &lt;span class="nt"&gt;--resource-group&lt;/span&gt; &amp;lt;rg&amp;gt; &lt;span class="nt"&gt;--service-name&lt;/span&gt; &amp;lt;APIM_NAME&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--source&lt;/span&gt; apim-artifacts &lt;span class="nt"&gt;--dry-run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Without &lt;code&gt;--dry-run&lt;/code&gt;, the same command applies the plan. With it, nothing is written. The CLI checks that the resource group and instance exist, validates the overrides against the artifacts, scans every artifact it would publish for &lt;code&gt;*** REDACTED ***&lt;/code&gt;, and then prints one planned call per resource: &lt;code&gt;PUT VersionSet/orders&lt;/code&gt;, &lt;code&gt;PUT Api/orders&lt;/code&gt;, &lt;code&gt;PUT ProductPolicy/orders-partners&lt;/code&gt; and so on, in the order it would send them. The version set and products come first, then the APIs, the product policies and links, the API policies, and the operations and their policies last. Running the CLI's dry-run reporter locally against the sample tree, with a stubbed Azure client instead of an instance, gives 19 planned calls: the 11 artifacts, the six links from the two products' &lt;code&gt;apis.json&lt;/code&gt; and &lt;code&gt;groups.json&lt;/code&gt;, and two &lt;code&gt;PUT ApiOperation&lt;/code&gt; calls for &lt;code&gt;get-order&lt;/code&gt;, one per API. Those two don't come from a folder. After importing a spec, 1.0.5 re-PUTs every operation whose spec entry has no &lt;code&gt;description&lt;/code&gt; and sets the description to null, and &lt;code&gt;get-order&lt;/code&gt; is the only operation in either spec without one. Add &lt;code&gt;--format json&lt;/code&gt; and the same report becomes machine-readable for a pipeline gate.&lt;/p&gt;

&lt;p&gt;The dry run is a plan of calls, not a diff. It does a GET per resource only to mark the ones that don't exist yet as &lt;code&gt;(new)&lt;/code&gt;; it doesn't compare properties. An unchanged policy shows up as &lt;code&gt;PUT&lt;/code&gt; exactly like a changed one. What changed is in the Git diff of the pull request. The dry run answers the other question: will this run, against this instance, with these overrides? &lt;a href="https://learn.microsoft.com/azure/api-management/how-to-manage-apiops-cli" rel="noopener noreferrer"&gt;Learn&lt;/a&gt; adds the obvious caveat that a successful dry run doesn't test policies, permissions or backend connectivity.&lt;/p&gt;

&lt;h3&gt;
  
  
  The first publish onto an instance Bicep built
&lt;/h3&gt;

&lt;p&gt;The order API's instance already has &lt;code&gt;orders&lt;/code&gt;, &lt;code&gt;orders-v2&lt;/code&gt;, the version set and both products, all deployed by Bicep. Set &lt;code&gt;apiSurfaceOwner&lt;/code&gt; to &lt;code&gt;apiops&lt;/code&gt;, run &lt;code&gt;azd up&lt;/code&gt;, and Bicep stops deploying them. ARM deployments in incremental mode don't delete what a template no longer mentions, so the resources stay where they are. The first publish then PUTs resources with the same names, which updates them in place. There's no second API, the version set keeps both versions, and &lt;code&gt;contoso-shop&lt;/code&gt; keeps its key because the &lt;code&gt;orders-partners&lt;/code&gt; product it belongs to was updated, not recreated.&lt;/p&gt;

&lt;p&gt;Expect two differences. The API is PUT together with its specification, so the operations follow the spec; anything an operation got only in the portal is a candidate to disappear, and a baseline extract before the switch is how you find it. And &lt;code&gt;serviceUrl&lt;/code&gt;, which the artifact leaves out, may or may not survive a PUT that doesn't mention it; the policy routes through &lt;code&gt;orders-func&lt;/code&gt; either way, so the answer changes nothing for a call, but it changes the next extract's diff. Neither has been observed on a live instance for this sample; a dry run and a publish to dev answer both before prod sees anything.&lt;/p&gt;

&lt;h3&gt;
  
  
  Safe to re-run, not a no-op
&lt;/h3&gt;

&lt;p&gt;A full publish, without &lt;code&gt;--commit-id&lt;/code&gt;, PUTs every artifact in the folder every time. Run it twice and the second run writes the same state again: same policies, same products, same links. That makes it safe to re-run after a partial failure (exit code &lt;code&gt;1&lt;/code&gt; means some resources failed and the rest were written). It doesn't make it free. Every policy PUT is a write the gateway picks up, and every resource gets an entry in the activity log, which is why the workflows publish per commit and keep the full publish for a manual run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Full, per commit, and the flag that deletes things
&lt;/h3&gt;

&lt;p&gt;There are four ways to call &lt;code&gt;publish&lt;/code&gt;, and they differ in what they touch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft53nbhe59ayds7xce4kl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ft53nbhe59ayds7xce4kl.png" alt="The four publish modes: what no --commit-id, --commit-id, --commit-id with --delete-unmatched and --delete-unmatched alone publish and delete" width="799" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--commit-id&lt;/code&gt; publishes the changes made by one commit, not everything since it. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-publish.yml" rel="noopener noreferrer"&gt;publish workflow&lt;/a&gt; passes the merged commit (&lt;code&gt;github.sha&lt;/code&gt;), so merge or squash pull requests: a rebase merge of three commits lands as three commits, and only the last one gets published. The &lt;a href="https://github.com/Azure/apiops-cli/blob/main/docs/commands/publish.md" rel="noopener noreferrer"&gt;publish reference&lt;/a&gt; describes it differently ("changed since that commit", with &lt;code&gt;github.event.before&lt;/code&gt; in its example), but the 1.0.5 source diffs &lt;code&gt;&amp;lt;sha&amp;gt;~1&lt;/code&gt; against &lt;code&gt;&amp;lt;sha&amp;gt;&lt;/code&gt;. With that source, &lt;code&gt;github.event.before&lt;/code&gt; would publish the last commit of the previous push, not the one that just landed. I reported the mismatch as &lt;a href="https://github.com/Azure/apiops-cli/issues/333" rel="noopener noreferrer"&gt;apiops-cli#333&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The last row is the dangerous one. Without a commit, &lt;code&gt;--delete-unmatched&lt;/code&gt; lists every non-system resource on the instance and deletes each one the folder doesn't have. In this repo the folder has no backend, no named values, no logger, no global policy and no subscription, so the first such run deletes the platform Bicep built. &lt;a href="https://learn.microsoft.com/azure/api-management/how-to-manage-apiops-cli" rel="noopener noreferrer"&gt;Learn's advice&lt;/a&gt; is to leave the flag out of your first workflow. In this layout, leave it out of every workflow. The CLI refuses to combine it with &lt;code&gt;--filter&lt;/code&gt; anyway, so you can't scope it down to the APIOps-owned types.&lt;/p&gt;

&lt;h3&gt;
  
  
  One set of files, several environments
&lt;/h3&gt;

&lt;p&gt;Dev is the lowest environment, so the artifacts describe it and it gets no override file. Prod gets &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/apiops/configuration.prod.yaml" rel="noopener noreferrer"&gt;&lt;code&gt;configuration.prod.yaml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# yaml-language-server: $schema=https://raw.githubusercontent.com/Azure/apiops-cli/main/schemas/v1/override-config.schema.json&lt;/span&gt;
&lt;span class="na"&gt;products&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;orders-partners&lt;/span&gt;
    &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;subscriptionsLimit&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In dev, a partner can hold as many subscriptions to &lt;code&gt;orders-partners&lt;/code&gt; as a test needs. In prod, each partner gets one key: a second subscription would get the same 60-call budget again and make the product rate limit meaningless. The override merges into the product's &lt;code&gt;productInformation.json&lt;/code&gt; at publish time, so the prod step passes it next to the source:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;&amp;gt;&lt;/span&gt;
          &lt;span class="s"&gt;npx --yes "$APIOPS_CLI" publish&lt;/span&gt;
          &lt;span class="s"&gt;--subscription-id ${{ vars.AZURE_SUBSCRIPTION_ID }}&lt;/span&gt;
          &lt;span class="s"&gt;--resource-group ${{ vars.APIM_RESOURCE_GROUP }}&lt;/span&gt;
          &lt;span class="s"&gt;--service-name ${{ vars.APIM_SERVICE_NAME }}&lt;/span&gt;
          &lt;span class="s"&gt;--source apim-artifacts&lt;/span&gt;
          &lt;span class="s"&gt;--overrides configuration.prod.yaml&lt;/span&gt;
          &lt;span class="s"&gt;--commit-id ${{ github.sha }}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Overrides change properties, never names. &lt;code&gt;orders-partners&lt;/code&gt; is &lt;code&gt;orders-partners&lt;/code&gt; in every environment, and an override can't point an artifact at a differently named resource. An environment that needs other names needs its own artifacts.&lt;/p&gt;

&lt;p&gt;A one-line override file is unusually small for a real API, and the split is the reason. The values that usually fill override files (backend URLs, named values, Key Vault references, logger keys) are all on the Bicep side here, where they're computed per environment from the resources they describe. What's left for APIOps is the API surface, which should look the same everywhere except for deliberate product decisions like this one.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reviewing an API change in a pull request
&lt;/h2&gt;

&lt;p&gt;Here is a change the pull request makes visible. A partner integration asks for a read-only client, and someone adds the role to the token check in &lt;code&gt;apis/orders/policy.xml&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;--- a/ApimOrdersDemo/apiops/apim-artifacts/apis/orders/policy.xml
&lt;/span&gt;&lt;span class="gi"&gt;+++ b/ApimOrdersDemo/apiops/apim-artifacts/apis/orders/policy.xml
&lt;/span&gt;&lt;span class="p"&gt;@@ -14,5 +14,6 @@&lt;/span&gt;
       &amp;lt;required-claims&amp;gt;
         &amp;lt;claim name="roles" match="any"&amp;gt;
           &amp;lt;value&amp;gt;Orders.ReadWrite&amp;lt;/value&amp;gt;
&lt;span class="gi"&gt;+          &amp;lt;value&amp;gt;Orders.Read&amp;lt;/value&amp;gt;
&lt;/span&gt;         &amp;lt;/claim&amp;gt;
       &amp;lt;/required-claims&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One added line, and it reads like a harmless extension. It isn't. &lt;code&gt;match="any"&lt;/code&gt; means a token with only &lt;code&gt;Orders.Read&lt;/code&gt; now passes the check for every operation, including &lt;code&gt;POST /orders&lt;/code&gt;, because the policy sits at API scope. The read-only client can create orders. In the portal, that edit is a save button. In the pull request, it's a line a reviewer can ask about: should the role check move to the operation scope, with &lt;code&gt;create-order&lt;/code&gt; keeping &lt;code&gt;Orders.ReadWrite&lt;/code&gt;?&lt;/p&gt;

&lt;p&gt;The diff shows a second problem by what's missing. &lt;code&gt;apis/orders-v2/policy.xml&lt;/code&gt; holds the same policy and isn't in the change, so the new role works on &lt;code&gt;/sales/orders&lt;/code&gt; and fails on &lt;code&gt;/sales/v2/orders&lt;/code&gt;. With two copies of one policy, the file list of the pull request is part of the review.&lt;/p&gt;

&lt;h3&gt;
  
  
  What should trigger a review
&lt;/h3&gt;

&lt;p&gt;Put a &lt;code&gt;CODEOWNERS&lt;/code&gt; entry on &lt;code&gt;ApimOrdersDemo/apiops/&lt;/code&gt; so every change under it needs an API owner's approval, then read some files more carefully than others:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Any &lt;code&gt;policy.xml&lt;/code&gt;.&lt;/strong&gt; Authentication, rate limits, CORS, caching keys and backend routing all live here, and a one-line change opens or closes the API. A product policy applies to every API in the product.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;specification.yaml&lt;/code&gt;.&lt;/strong&gt; An added operation or optional field is safe. A removed or renamed operation, or a new required field, breaks callers; that's a new version in the version set from Part 4, not an edit.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;apiInformation.json&lt;/code&gt; and &lt;code&gt;productInformation.json&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;path&lt;/code&gt;, &lt;code&gt;subscriptionRequired&lt;/code&gt;, &lt;code&gt;apiVersionSetId&lt;/code&gt;, &lt;code&gt;approvalRequired&lt;/code&gt; and &lt;code&gt;state&lt;/code&gt; decide who can reach the API at all.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;apis.json&lt;/code&gt; and &lt;code&gt;groups.json&lt;/code&gt;.&lt;/strong&gt; &lt;code&gt;orders-free&lt;/code&gt; is auto-approved, so an API added to its &lt;code&gt;apis.json&lt;/code&gt; is open to anyone who signs up in the developer portal.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;configuration.prod.yaml&lt;/code&gt;.&lt;/strong&gt; It only applies in prod, so it's the change dev never tested.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every deleted file.&lt;/strong&gt; With the sample's workflows nothing gets deleted in APIM, which is its own surprise: the API stays live after its folder is gone.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  What the reviewer actually checks
&lt;/h3&gt;

&lt;p&gt;Read a policy change in its scope. A product policy runs for every API in the product; an API policy for every operation; and a narrower policy only runs the broader one where it calls &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; (Part 2). A pull request that adds an operation policy without &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; silently drops the token check for that operation, and the diff shows that as an innocent new file.&lt;/p&gt;

&lt;p&gt;Then open the dry-run check on the pull request and compare its plan with the description. A change described as "raise the partner limit" should plan one &lt;code&gt;PUT ProductPolicy/orders-partners&lt;/code&gt;. If it plans &lt;code&gt;Api/orders&lt;/code&gt; as well, ask why.&lt;/p&gt;

&lt;p&gt;The last checks are about the boundary: no secret and no &lt;code&gt;*** REDACTED ***&lt;/code&gt; in the diff, an override for every value that has to differ in prod, and no file that belongs to a Bicep-owned resource. A pull request that adds &lt;code&gt;apim-artifacts/backends/&lt;/code&gt; is trying to give the backend a second owner.&lt;/p&gt;

&lt;p&gt;When a merged change turns out wrong, the rollback is &lt;code&gt;git revert&lt;/code&gt; and the same publish run, not a fix in the portal. The &lt;a href="https://learn.microsoft.com/azure/architecture/example-scenario/devops/automated-api-deployments-apiops" rel="noopener noreferrer"&gt;Architecture Center&lt;/a&gt; says a revert "still requires validation and a controlled publish", which is the point: the revert goes through the same pull request and dry run as the change it undoes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Drift: when the portal and Git disagree
&lt;/h2&gt;

&lt;p&gt;The baseline only describes the instance on the day you extracted it. After that, the portal is still open, and every edit there is drift. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/.github/workflows/apim-orders-apiops-extract.yml" rel="noopener noreferrer"&gt;extract workflow&lt;/a&gt; is the drift detector. It extracts with the committed filter, &lt;code&gt;--no-transitive&lt;/code&gt; and &lt;code&gt;--remove-stale&lt;/code&gt;, and opens a pull request labelled &lt;code&gt;extract&lt;/code&gt; with whatever differs. The incident from the start comes back in the prod pull request as a one-line diff in &lt;code&gt;products/orders-partners/policy.xml&lt;/code&gt;, 60 against 300. Commit the 300 and the hotfix becomes the committed state. Publish the 60 instead, and the instance goes back to it, this time on purpose.&lt;/p&gt;

&lt;p&gt;It runs every night against both instances, and on demand against the one you pick:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cron&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;17&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;3&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*'&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;inputs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Instance to extract from&lt;/span&gt;
        &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;choice&lt;/span&gt;
        &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;dev&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;prod&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
        &lt;span class="na"&gt;default&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A scheduled run has no inputs, so the job's matrix falls back to both environments, while a manual run gets a one-element list:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;extract&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="c1"&gt;# A scheduled run has no inputs, so it extracts both instances.&lt;/span&gt;
    &lt;span class="na"&gt;strategy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;fail-fast&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
      &lt;span class="na"&gt;matrix&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ fromJSON(inputs.environment &amp;amp;&amp;amp; format('["{0}"]', inputs.environment) || '["dev", "prod"]') }}&lt;/span&gt;

    &lt;span class="c1"&gt;# One run per environment at a time: both would push to the same PR branch.&lt;/span&gt;
    &lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;apiops-extract-${{ matrix.environment }}&lt;/span&gt;
      &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;fail-fast: false&lt;/code&gt; keeps a failed dev extract from cancelling the prod one. A quiet night extracts, finds no diff and opens nothing. A night with drift opens a pull request per instance, from the branch &lt;code&gt;apiops-extract/dev&lt;/code&gt; or &lt;code&gt;apiops-extract/prod&lt;/code&gt;, and the nights after it don't pile up more pull requests: &lt;a href="https://github.com/peter-evans/create-pull-request#action-behaviour" rel="noopener noreferrer"&gt;&lt;code&gt;create-pull-request&lt;/code&gt;&lt;/a&gt; reuses that branch, updates the open pull request with each new extract, and closes it once the instance matches &lt;code&gt;main&lt;/code&gt; again. The &lt;code&gt;concurrency&lt;/code&gt; group sits on the job so it can read the matrix, and keeps a manual run and the nightly one from pushing to the same branch at the same time. The portal fix from the start was made in prod, so it is the prod run that reports it the next morning. That run signs in through a &lt;code&gt;prod-read&lt;/code&gt; environment with a Reader identity instead of &lt;code&gt;prod&lt;/code&gt;: required reviewers apply to every job that names an environment, even one that only reads and &lt;a href="https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/control-deployments#using-environments-without-deployments" rel="noopener noreferrer"&gt;sets &lt;code&gt;deployment: false&lt;/code&gt;&lt;/a&gt;, and the nightly extract would otherwise wait for an approval every night. GitHub &lt;a href="https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#schedule" rel="noopener noreferrer"&gt;runs schedules from the default branch only&lt;/a&gt;, and in a public repository it disables them after 60 days without activity.&lt;/p&gt;

&lt;p&gt;Three details decide whether the drift pull request tells the truth:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The prod pull request is never clean.&lt;/strong&gt; The artifacts describe dev, and &lt;code&gt;extract&lt;/code&gt; has no &lt;code&gt;--overrides&lt;/code&gt; option: it writes what the instance returns and can neither apply nor strip &lt;code&gt;configuration.prod.yaml&lt;/code&gt;. Every prod extract shows &lt;code&gt;subscriptionsLimit: 1&lt;/code&gt; as a change, plus the values that name the instance once a live dev extract has been committed. That's the override, not drift. Leave the prod pull request open as a standing report, never merge it, and move the real drift, like the 300, into a branch of its own.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Per-commit publishing leaves drift alone until it doesn't.&lt;/strong&gt; A portal edit to a resource no commit touches survives every &lt;code&gt;--commit-id&lt;/code&gt; publish. The next commit that changes that file, or the next full publish, overwrites it without a word. Extract before that happens, not after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The drift pull request has no dry run until someone pushes to it.&lt;/strong&gt; The workflow opens it with the default &lt;code&gt;GITHUB_TOKEN&lt;/code&gt;, and &lt;a href="https://docs.github.com/en/actions/concepts/security/github_token#when-github_token-triggers-workflow-runs" rel="noopener noreferrer"&gt;events created with that token don't start other workflows&lt;/a&gt;. Pushing a commit to the branch starts the check, but only until the next night: the next run rebuilds the branch from &lt;code&gt;main&lt;/code&gt; and force-pushes it, and the hand-pushed commit is gone. Switching &lt;code&gt;create-pull-request&lt;/code&gt; to a GitHub App token gets the check on every update.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bicep and APIOps on the same instance: who owns what
&lt;/h2&gt;

&lt;p&gt;Microsoft's &lt;a href="https://learn.microsoft.com/azure/architecture/example-scenario/devops/automated-api-deployments-apiops#alternatives" rel="noopener noreferrer"&gt;Architecture Center&lt;/a&gt; doesn't make you pick one tool: infrastructure as code and APIOps "can serve different parts of the same solution", and APIOps fits when API definitions and policies "have separate owners or a release lifecycle that's independent of the service infrastructure". What it doesn't say loudly is that neither tool notices the other. If both deploy the same policy, the later one wins, and nothing warns either side.&lt;/p&gt;

&lt;p&gt;So the sample gives every resource exactly one owner:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwljbvbsbj9lybfn3mx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fcwljbvbsbj9lybfn3mx2.png" alt="Resource ownership on the order API's instance: Bicep keeps the platform, APIOps owns the version set, both APIs with their policies, and both products" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The switch is one parameter in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/apim.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;apim.bicep&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Part 5: with 'apiops', the version set, both APIs with their policies, and both products with their&lt;/span&gt;
&lt;span class="c1"&gt;// policies and links come from `apiops publish` instead. Bicep keeps the platform either way.&lt;/span&gt;
&lt;span class="nd"&gt;@allowed&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'bicep'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'apiops'&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;span class="k"&gt;param&lt;/span&gt; &lt;span class="n"&gt;apiSurfaceOwner&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'bicep'&lt;/span&gt;

&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;bicepOwnsApiSurface&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;apiSurfaceOwner&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'bicep'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every API-surface resource carries the condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersApiPolicy&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/apis/policies@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bicepOwnsApiSurface&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersApi&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'policy'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'rawxml'&lt;/span&gt;
    &lt;span class="py"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;loadTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'../apiops/apim-artifacts/apis/orders/policy.xml'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="py"&gt;dependsOn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ordersBackend&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;namedValues&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The boundary isn't perfectly clean, and the diagnostics show where. The Application Insights diagnostic on &lt;code&gt;orders&lt;/code&gt; is a child of the API, and the API is APIOps-owned. It stays in Bicep because the logger it points at is Bicep's, so it hangs off an &lt;code&gt;existing&lt;/code&gt; reference to &lt;code&gt;orders&lt;/code&gt; by name instead of the conditional resource. The &lt;code&gt;contoso-shop&lt;/code&gt; subscription has the same shape: Bicep owns it, but its scope is the APIOps-owned &lt;code&gt;orders-partners&lt;/code&gt; product.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Gotcha: a fresh environment in &lt;code&gt;apiops&lt;/code&gt; mode can't deploy in one pass.&lt;/strong&gt; Bicep's diagnostic needs the &lt;code&gt;orders&lt;/code&gt; API and its &lt;code&gt;contoso-shop&lt;/code&gt; subscription needs the &lt;code&gt;orders-partners&lt;/code&gt; product. In &lt;code&gt;apiops&lt;/code&gt; mode Bicep doesn't create either, and the publisher needs the backend and named values Bicep creates. On an empty resource group, the Bicep deploy fails on those two resources. Deploy once in &lt;code&gt;bicep&lt;/code&gt; mode and then switch, or run the Bicep deploy, publish, and deploy again. The sample documents this instead of splitting &lt;code&gt;apim.bicep&lt;/code&gt; into two deployments; the split would be the cleaner fix for a team that creates environments often.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Policies hide a dependency in the other direction. The API policy reads &lt;code&gt;{{tenant-id}}&lt;/code&gt; and three app IDs and routes to &lt;code&gt;orders-func&lt;/code&gt;, all Bicep-owned. Publishing a policy that references a named value the instance doesn't have yet fails, so on any new instance Bicep goes first. Whether the dry run already reports a missing named value or only the real PUT fails is not something I could check without an instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  Already on the APIOps Toolkit?
&lt;/h2&gt;

&lt;p&gt;The Toolkit (the separate &lt;code&gt;extractor&lt;/code&gt; and &lt;code&gt;publisher&lt;/code&gt; binaries, configured through environment variables) still works, and the &lt;a href="https://learn.microsoft.com/azure/architecture/example-scenario/devops/automated-api-deployments-apiops" rel="noopener noreferrer"&gt;Architecture Center&lt;/a&gt; now calls it legacy and tells you to plan the upgrade as a controlled cutover. The concepts map one to one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwkw74zn3jedu4no55shg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwkw74zn3jedu4no55shg.png" alt="APIOps Toolkit to APIOps CLI mapping: extractor and publisher binaries, CONFIGURATION_YAML_PATH, COMMIT_ID and the CLI-only flags" width="714" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;COMMIT_ID&lt;/code&gt; and &lt;code&gt;--commit-id&lt;/code&gt; publish the same thing, the changes made by that commit. They differ on deletions: the Toolkit &lt;a href="https://github.com/Azure/apiops/blob/5b3d0e0733229c83a589dbba0ae22120fdbc740d/src/publisher/Resource.cs#L80" rel="noopener noreferrer"&gt;reads the files a commit deleted from the parent commit&lt;/a&gt; and deletes those resources in APIM, and the CLI only does with &lt;code&gt;--delete-unmatched&lt;/code&gt;. A pipeline that relies on deleting a folder to remove an API stops doing that after the switch, quietly. The Toolkit's commit mode also publishes every artifact the override file names, changed or not; the CLI doesn't.&lt;/p&gt;

&lt;p&gt;The folder layout is the part to test rather than trust. Toolkit trees use names with spaces (&lt;code&gt;named values/&lt;/code&gt;, &lt;code&gt;version sets/&lt;/code&gt;) and folder-per-link products, and the 1.0.5 source only reads the camel-case names. Run the CLI's &lt;code&gt;publish --dry-run&lt;/code&gt; against your existing tree before you change the pipeline. If the plan is missing resources you know are there, re-extract with the CLI into a new folder and review that diff as the new baseline.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The 60 came back because one policy had two writers and nothing recorded the second one. APIOps fixes the record: every change to the API surface is a file in a pull request, and every portal edit comes back as one through the extract. Bicep keeping the platform fixes the writers, and it's the reason this repo has no secrets and a prod override file with one line in it. The cost is a boundary you have to hold on purpose: &lt;code&gt;--no-transitive&lt;/code&gt; on every extract, &lt;code&gt;--delete-unmatched&lt;/code&gt; on none, and an ordering step for new environments.&lt;/p&gt;

&lt;p&gt;Part 6 turns the two workflows into the full pipeline: the dry run as a required check, dev on merge, prod behind an environment approval, signed in through OIDC with a managed identity.&lt;/p&gt;

&lt;p&gt;Does your API Management configuration live in Git today, or does the instance still hold the only copy?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azureapimanagement</category>
      <category>ops</category>
      <category>infrastructureascode</category>
    </item>
    <item>
      <title>Azure API Management Developer Portal and API Versioning: Version Sets Without Breaking Callers</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 30 Oct 2026 06:46:40 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-api-management-developer-portal-and-api-versioning-version-sets-without-breaking-callers-40em</link>
      <guid>https://dev.to/martin_oehlert/azure-api-management-developer-portal-and-api-versioning-version-sets-without-breaking-callers-40em</guid>
      <description>&lt;p&gt;How do you ship a breaking change to the order API without breaking the partners who already call it, when the next partner should find the API in the developer portal, read the docs and get a key without opening a ticket? The versioning half has a trap that decides the rest: API Management fixes the versioning scheme for every version in a version set the moment you add the first one, and the live API keeps its URL only if it stays the &lt;strong&gt;Original&lt;/strong&gt; version. Give it a &lt;code&gt;v1&lt;/code&gt; identifier and every existing call stops matching. The short answer for the order API: path versioning, the live API kept as Original, &lt;code&gt;v2&lt;/code&gt; only for the breaking change, revisions for everything else, and two products so a free tier and partners get different limits and only partners need approval.&lt;/p&gt;

&lt;p&gt;After Part 3 the order API is locked down and nobody can find it. There is one product, one subscription that Bicep created for a partner called Contoso Shop, and an Entra ID token check in front of every operation. A new partner learns the API exists from an email, gets the OpenAPI file as an attachment and waits for someone to create a key. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt; now enables the &lt;strong&gt;developer portal&lt;/strong&gt;, adds a global CORS policy so the portal's test console can reach the gateway, puts the existing API into a path-based version set next to a &lt;code&gt;v2&lt;/code&gt; with a paged &lt;code&gt;list-orders&lt;/code&gt;, and splits access into an auto-approved free product and a partner product that needs approval. The instance is still Basic v2, and that has two consequences: the portal is off until you turn it on, and the managed portal can't host custom widgets. The Bicep and the function project build clean; none of it has been deployed yet, so where the article depends on how a live instance behaves, it says so and points to the check in the repo's &lt;code&gt;scripts/verify.sh&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the developer portal builds from your OpenAPI file
&lt;/h2&gt;

&lt;p&gt;The portal's API reference is the OpenAPI file you imported in Part 1, rendered. This is &lt;code&gt;list-orders&lt;/code&gt; in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/openapi/orders.yaml" rel="noopener noreferrer"&gt;&lt;code&gt;openapi/orders.yaml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;/orders&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;operationId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;list-orders&lt;/span&gt;
      &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;List orders&lt;/span&gt;
      &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Returns all orders, newest first. Filter with `status`.&lt;/span&gt;
      &lt;span class="na"&gt;parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;status&lt;/span&gt;
          &lt;span class="na"&gt;in&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;query&lt;/span&gt;
          &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Only orders in this status.&lt;/span&gt;
          &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;$ref&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;#/components/schemas/OrderStatus'&lt;/span&gt;
      &lt;span class="na"&gt;responses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;200'&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Orders, newest first.&lt;/span&gt;
          &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;application/json&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;array&lt;/span&gt;
                &lt;span class="na"&gt;items&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
                  &lt;span class="na"&gt;$ref&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;#/components/schemas/Order'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Learn calls the portal "an automatically generated, fully customizable website with the documentation of your APIs", and "out of the box, the developer portal is already populated with your published APIs and products" (&lt;a href="https://learn.microsoft.com/azure/api-management/developer-portal-overview" rel="noopener noreferrer"&gt;overview&lt;/a&gt;). For the order API that means a list of APIs, a reference page per operation built from the imported definition (method, URL, parameters, request and response schemas), a products page, sign-up and sign-in, and a profile page where a signed-in developer sees their subscription keys. Nobody writes these pages; they change when the API definition changes.&lt;/p&gt;

&lt;p&gt;Three defaults decide what a visitor gets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Only published products show up.&lt;/strong&gt; A product's &lt;code&gt;state: 'published'&lt;/code&gt; makes it discoverable in the portal, and that's all it does. Learn is explicit that the gateway doesn't care: "Regardless of whether the product is published, all of the product's APIs are accessible for requests via the API Management gateway" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-add-products" rel="noopener noreferrer"&gt;products&lt;/a&gt;). Unpublishing a product hides it from new developers; it doesn't revoke a single key.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The profile page only lists product keys.&lt;/strong&gt; "Currently, the developer portal only shows the product scope subscriptions under the &lt;strong&gt;User Profile&lt;/strong&gt; section" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" rel="noopener noreferrer"&gt;subscriptions&lt;/a&gt;). A subscription scoped to one API or to all APIs works at the gateway and is invisible to its owner in the portal. If developers are meant to manage their own keys, scope every subscription to a product.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anyone can read it.&lt;/strong&gt; "By default, the developer portal enables anonymous access." Anonymous visitors are in the built-in Guests group and see the pages and the products made visible to Guests, until you switch on the site setting that requires sign-in. For many partner APIs that's fine, since the docs aren't the secret; the keys are. If the API's shape is itself confidential, keep its products away from Guests and require sign-in before the first publish, not after.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Sign-up uses API Management's own user accounts by default; Entra ID and Entra External ID sign-in are the alternatives (not on the classic Basic tier or Consumption). A user who signs up lands in the built-in Developers group, and which products a developer can see is decided per group. The products section below uses that to keep the partner product out of sight for everyone outside a &lt;code&gt;partners&lt;/code&gt; group.&lt;/p&gt;

&lt;h3&gt;
  
  
  Turning it on in Basic v2
&lt;/h3&gt;

&lt;p&gt;On the classic tiers the portal exists from the moment the instance does. On v2 tiers it doesn't: "If you created your instance in a v2 service tier, first enable the developer portal" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-developer-portal-customize" rel="noopener noreferrer"&gt;customize&lt;/a&gt;). In the Azure portal that's &lt;strong&gt;Developer portal &amp;gt; Portal settings &amp;gt; Enabled &amp;gt; Save&lt;/strong&gt;, which "might take a few minutes". In Bicep it's one property on the service in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/apim.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;infra/apim.bicep&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;  &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;publisherEmail&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;publisherEmail&lt;/span&gt;
    &lt;span class="py"&gt;publisherName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders demo'&lt;/span&gt;
    &lt;span class="c1"&gt;// v2 tiers create the instance with the portal off; Consumption has no portal at all.&lt;/span&gt;
    &lt;span class="py"&gt;developerPortalStatus&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apimSku&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'Consumption'&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="py"&gt;null&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Enabled'&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;developerPortalStatus&lt;/code&gt; takes &lt;code&gt;'Enabled'&lt;/code&gt; or &lt;code&gt;'Disabled'&lt;/code&gt; in resource API version &lt;code&gt;2024-05-01&lt;/code&gt;, which the sample already uses (&lt;a href="https://learn.microsoft.com/azure/templates/microsoft.apimanagement/2024-05-01/service" rel="noopener noreferrer"&gt;template reference&lt;/a&gt;). The sample's &lt;code&gt;apimSku&lt;/code&gt; parameter still allows Consumption, and Consumption is the one tier without a managed portal, so the property is &lt;code&gt;null&lt;/code&gt; there instead of asking for something the tier can't do.&lt;/p&gt;

&lt;p&gt;Learn says the enable step works on every v2 tier. One &lt;a href="https://learn.microsoft.com/answers/a/2000124" rel="noopener noreferrer"&gt;Microsoft Q&amp;amp;A answer&lt;/a&gt; (not documentation) reports an instance where the option was missing on Basic v2. This sample hasn't been deployed with the property yet, so treat Learn as the authority and check your own instance: after the deployment, &lt;strong&gt;Portal overview&lt;/strong&gt; in the Azure portal should show the portal URL, &lt;code&gt;https://&amp;lt;service name&amp;gt;.developer.azure-api.net&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Enabling the portal doesn't make it visible. The portal content has to be published, and the first publish is a manual step: open &lt;strong&gt;Portal overview&lt;/strong&gt;, select &lt;strong&gt;Developer portal&lt;/strong&gt; to open it in the administrative interface, then &lt;strong&gt;Publish&lt;/strong&gt;. The same rule applies to every later change, because "Saved changes are visible only to you and aren't visible to portal visitors until you publish them." Learn also lists service changes that need a republish: a custom domain, identity providers, delegation, sign-in and product terms. Changes to an API definition are not on that list. That fits Learn's split between portal content (pages, styles, layouts) and API Management data (APIs, operations, products), but it's an inference; republish once after the first import and check. No Learn page shows publishing from Bicep, so the sample leaves it as a README step.&lt;/p&gt;

&lt;h3&gt;
  
  
  Descriptions and examples that end up on the page
&lt;/h3&gt;

&lt;p&gt;Learn doesn't enumerate which OpenAPI fields the reference page renders, so the sample fills in the ones a partner would look for, and you check the result on your instance before relying on any of them. The order spec now carries three kinds of text:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an operation &lt;code&gt;description&lt;/code&gt; that says what the call returns and how to filter it,&lt;/li&gt;
&lt;li&gt;a &lt;code&gt;description&lt;/code&gt; on each parameter, which is where a partner looks to find out what &lt;code&gt;status&lt;/code&gt; filters on,&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;example&lt;/code&gt; values on schema properties, from &lt;code&gt;components.schemas&lt;/code&gt; in the same file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;      &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;sku&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;quantity&lt;/span&gt;&lt;span class="pi"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;unitPrice&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
      &lt;span class="na"&gt;properties&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;sku&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;string&lt;/span&gt;
          &lt;span class="na"&gt;example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;BOOK-0042&lt;/span&gt;
        &lt;span class="na"&gt;quantity&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;integer&lt;/span&gt;
          &lt;span class="na"&gt;minimum&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
          &lt;span class="na"&gt;example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
        &lt;span class="na"&gt;unitPrice&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;number&lt;/span&gt;
          &lt;span class="na"&gt;format&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;decimal&lt;/span&gt;
          &lt;span class="na"&gt;example&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;24.90&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Write these for the person reading the portal, not for the code generator. &lt;code&gt;Only orders in this status.&lt;/code&gt; is short, but it answers the question a partner has at that spot; a description that repeats the parameter name in a sentence answers nothing. The examples matter more than they look: a developer copies them into their first request, so keep the set consistent (the same &lt;code&gt;BOOK-0042&lt;/code&gt; everywhere).&lt;/p&gt;

&lt;p&gt;Two more texts reach the portal without touching the spec. When you make a revision current, the optional change log "is included in the developer portal for your API users to view" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-revisions" rel="noopener noreferrer"&gt;revisions&lt;/a&gt;), which is the only release-notes channel the portal has built in. And each API version carries its own spec, so the &lt;code&gt;v2&lt;/code&gt; reference page documents the page envelope while the Original keeps documenting the array; the versioning section below covers how the two coexist.&lt;/p&gt;

&lt;h2&gt;
  
  
  The try-it console and the CORS error everyone hits
&lt;/h2&gt;

&lt;p&gt;Every operation page has a &lt;strong&gt;Try it&lt;/strong&gt; button. It opens a console that fills in the request URL, takes a subscription key (a signed-in developer can pick one of their own), lets you set parameters and headers, and sends the call. Learn lists three authorization models for it: no authorization, a subscription key, and OAuth 2.0, where "you can configure the test console to generate a valid OAuth token on behalf of the test console user".&lt;/p&gt;

&lt;p&gt;The first time someone selects &lt;strong&gt;Send&lt;/strong&gt; against a fresh instance, the browser shows a CORS error and nothing reaches the API. The console is JavaScript running on &lt;code&gt;https://&amp;lt;service name&amp;gt;.developer.azure-api.net&lt;/code&gt; and calling &lt;code&gt;https://&amp;lt;service name&amp;gt;.azure-api.net&lt;/code&gt;, a different origin. The subscription key travels in the &lt;code&gt;Ocp-Apim-Subscription-Key&lt;/code&gt; header, a custom header, so the browser first sends an &lt;code&gt;OPTIONS&lt;/code&gt; preflight asking whether the portal's origin may send it. Without a &lt;code&gt;cors&lt;/code&gt; policy the gateway's answer carries no &lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;, and the browser stops there. Learn: "If the developer portal's domain name isn't an allowed origin for cross-domain API requests, test console users will see a CORS error" (&lt;a href="https://learn.microsoft.com/azure/api-management/enable-cors-developer-portal" rel="noopener noreferrer"&gt;enable CORS&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The fix is a &lt;code&gt;cors&lt;/code&gt; policy at the top of the global policy, &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/policies/global.xml" rel="noopener noreferrer"&gt;&lt;code&gt;infra/policies/global.xml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;cors&lt;/span&gt; &lt;span class="na"&gt;allow-credentials=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;allowed-origins&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;origin&amp;gt;&lt;/span&gt;{{portal-origin}}&lt;span class="nt"&gt;&amp;lt;/origin&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/allowed-origins&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;allowed-methods&lt;/span&gt; &lt;span class="na"&gt;preflight-result-max-age=&lt;/span&gt;&lt;span class="s"&gt;"300"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;method&amp;gt;&lt;/span&gt;*&lt;span class="nt"&gt;&amp;lt;/method&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/allowed-methods&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;allowed-headers&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;*&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/allowed-headers&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;expose-headers&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;header&amp;gt;&lt;/span&gt;*&lt;span class="nt"&gt;&amp;lt;/header&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/expose-headers&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/cors&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The origin comes from a named value, built in &lt;code&gt;apim.bicep&lt;/code&gt; from the instance name and added to the named values the policies already read:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The default portal host; add a custom portal domain here too, or the try-it console gets a CORS error there.&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;portalOrigin&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;apim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;.developer.azure-api.net'&lt;/span&gt;

&lt;span class="c1"&gt;// Plain (non-secret) values the policies read as {{name}}: IDs and the portal origin, not credentials.&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;policyNamedValues&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="s1"&gt;'tenant-id'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt;
  &lt;span class="s1"&gt;'orders-api-app-id'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersApiAppId&lt;/span&gt;
  &lt;span class="s1"&gt;'orders-backend-app-id'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;backendAppId&lt;/span&gt;
  &lt;span class="s1"&gt;'orders-test-client-app-id'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;testClientAppId&lt;/span&gt;
  &lt;span class="s1"&gt;'portal-origin'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;portalOrigin&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What each part of the policy decides:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;One origin, not &lt;code&gt;*&lt;/code&gt;.&lt;/strong&gt; The &lt;a href="https://learn.microsoft.com/azure/api-management/cors-policy" rel="noopener noreferrer"&gt;&lt;code&gt;cors&lt;/code&gt; policy reference&lt;/a&gt; wants a full URI with scheme and host for each &lt;code&gt;origin&lt;/code&gt;, and warns that &lt;code&gt;*&lt;/code&gt; "may be overly permissive". Allowing every origin would let any website call your API from a visitor's browser with whatever key that page holds. With a custom domain on the portal, add its origin as a second &lt;code&gt;&amp;lt;origin&amp;gt;&lt;/code&gt;; the custom domain setup can add it for you.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;allow-credentials="false"&lt;/code&gt;.&lt;/strong&gt; The console sends the key and, with OAuth, the token as headers. It has no cookies to send to the gateway, so there is no reason to allow them. This is the policy's default; it's spelled out so nobody flips it to &lt;code&gt;true&lt;/code&gt; while debugging.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Methods and headers &lt;code&gt;*&lt;/code&gt;.&lt;/strong&gt; The console sends whatever the operation needs: &lt;code&gt;POST&lt;/code&gt; with &lt;code&gt;Content-Type&lt;/code&gt; for &lt;code&gt;create-order&lt;/code&gt;, the key header, &lt;code&gt;Authorization&lt;/code&gt;. Listing them one by one is tighter, and it's also the list you forget to update when the next API arrives on the same instance.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;At the top of &lt;code&gt;inbound&lt;/code&gt;, before everything else.&lt;/strong&gt; Learn's troubleshooting list warns of "unexpected behavior if the &lt;code&gt;cors&lt;/code&gt; policy is not the first policy in the inbound section". It also documents why the Part 3 token check doesn't break the preflight: "Only the &lt;code&gt;cors&lt;/code&gt; policy is evaluated on the &lt;code&gt;OPTIONS&lt;/code&gt; request during preflight. Remaining configured policies are evaluated on the approved request." The &lt;code&gt;OPTIONS&lt;/code&gt; call carries no key and no token, and it doesn't need to.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Global, not per API, and only once.&lt;/strong&gt; The portal's own &lt;strong&gt;Enable CORS&lt;/strong&gt; button on &lt;strong&gt;Portal overview&lt;/strong&gt; writes the same kind of policy at the global scope, for all APIs, and that's the right place for it: the &lt;code&gt;v2&lt;/code&gt; API and every later API inherit it. Take the warning on Learn's portal page literally: "Only one CORS policy is executed. If you specify multiple CORS policies (for example, on the API level and on the all-APIs level), your interactive console may not work as expected." The &lt;code&gt;cors&lt;/code&gt; reference says you may configure it at more than one scope, which reads like a contradiction until you note that "generally, only the first &lt;code&gt;cors&lt;/code&gt; policy is applied". Keep one, globally, and you never have to work out which one won.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Never on the product.&lt;/strong&gt; Putting the policy on &lt;code&gt;orders-partners&lt;/code&gt; looks tidy, since only partners should use the console. It doesn't work: "If you apply the CORS policy in the Product scope, instead of the API(s) scope, and your API uses subscription key authentication through a header, your console won't work." The preflight carries no subscription key, so API Management can't tell which product the call belongs to, and a product-scoped policy never runs for it. Learn's workaround is the key in the query string, which Part 1 argued against: the key ends up in every access log between the browser and the gateway. Move the policy to global scope instead.&lt;/p&gt;

&lt;p&gt;When the gateway itself isn't reachable from the browser (a network-isolated instance), the console can route its calls through the portal's backend instead: the &lt;strong&gt;Operation: Details&lt;/strong&gt; widget has a &lt;strong&gt;Use CORS proxy&lt;/strong&gt; setting, and after saving you republish the portal. That needs no &lt;code&gt;cors&lt;/code&gt; policy at all, at the price of the portal backend making the calls for you.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;scripts/verify.sh&lt;/code&gt; sends both preflights after a deployment (cases P4 and P5): one from the portal origin, which should come back &lt;code&gt;200&lt;/code&gt; with &lt;code&gt;Access-Control-Allow-Origin&lt;/code&gt;, and one from &lt;code&gt;https://example.com&lt;/code&gt;, which should get an empty &lt;code&gt;200&lt;/code&gt; without that header, the policy's documented behaviour for an origin it doesn't match.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Entra token the console doesn't have
&lt;/h3&gt;

&lt;p&gt;With CORS fixed, the order API's console call still fails, now with a 401. Part 3 put &lt;code&gt;validate-azure-ad-token&lt;/code&gt; on the API, and the console sends a subscription key and nothing else. That's the same call as case V2 in the verify script: key, no token, rejected at the gateway. The &lt;code&gt;v2&lt;/code&gt; API from the versioning section reuses the same API policy file, on purpose: a new version shouldn't be a way around the token check.&lt;/p&gt;

&lt;p&gt;The console can get a token, through &lt;strong&gt;OAuth 2.0 user authorization&lt;/strong&gt; (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-oauth2" rel="noopener noreferrer"&gt;Learn&lt;/a&gt;). You register a second Entra app that represents the console, add an OAuth 2.0 authorization server to API Management pointing at Entra ID, and select that server in the API's settings. The console then shows an authorization drop-down, signs the developer in with the authorization code flow and adds the &lt;code&gt;Authorization&lt;/code&gt; header to the call. As Part 3 quoted from the same page, this "only enables the developer portal's test console (and the test console in the Azure portal) as a client to acquire a token"; validating the token stays the policy's job.&lt;/p&gt;

&lt;p&gt;Even with OAuth set up, Part 3's policy would still reject the console's token, because it was written for partner backends that call as themselves.&lt;/p&gt;

&lt;p&gt;Two checks get in the way. Part 3's policy pins the calling app in &lt;code&gt;client-application-ids&lt;/code&gt; to the test client, and the console's token is issued to the console's own app, so its &lt;code&gt;azp&lt;/code&gt; is the wrong app ID. The policy also requires &lt;code&gt;Orders.ReadWrite&lt;/code&gt; in &lt;code&gt;roles&lt;/code&gt;, and that role is defined with &lt;code&gt;allowedMemberTypes: ['Application']&lt;/code&gt;, so no signed-in developer can be assigned it.&lt;/p&gt;

&lt;p&gt;The console keeps getting a 401 until the policy accepts the console app's ID and the role (or a separate one) allows user assignments. That follows from the claims Part 3 walked through, not from a Learn page about the console, and it hasn't been tested here.&lt;/p&gt;

&lt;p&gt;This article doesn't show the console calling the order API. Every step above needs at least one more app registration, and the tenant the sample is built in doesn't allow users to create them, the same constraint that kept Part 3's token checks a runbook. With a subscription key alone, the console works for any API that doesn't check a token. For the order API, the options are OAuth configured as above, or reference pages whose console can't complete a call to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Versioning: one scheme per version set, chosen once
&lt;/h2&gt;

&lt;p&gt;"Turning on versioning" in API Management means creating a &lt;strong&gt;version set&lt;/strong&gt;, and a version set holds very little: a display name and a scheme. The versions themselves are ordinary APIs. "Each version of an API is maintained as its own API resource and is associated with a version set" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-versions" rel="noopener noreferrer"&gt;versions&lt;/a&gt;), so &lt;code&gt;v2&lt;/code&gt; of the order API isn't a flag on the existing API. It's a second API resource with its own spec, operations and policies that shares a path and a portal entry with the first.&lt;/p&gt;

&lt;p&gt;The scheme is the part you can't take back. "All versions in a version set have the same versioning scheme. It's based on the versioning scheme that's used when you first add a version to an API." There is no migration from header to path later. A different scheme means a new version set, and a new version set means every caller changes how they ask for a version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Path: the version in every log line
&lt;/h3&gt;

&lt;p&gt;The sample's version set in &lt;code&gt;infra/apim.bicep&lt;/code&gt;. ARM calls path versioning &lt;code&gt;Segment&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Path versioning (Segment in ARM), fixed for every version in the set by the first one.&lt;/span&gt;
&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersVersionSet&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/apiVersionSets@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders API'&lt;/span&gt;
    &lt;span class="py"&gt;versioningScheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Segment'&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The existing API from Part 1 joins it with one new property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The Original version: in the set, but no apiVersion, so existing callers keep /sales/orders.&lt;/span&gt;
&lt;span class="c1"&gt;// Giving it apiVersion: 'v1' would move it to /sales/v1/orders and break every existing call.&lt;/span&gt;
&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersApi&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/apis@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders API'&lt;/span&gt;
    &lt;span class="py"&gt;apiVersionSetId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersVersionSet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
    &lt;span class="py"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'sales'&lt;/span&gt;
    &lt;span class="py"&gt;protocols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'https'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="py"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'openapi'&lt;/span&gt;
    &lt;span class="py"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;loadTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'../openapi/orders.yaml'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="py"&gt;serviceUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;functionBaseUrl&lt;/span&gt;
    &lt;span class="py"&gt;subscriptionRequired&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There's deliberately no &lt;code&gt;apiVersion&lt;/code&gt; line. Without it, the API is the &lt;strong&gt;Original&lt;/strong&gt;: "If you add a version to a non-versioned API, an &lt;code&gt;Original&lt;/code&gt; version will be automatically created and will respond on the default URL, without a version identifier specified. The &lt;code&gt;Original&lt;/code&gt; version ensures that any existing callers aren't affected." &lt;code&gt;/sales/orders&lt;/code&gt; keeps answering, and every partner integration keeps working without a release on their side.&lt;/p&gt;

&lt;p&gt;Adding &lt;code&gt;apiVersion: 'v1'&lt;/code&gt; next to &lt;code&gt;v2&lt;/code&gt; looks tidier, and it's the trap from the introduction. An API with an identifier answers only on its versioned URL, so the live API moves to &lt;code&gt;/sales/v1/orders&lt;/code&gt;. The deployment is green, and every existing call to &lt;code&gt;/sales/orders&lt;/code&gt; now matches no API at all. Learn doesn't document the status code for a call that matches no version, so &lt;code&gt;verify.sh&lt;/code&gt; case P3 calls &lt;code&gt;/sales/v9/orders&lt;/code&gt; and prints whatever comes back rather than asserting a number.&lt;/p&gt;

&lt;p&gt;Learn describes the Original for the Azure portal's flow, where the existing API is linked to the set "but a version identifier doesn't need to be specified". It doesn't show the ARM form. Leaving &lt;code&gt;apiVersion&lt;/code&gt; out is the direct translation, and the Bicep builds, but whether a deployed instance keeps the Original on its old URL is what case P1 checks, and P1 hasn't run. If ARM insists on an identifier, the README's fallback is &lt;code&gt;v1&lt;/code&gt;, with the URL change announced to partners before the deploy rather than discovered by them after it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;v2&lt;/code&gt; is the second API resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// v2 breaks one contract: list-orders returns a page envelope. Same path, identifier in the URL: /sales/v2/orders.&lt;/span&gt;
&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersApiV2&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/apis@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-v2'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders API'&lt;/span&gt;
    &lt;span class="py"&gt;apiVersionSetId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersVersionSet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
    &lt;span class="py"&gt;apiVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'v2'&lt;/span&gt;
    &lt;span class="py"&gt;apiVersionDescription&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'list-orders returns a page of orders ({ items, nextLink &lt;/span&gt;&lt;span class="err"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;) instead of an array.'&lt;/span&gt;
    &lt;span class="py"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'sales'&lt;/span&gt;
    &lt;span class="py"&gt;protocols&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'https'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="py"&gt;format&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'openapi'&lt;/span&gt;
    &lt;span class="py"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;loadTextContent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'../openapi/orders-v2.yaml'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="py"&gt;serviceUrl&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;functionBaseUrl&lt;/span&gt;
    &lt;span class="py"&gt;subscriptionRequired&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="c1"&gt;// Two APIs on one path only work inside a version set, so the Original has to join it first.&lt;/span&gt;
  &lt;span class="py"&gt;dependsOn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ordersApi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Same &lt;code&gt;path&lt;/code&gt;, same version set, identifier &lt;code&gt;v2&lt;/code&gt;: the gateway serves it at &lt;code&gt;/sales/v2/orders&lt;/code&gt;. The &lt;code&gt;dependsOn&lt;/code&gt; exists because two APIs may share &lt;code&gt;sales&lt;/code&gt; only as members of one version set. ARM would otherwise be free to create &lt;code&gt;orders-v2&lt;/code&gt; while the Original is still a standalone API on that path.&lt;/p&gt;

&lt;p&gt;The breaking change lives in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/openapi/orders-v2.yaml" rel="noopener noreferrer"&gt;&lt;code&gt;openapi/orders-v2.yaml&lt;/code&gt;&lt;/a&gt;: &lt;code&gt;list-orders&lt;/code&gt; returns &lt;code&gt;{ "items": [...], "nextLink": "orders?skip=50" }&lt;/code&gt; instead of a bare array. Every client that deserialises the response into a list breaks on that, which is what makes it a version and not a revision. The function app gets one new function, &lt;code&gt;list-orders-v2&lt;/code&gt; on route &lt;code&gt;v2/orders&lt;/code&gt;, and the v2 operation gets a policy that sends it there:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rewrite-uri&lt;/span&gt; &lt;span class="na"&gt;template=&lt;/span&gt;&lt;span class="s"&gt;"/v2/orders"&lt;/span&gt; &lt;span class="na"&gt;copy-unmatched-params=&lt;/span&gt;&lt;span class="s"&gt;"true"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;copy-unmatched-params&lt;/code&gt; carries &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;skip&lt;/code&gt; over to the rewritten URL. Everything else in v2 (the other two operations, the API policy, the token check) is the same as in the Original.&lt;/p&gt;

&lt;p&gt;Path versioning costs you clean resource URLs: &lt;code&gt;/sales/v2/orders&lt;/code&gt; and &lt;code&gt;/sales/orders&lt;/code&gt; are the same orders. In return the version is in every access log line, every bug report that pastes a URL, and every &lt;code&gt;curl&lt;/code&gt; a partner sends to support. For server-to-server partners on mixed stacks, I'd take that visibility over clean URLs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Header: clean URLs, invisible version
&lt;/h3&gt;

&lt;p&gt;The sample doesn't use it, but the version set would differ in two properties (&lt;a href="https://learn.microsoft.com/azure/templates/microsoft.apimanagement/2024-05-01/service/apiversionsets" rel="noopener noreferrer"&gt;apiVersionSets reference&lt;/a&gt;):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;  &lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders API'&lt;/span&gt;
    &lt;span class="py"&gt;versioningScheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Header'&lt;/span&gt;
    &lt;span class="py"&gt;versionHeaderName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Api-Version'&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every caller now sends &lt;code&gt;Api-Version: v2&lt;/code&gt;, and the URL stays &lt;code&gt;/sales/orders&lt;/code&gt; for all versions. The cost moves to the client side, where you can't see it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;A forgotten header isn't an error.&lt;/strong&gt; A request without the header is a request without an identifier, and with an Original in the set that's the Original's URL. A partner who upgrades their client code to the v2 response shape but misses the header gets the old array back, and the bug surfaces as a deserialisation failure in their code, not at your gateway.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The version disappears from logs.&lt;/strong&gt; Access logs and pasted URLs no longer say which version was called. You get it back only by logging the header explicitly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Every hop has to keep the header.&lt;/strong&gt; A &lt;code&gt;curl&lt;/code&gt; needs &lt;code&gt;-H&lt;/code&gt;, a browser address bar can't send it at all, and any proxy or HTTP cache between partner and gateway has to pass the header through and key on it. A cache that keys on the URL alone needs &lt;code&gt;Vary: Api-Version&lt;/code&gt;, or it serves one version's response to another version's caller. That's general HTTP caching behaviour, not something API Management documents.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The try-it console needs one more thing. The version header is a custom header, so it triggers a preflight, and the &lt;code&gt;cors&lt;/code&gt; policy has to allow it. The sample's global policy allows &lt;code&gt;*&lt;/code&gt;, which covers it; if you tighten &lt;code&gt;allowed-headers&lt;/code&gt; to a list, add the version header to it. That follows from how CORS works and isn't stated on Learn. What Learn does state is the scope rule: "If you configure the &lt;code&gt;cors&lt;/code&gt; policy at the &lt;em&gt;API&lt;/em&gt; scope, and your API uses a header-versioning scheme, the policy won't work because the version is passed in a header" (&lt;a href="https://learn.microsoft.com/azure/api-management/cors-policy" rel="noopener noreferrer"&gt;&lt;code&gt;cors&lt;/code&gt; policy&lt;/a&gt;). The preflight doesn't carry the version header's value, so the gateway can't pick the version whose policy should answer. It's the product-scope problem again, with a header in place of the key, and the global policy from the CORS section avoids both.&lt;/p&gt;

&lt;h3&gt;
  
  
  Query string: the parameter that drops out of your spec
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;versioningScheme: 'Query'&lt;/code&gt; with &lt;code&gt;versionQueryName: 'api-version'&lt;/code&gt; gives &lt;code&gt;/sales/orders?api-version=v2&lt;/code&gt;. It's Azure's own convention (the &lt;code&gt;az rest&lt;/code&gt; calls later in this article send &lt;code&gt;?api-version=2024-05-01&lt;/code&gt; to ARM), it shows up in logs, and it works from an address bar.&lt;/p&gt;

&lt;p&gt;This one bites in the tooling rather than at the gateway. Learn: "Query parameters aren't allowed in the &lt;code&gt;servers&lt;/code&gt; property of an OpenAPI specification. If you export an OpenAPI specification from an API version, a query string won't appear in the server URL." A partner who downloads the v2 spec from the portal and generates a client from it gets a client that never sends &lt;code&gt;api-version&lt;/code&gt;, which means it calls the Original and receives the v1 contract. The same goes for anything else that treats the exported file as the contract, such as a contract test or a mock server. If you pick query versioning, document the parameter in each operation of the spec yourself, and don't assume an exported definition round-trips.&lt;/p&gt;

&lt;h3&gt;
  
  
  Versions or revisions
&lt;/h3&gt;

&lt;p&gt;Most changes to the order API shouldn't be a version at all. Learn's rule of thumb: "versions are used to separate API versions that have breaking changes, and revisions can be used for minor and non-breaking changes" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-revisions" rel="noopener noreferrer"&gt;revisions&lt;/a&gt;). A new optional field, a new operation, a policy fix: those are revisions. A revision is a numbered copy of the same API that you edit and test without callers noticing, at &lt;code&gt;https://&amp;lt;service name&amp;gt;.azure-api.net/sales;rev=2/orders&lt;/code&gt; (the &lt;code&gt;;rev=n&lt;/code&gt; goes after the API path, before the operation). Making it current is the release, and the optional change log from the portal section is the release note.&lt;/p&gt;

&lt;p&gt;The mistake to watch for is the reverse: a breaking change shipped as a revision. "It's only a field rename" goes out as &lt;code&gt;rev=3&lt;/code&gt;, and every partner gets it at the moment someone selects &lt;strong&gt;Make current&lt;/strong&gt;, with no URL to opt out on. If a revision turns out to be breaking while it's still being tested, the Azure portal can turn it into a version with &lt;strong&gt;Create Version from this Revision&lt;/strong&gt;, which keeps the work and puts the change behind its own identifier. Some properties can't change in a non-current revision at all (name, path, protocols, subscription required, API version among them), so path and scheme changes are version-level decisions anyway.&lt;/p&gt;

&lt;p&gt;The four options side by side:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F00x4mha5givnecvworxa.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F00x4mha5givnecvworxa.png" alt="Path, header and query-string versioning compared with a revision: what the caller sends, log visibility, OpenAPI export, CORS, caching and the main risk" width="800" height="580"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Picking by situation:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;External partners, many client stacks, support by email:&lt;/strong&gt; path, with the live API as the Original. That's the order API's choice.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Clients you build and ship yourself, URLs stored where you can't easily change them:&lt;/strong&gt; header, and keep an Original so a missing header has a defined answer.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;An API that already follows the Azure-style &lt;code&gt;api-version&lt;/code&gt; convention:&lt;/strong&gt; query string, with the parameter written into the spec by hand.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything a correct client wouldn't notice:&lt;/strong&gt; a revision, whichever scheme the set uses.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Products as subscription tiers
&lt;/h2&gt;

&lt;p&gt;Part 1 put the order API into one product and Part 2 gave that product a rate limit. A portal with self-service sign-up needs a second one, because the developer who signs up on a Sunday to try the API shouldn't get the same key a contracted partner gets. Both products contain the same APIs; the differences are approval, the subscription limit and the policy.&lt;/p&gt;

&lt;p&gt;The free tier in &lt;code&gt;infra/apim.bicep&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Evaluation: auto-approved, one subscription per user account, low limits.&lt;/span&gt;
&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;freeProduct&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/products@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-free'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders (free)'&lt;/span&gt;
    &lt;span class="py"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Try the order API: 5 calls a minute, 1,000 a week. Keys are issued right away.'&lt;/span&gt;
    &lt;span class="py"&gt;subscriptionRequired&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
    &lt;span class="py"&gt;approvalRequired&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;
    &lt;span class="py"&gt;subscriptionsLimit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
    &lt;span class="py"&gt;state&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'published'&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The partner product is the Part 1 resource with &lt;code&gt;approvalRequired&lt;/code&gt; switched to &lt;code&gt;true&lt;/code&gt;. Their policies, &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/policies/product-orders-free.xml" rel="noopener noreferrer"&gt;&lt;code&gt;product-orders-free.xml&lt;/code&gt;&lt;/a&gt; and then &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/policies/product-orders-partners.xml" rel="noopener noreferrer"&gt;&lt;code&gt;product-orders-partners.xml&lt;/code&gt;&lt;/a&gt;, differ only in the &lt;code&gt;inbound&lt;/code&gt; section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rate-limit&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;quota&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"1000"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"604800"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rate-limit&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The free tier has two limits because they stop different things. &lt;code&gt;rate-limit&lt;/code&gt; caps bursts: the sixth call inside a minute gets a 429 (&lt;code&gt;verify.sh&lt;/code&gt; case P6). &lt;code&gt;quota&lt;/code&gt; caps volume: 1,000 calls in 604,800 seconds, a week, after which "the caller receives a &lt;code&gt;403 Forbidden&lt;/code&gt; response status code" with a &lt;code&gt;Retry-After&lt;/code&gt; header (&lt;a href="https://learn.microsoft.com/azure/api-management/quota-policy" rel="noopener noreferrer"&gt;&lt;code&gt;quota&lt;/code&gt;&lt;/a&gt;). Five calls a minute without a quota still allows about 50,000 calls a week from a key nobody reviewed. Two details of &lt;code&gt;quota&lt;/code&gt; matter here: it's allowed only at product scope, and the week starts "relative to the start time of the subscription", so every free key has its own week and no Monday-morning reset. The partner product's 60 calls a minute raises Part 2's 10. As Part 2 showed, product policies only run for product-scoped keys; the built-in all-access key the Azure portal's test tab uses skips both limits.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;subscriptionsLimit: 1&lt;/code&gt; means one free subscription per user account. It isn't one per person: nothing stops someone from signing up with five email addresses and calling with five keys at 25 calls a minute. The free tier's numbers are set low enough that this buys little, and the partner product, where the real throughput is, sits behind approval. The &lt;a href="https://learn.microsoft.com/azure/templates/microsoft.apimanagement/2024-05-01/service/products" rel="noopener noreferrer"&gt;&lt;code&gt;2024-05-01&lt;/code&gt; products template reference&lt;/a&gt; also says the property "can be present only if subscriptionRequired property is present and has a value of false", which contradicts the portal tutorial and the sample's protected product. The same reference for older API versions such as &lt;code&gt;2019-12-01&lt;/code&gt; says "a value of true", so the reference versions disagree; the Bicep builds, and it's unverified until a deployment accepts it.&lt;/p&gt;

&lt;p&gt;Since each version is its own API, each version goes into each product:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Every version is its own API, so each one goes into each product.&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;orderApiVersions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;ordersApi&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ordersApiV2&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;partnerProductApis&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/products/apis@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;orderApiVersions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;partnerProduct&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;freeProductApis&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/products/apis@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;orderApiVersions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;freeProduct&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;api&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Forget this for &lt;code&gt;v2&lt;/code&gt; and it's in no product: "To publish the API, you must associate it with a product" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-get-started-publish-versions" rel="noopener noreferrer"&gt;publish versions&lt;/a&gt;). No product key can call it, and the portal has no product to show it in.&lt;/p&gt;

&lt;p&gt;Who sees which product is decided by groups: "Products are first made visible to groups, and then developers in those groups can view and subscribe to the products that are associated with the groups" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-create-groups" rel="noopener noreferrer"&gt;groups&lt;/a&gt;). The sample makes the free product visible to the built-in &lt;code&gt;developers&lt;/code&gt; group (everyone who signed in) and the partner product visible to a custom &lt;code&gt;partners&lt;/code&gt; group, both through &lt;code&gt;products/groups&lt;/code&gt; resources. Neither is visible to Guests, the group anonymous visitors fall into.&lt;/p&gt;

&lt;h3&gt;
  
  
  Approving a partner subscription
&lt;/h3&gt;

&lt;p&gt;A partner's path through the portal, with the sample's settings:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;They sign up and land in Developers. They see the free product and can take a key straight away.&lt;/li&gt;
&lt;li&gt;Someone on the API team adds their account to &lt;code&gt;partners&lt;/code&gt; (Azure portal &amp;gt; the instance &amp;gt; Users). Only now does &lt;strong&gt;Orders for partners&lt;/strong&gt; appear for them.&lt;/li&gt;
&lt;li&gt;They request it. Because the product requires approval, the new subscription is created in the &lt;code&gt;submitted&lt;/code&gt; state, which the &lt;a href="https://learn.microsoft.com/azure/templates/microsoft.apimanagement/2024-05-01/service/subscriptions" rel="noopener noreferrer"&gt;subscriptions template reference&lt;/a&gt; defines as "request has been made by the developer, but has not yet been approved or rejected".&lt;/li&gt;
&lt;li&gt;API Management sends the &lt;strong&gt;Subscription requests (requiring approval)&lt;/strong&gt; notification to whoever is configured for it under &lt;strong&gt;Notifications&lt;/strong&gt; on the instance (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-configure-notifications" rel="noopener noreferrer"&gt;notifications&lt;/a&gt;). If nobody is configured, nobody gets an email and the request just sits there.&lt;/li&gt;
&lt;li&gt;Someone approves it, in the Azure portal under &lt;strong&gt;Subscriptions&lt;/strong&gt; or from a script.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The script version, from the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo#developer-portal-versions-and-products" rel="noopener noreferrer"&gt;README&lt;/a&gt;, lists the waiting subscriptions and activates one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;APIM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;https://management.azure.com/subscriptions/&amp;lt;azure-subscription-id&amp;gt;/resourceGroups/&amp;lt;rg&amp;gt;/providers/Microsoft.ApiManagement/service/&amp;lt;APIM_NAME&amp;gt;
az rest &lt;span class="nt"&gt;--method&lt;/span&gt; get &lt;span class="nt"&gt;--url&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APIM&lt;/span&gt;&lt;span class="s2"&gt;/subscriptions?api-version=2024-05-01&amp;amp;&lt;/span&gt;&lt;span class="se"&gt;\$&lt;/span&gt;&lt;span class="s2"&gt;filter=properties/state eq 'submitted'"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"value[].{name:name, scope:properties.scope, owner:properties.ownerId}"&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; table
az rest &lt;span class="nt"&gt;--method&lt;/span&gt; patch &lt;span class="nt"&gt;--url&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APIM&lt;/span&gt;&lt;span class="s2"&gt;/subscriptions/&amp;lt;name&amp;gt;?api-version=2024-05-01"&lt;/span&gt; &lt;span class="nt"&gt;--body&lt;/span&gt; &lt;span class="s1"&gt;'{"properties":{"state":"active"}}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;owner&lt;/code&gt; column is the developer account, which is how you match a request to a contract before approving it. &lt;code&gt;verify.sh&lt;/code&gt; covers both ends: case P7 calls with the key of a subscription still in &lt;code&gt;submitted&lt;/code&gt; and expects a 401; case P8 repeats the call after the &lt;code&gt;PATCH&lt;/code&gt; and expects a 200. The PATCH with &lt;code&gt;"state":"cancelled"&lt;/code&gt; from Part 1 is the same call in the other direction.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;contoso-shop&lt;/code&gt;, the subscription Bicep created in Part 1, isn't affected by the switch to approval. It was created with &lt;code&gt;state: 'active'&lt;/code&gt;, and &lt;code&gt;approvalRequired&lt;/code&gt; only applies to new requests. That also means the Bicep route is still open for partners you onboard without the portal: a &lt;code&gt;subscriptions&lt;/code&gt; resource with &lt;code&gt;state: 'active'&lt;/code&gt; skips the queue entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Customising the portal, and when to self-host it
&lt;/h2&gt;

&lt;p&gt;The managed portal on v2 is customisable in the visual editor: pages, layouts, styles, menus and the built-in widgets, plus a content security policy and per-group visibility for sections, menus and buttons. White-labelling stays within that: your colours and fonts in the styles, your logo as a media file, and a custom domain on the portal, whose origin then goes into the &lt;code&gt;cors&lt;/code&gt; policy next to the default one, as the CORS section said.&lt;/p&gt;

&lt;p&gt;What v2 limits is how much of that you can have. From the &lt;a href="https://learn.microsoft.com/azure/azure-resource-manager/management/azure-subscription-service-limits#limits---developer-portal-in-api-management-v2-tiers" rel="noopener noreferrer"&gt;service limits for the portal on v2 tiers&lt;/a&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F97wkfq1enmoqb77v10pf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F97wkfq1enmoqb77v10pf.png" alt="Developer portal limits on API Management v2 tiers: pages, widgets, media files and client requests for Basic v2, Standard v2 and Premium v2" width="634" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thirty pages sounds like plenty until a partner programme wants a page per integration guide. Fifteen media files of 500 KB each is a logo, a favicon and a handful of diagrams. And three features aren't there at all: the &lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" rel="noopener noreferrer"&gt;v2 tiers overview&lt;/a&gt; lists &lt;strong&gt;Reports&lt;/strong&gt; and the &lt;strong&gt;custom HTML code widget and custom widget&lt;/strong&gt; as currently unavailable. On Basic v2 a developer can't see their own usage in the portal, and anything the built-in widgets can't render (an onboarding form posting to your CRM, an embedded status page) has no place to live.&lt;/p&gt;

&lt;h3&gt;
  
  
  Restricting it to your own people
&lt;/h3&gt;

&lt;p&gt;For an internal API the portal should be invisible to everyone else, and that's configuration, not self-hosting (&lt;a href="https://learn.microsoft.com/azure/api-management/secure-developer-portal-access" rel="noopener noreferrer"&gt;secure access&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Require sign-in.&lt;/strong&gt; Under the portal's site settings, &lt;strong&gt;Redirect anonymous users to sign-in page&lt;/strong&gt; removes the anonymous default the portal section described.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sign in with Entra ID, and nothing else.&lt;/strong&gt; Add Entra ID as the identity provider, then delete the &lt;strong&gt;Username and password&lt;/strong&gt; provider, which "prevents adding users to use username and password authentication" (&lt;a href="https://learn.microsoft.com/azure/api-management/developer-portal-basic-authentication#delete-the-username-and-password-provider" rel="noopener noreferrer"&gt;basic authentication&lt;/a&gt;). Entra ID sign-in needs an app registration of its own, which is why the sample keeps the default provider.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Hide what's left with groups.&lt;/strong&gt; Products visible only to an internal group, and sections of pages restricted to the same group.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;What configuration can't do on v2 is take the portal off the internet. Even with &lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview#networking-options" rel="noopener noreferrer"&gt;VNet integration&lt;/a&gt; on Standard v2, "the API Management gateway, management plane, and developer portal remain publicly accessible from the internet". Sign-in is the boundary.&lt;/p&gt;

&lt;h3&gt;
  
  
  When self-hosting pays off
&lt;/h3&gt;

&lt;p&gt;The portal's source is open, at &lt;a href="https://github.com/Azure/api-management-developer-portal" rel="noopener noreferrer"&gt;Azure/api-management-developer-portal&lt;/a&gt;, and you can build and host it yourself (&lt;a href="https://learn.microsoft.com/azure/api-management/developer-portal-self-host" rel="noopener noreferrer"&gt;self-host&lt;/a&gt;). The self-hosted portal is a static site, typically in a storage account's static website, that still uses the managed portal's backend at &lt;code&gt;https://&amp;lt;service name&amp;gt;.developer.azure-api.net&lt;/code&gt; for its data; "the content of all portals is stored in the same API Management service". Learn describes it as "full flexibility and extensibility": your own widgets, your own hosting and CDN, your own release cadence, the portal inside a site you already run.&lt;/p&gt;

&lt;p&gt;It pays off when the limits above are the reason the portal doesn't do its job: you need a custom widget, or the portal has to live inside an existing site. One caveat for v2: the self-host page applies to Basic v2 and Standard v2, and v2 rules out custom widgets in the managed portal, but no Learn page says that custom widgets in a self-hosted portal are supported against a v2 instance. Check that before you plan around it.&lt;/p&gt;

&lt;p&gt;What you pay:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;An Entra app registration.&lt;/strong&gt; The prerequisites list "permissions to create a Microsoft Entra app registration", next to a storage account, Node.js and the Azure CLI. This is why the article doesn't show a self-hosted portal: the tenant the sample is built in doesn't allow users to create app registrations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The visibility controls.&lt;/strong&gt; "Visibility and access controls are supported only in the managed developer portal. They aren't supported in the self-hosted portal." The &lt;code&gt;partners&lt;/code&gt; group still decides who can subscribe, but no longer what a page shows.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upgrades.&lt;/strong&gt; The managed portal "receives and applies software updates automatically". A self-hosted one is on the release tag you built from (not &lt;code&gt;master&lt;/code&gt;, which is daily development) until you rebuild.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Upkeep around it.&lt;/strong&gt; A SAS token in the configuration that expires, notification email templates that still link to the managed portal's URL until you change them, and support that's limited: "Azure Support's assistance is limited only to the basic setup."&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If the limit you hit is pages, Standard v2's 50 or a few merged pages is a cheaper fix than owning a portal build. Self-host when you need a capability the managed portal can't have; more headroom alone doesn't justify the build.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The order API now has a second version and a portal where new partners can find it. Partners who already call &lt;code&gt;/sales/orders&lt;/code&gt; haven't noticed anything, because the live API joined its version set as the Original; &lt;code&gt;v2&lt;/code&gt; and its page envelope sit next to it at &lt;code&gt;/sales/v2/orders&lt;/code&gt;. New developers find both in the portal, take a free key without asking anyone, and wait for a person only when they want partner limits. The decisions that are hard to undo were made once: path as the scheme, global scope for &lt;code&gt;cors&lt;/code&gt;, groups for visibility. The ones that will change often (descriptions, limits, which developer is in &lt;code&gt;partners&lt;/code&gt;) are a Bicep change or a click.&lt;/p&gt;

&lt;p&gt;Those clicks are the problem Part 5 picks up. The products and version set are in Bicep, but group membership, every subscription approved by hand and any policy someone fixed in the Azure portal's editor exist only in the instance. The APIOps extractor pulls an instance's configuration out into files, and the publisher pushes those files into the next environment, so a test instance and production stop drifting apart one portal edit at a time.&lt;/p&gt;

&lt;p&gt;Is your live API in a version set as the Original, or does it already carry a &lt;code&gt;v1&lt;/code&gt; identifier?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azureapimanagement</category>
      <category>api</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>Azure API Management Security: Entra ID JWT Validation and Managed Identity</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Tue, 27 Oct 2026 06:38:48 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-api-management-security-entra-id-jwt-validation-and-managed-identity-9i0</link>
      <guid>https://dev.to/martin_oehlert/azure-api-management-security-entra-id-jwt-validation-and-managed-identity-9i0</guid>
      <description>&lt;p&gt;Which of the two shared secrets around the Azure API Management gateway can an Entra ID token or a managed identity replace, and what does each new check actually reject? After Part 2, the API trusts a subscription key on the way in and a function key on the way out, and neither one says who is calling. A subscription key that leaks from a partner's config identifies nobody, and the function key works just as well from a laptop as from the gateway, so anyone holding it skips every policy from Part 2. The short answer: the token doesn't replace the subscription key at all, and the managed identity replaces the function key only at the end of a migration.&lt;/p&gt;

&lt;p&gt;Checking identity at the gateway means the function code never parses a token, one policy covers every operation of the API, and a rejected call never reaches the Flex Consumption app. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt; adds three Entra ID app registrations (deployed with Graph Bicep), a system-assigned &lt;strong&gt;managed identity&lt;/strong&gt; on API Management, &lt;code&gt;validate-azure-ad-token&lt;/code&gt; (the Entra-specific sibling of &lt;code&gt;validate-jwt&lt;/code&gt;) in the API policy, &lt;code&gt;authentication-managed-identity&lt;/code&gt; toward the function, and App Service Authentication on the function app, with the function key kept as a second layer. The Bicep and the function project build clean, and the README has a runbook to deploy and exercise everything. The status codes in this article are the ones Microsoft Learn documents; where Learn is silent, the article says so.&lt;/p&gt;

&lt;h2&gt;
  
  
  OAuth 2.0 with Entra ID: who gets a token for what
&lt;/h2&gt;

&lt;p&gt;Partners call the order API from their own backends, with no user signed in. That is the &lt;strong&gt;client credentials&lt;/strong&gt; flow: the partner's app authenticates as itself and asks Entra ID for an app-only token for your API. Three app registrations make that work in the sample:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;orders-api&lt;/strong&gt; represents the API behind the gateway. Callers request tokens for it, and it defines the permission they need.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;orders-test-client&lt;/strong&gt; stands in for a partner's service.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;orders-backend&lt;/strong&gt; is the audience API Management uses toward the function. It belongs to the managed identity section; it's a separate registration so that a partner's token for the gateway is useless against the function.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is the part of &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/entra.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;infra/entra.bicep&lt;/code&gt;&lt;/a&gt; that defines the API and lets the test client in:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="k"&gt;extension&lt;/span&gt; &lt;span class="n"&gt;microsoftGraphV1&lt;/span&gt;

&lt;span class="k"&gt;param&lt;/span&gt; &lt;span class="n"&gt;resourceToken&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;

&lt;span class="c1"&gt;// v2 access tokens: aud is the client ID, iss is https://login.microsoftonline.com/{tenant}/v2.0.&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;tokenVersion&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;var&lt;/span&gt; &lt;span class="n"&gt;ordersRoleId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;guid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'orders-api'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;resourceToken&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'Orders.ReadWrite'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersApiApp&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.Graph/applications@v1.0'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;uniqueName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-api-&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;resourceToken&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
  &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders API (&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;resourceToken&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;)'&lt;/span&gt;
  &lt;span class="py"&gt;signInAudience&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'AzureADMyOrg'&lt;/span&gt;
  &lt;span class="py"&gt;api&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;requestedAccessTokenVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;tokenVersion&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="py"&gt;appRoles&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="pi"&gt;{&lt;/span&gt;
      &lt;span class="py"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersRoleId&lt;/span&gt;
      &lt;span class="py"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders.ReadWrite'&lt;/span&gt;
      &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Orders.ReadWrite'&lt;/span&gt;
      &lt;span class="py"&gt;description&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Place and read orders through API Management.'&lt;/span&gt;
      &lt;span class="py"&gt;allowedMemberTypes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Application'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="py"&gt;isEnabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Only clients with an app role assignment (testClientRole below) can get a token for this API.&lt;/span&gt;
&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersApiSp&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.Graph/servicePrincipals@v1.0'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersApiApp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;appId&lt;/span&gt;
  &lt;span class="py"&gt;appRoleAssignmentRequired&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;testClientRole&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.Graph/appRoleAssignedTo@v1.0'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;appRoleId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersRoleId&lt;/span&gt;
  &lt;span class="py"&gt;principalId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;testClientSp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
  &lt;span class="py"&gt;resourceId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ordersApiSp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;extension microsoftGraphV1&lt;/code&gt; line needs the Graph extension registered in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/bicepconfig.json" rel="noopener noreferrer"&gt;&lt;code&gt;bicepconfig.json&lt;/code&gt;&lt;/a&gt;, and the identity running the deployment needs permission to create app registrations. Many company tenants turn that off for regular users; in that case the Entra part of the deployment is denied and you need someone with the Application Developer role (or higher) to run it.&lt;/p&gt;

&lt;p&gt;Three settings in that file decide what the gateway will see later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;requestedAccessTokenVersion: 2&lt;/code&gt;&lt;/strong&gt; pins the token format. The version is a property of the API's registration, not of the endpoint the client calls: &lt;a href="https://learn.microsoft.com/entra/identity-platform/access-tokens" rel="noopener noreferrer"&gt;Learn&lt;/a&gt; says "The values of &lt;code&gt;null&lt;/code&gt; and &lt;code&gt;1&lt;/code&gt; result in v1.0 tokens, and the value of &lt;code&gt;2&lt;/code&gt; results in v2.0 tokens", and a new registration starts at &lt;code&gt;null&lt;/code&gt;. So a partner calling the v2 token endpoint still gets a v1 token unless you change this. The two versions differ in exactly the claims a gateway checks: a v2 token's &lt;code&gt;iss&lt;/code&gt; ends in &lt;code&gt;/v2.0&lt;/code&gt; and its &lt;code&gt;aud&lt;/code&gt; "is always the client ID of the API", while a v1 token comes from &lt;code&gt;https://sts.windows.net/{tenant-id}/&lt;/code&gt; and its &lt;code&gt;aud&lt;/code&gt; "can be the client ID or the resource URI used in the request" (&lt;a href="https://learn.microsoft.com/entra/identity-platform/access-token-claims-reference" rel="noopener noreferrer"&gt;claims reference&lt;/a&gt;). The calling app's ID sits in &lt;code&gt;azp&lt;/code&gt; on v2 and in &lt;code&gt;appid&lt;/code&gt; on v1. The portal's manifest editor calls this setting &lt;code&gt;requestedAccessTokenVersion&lt;/code&gt; under &lt;code&gt;api&lt;/code&gt;; older docs, including API Management's own tutorial, still use the Azure AD Graph name &lt;code&gt;accessTokenAcceptedVersion&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The app role&lt;/strong&gt; is how an app-only caller gets a permission. Delegated &lt;strong&gt;scopes&lt;/strong&gt; land in the &lt;code&gt;scp&lt;/code&gt; claim, which is "only included for user tokens". A client credentials token carries the app roles assigned to the calling app in the &lt;code&gt;roles&lt;/code&gt; claim instead, so the role needs &lt;code&gt;allowedMemberTypes: ['Application']&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;appRoleAssignmentRequired: true&lt;/code&gt;&lt;/strong&gt; on the service principal is the setting the portal shows as &lt;strong&gt;Assignment required?&lt;/strong&gt; under the enterprise application's properties. Without it, Learn's Easy Auth page is blunt about the default: it "allows &lt;em&gt;any&lt;/em&gt; client application in your Microsoft Entra tenant to request an access token". With it, Entra refuses to issue a token to an app that has no role assignment (&lt;a href="https://learn.microsoft.com/entra/identity-platform/howto-restrict-your-app-to-a-set-of-users" rel="noopener noreferrer"&gt;error &lt;code&gt;AADSTS501051&lt;/code&gt;&lt;/a&gt;), and &lt;code&gt;testClientRole&lt;/code&gt; is the assignment that lets the test client through. Every new partner app needs its own assignment.&lt;/p&gt;

&lt;p&gt;The partner's service then asks for a token. Graph Bicep can't create client secrets, so the README creates one for the test client and requests a token with curl:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;azd &lt;span class="nb"&gt;env &lt;/span&gt;get-values&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nv"&gt;CLIENT_SECRET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;az ad app credential reset &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TEST_CLIENT_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--display-name&lt;/span&gt; requests-http &lt;span class="nt"&gt;--years&lt;/span&gt; 1 &lt;span class="nt"&gt;--query&lt;/span&gt; password &lt;span class="nt"&gt;-o&lt;/span&gt; tsv&lt;span class="si"&gt;)&lt;/span&gt;
curl &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="s2"&gt;"https://login.microsoftonline.com/&lt;/span&gt;&lt;span class="nv"&gt;$AZURE_TENANT_ID&lt;/span&gt;&lt;span class="s2"&gt;/oauth2/v2.0/token"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;grant_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;client_credentials &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;client_id&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TEST_CLIENT_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--data-urlencode&lt;/span&gt; &lt;span class="nv"&gt;client_secret&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$CLIENT_SECRET&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="nv"&gt;scope&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;/.default"&lt;/span&gt; | jq &lt;span class="nt"&gt;-r&lt;/span&gt; .access_token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The scope is the API's identifier followed by &lt;code&gt;/.default&lt;/code&gt;, and for client credentials it &lt;a href="https://learn.microsoft.com/entra/identity-platform/v2-oauth2-client-creds-grant-flow" rel="noopener noreferrer"&gt;always is&lt;/a&gt;: an app-only token can't ask for individual permissions, it gets every app role the client has been assigned. The sample sets no Application ID URI on orders-api, so the identifier is the client ID itself. If you add an &lt;code&gt;api://&lt;/code&gt; URI and partners ask for &lt;code&gt;api://.../.default&lt;/code&gt;, a v2 token still carries the client ID in &lt;code&gt;aud&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Decoded, the payload of that token carries these claims (values shortened):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"aud"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;orders-api client ID&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"iss"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://login.microsoftonline.com/&amp;lt;tenant-id&amp;gt;/v2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"azp"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;orders-test-client client ID&amp;gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"roles"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Orders.ReadWrite"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"ver"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The gateway policy below checks the first four, &lt;code&gt;iss&lt;/code&gt; through the tenant's metadata; &lt;code&gt;ver&lt;/code&gt; tells you which format the other four follow.&lt;/p&gt;

&lt;p&gt;API Management also has an &lt;strong&gt;OAuth 2.0 authorization server&lt;/strong&gt; setting, and it looks like the place to attach OAuth to an API. It doesn't protect anything. &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-oauth2" rel="noopener noreferrer"&gt;Learn&lt;/a&gt; says it "only enables the developer portal's test console (and the test console in the Azure portal) as a client to acquire a token", and on the same page: "In the configuration so far, API Management doesn't validate the access token. It only passes the token in the authorization header to the backend API." Part 4 covers the developer portal; for the gateway, the protection is a policy.&lt;/p&gt;

&lt;h2&gt;
  
  
  Validating the Entra ID token at the gateway
&lt;/h2&gt;

&lt;p&gt;This is the start of the API policy's &lt;code&gt;inbound&lt;/code&gt; section in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/policies/api-orders.xml" rel="noopener noreferrer"&gt;&lt;code&gt;infra/policies/api-orders.xml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ip-filter&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"forbid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;address-range&lt;/span&gt; &lt;span class="na"&gt;from=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.0"&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.255"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ip-filter&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;validate-azure-ad-token&lt;/span&gt; &lt;span class="na"&gt;tenant-id=&lt;/span&gt;&lt;span class="s"&gt;"{{tenant-id}}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;client-application-ids&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;application-id&amp;gt;&lt;/span&gt;{{orders-test-client-app-id}}&lt;span class="nt"&gt;&amp;lt;/application-id&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/client-application-ids&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;audiences&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;audience&amp;gt;&lt;/span&gt;{{orders-api-app-id}}&lt;span class="nt"&gt;&amp;lt;/audience&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/audiences&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;required-claims&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;claim&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"roles"&lt;/span&gt; &lt;span class="na"&gt;match=&lt;/span&gt;&lt;span class="s"&gt;"any"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;Orders.ReadWrite&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/claim&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/required-claims&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/validate-azure-ad-token&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;authentication-managed-identity&lt;/span&gt; &lt;span class="na"&gt;resource=&lt;/span&gt;&lt;span class="s"&gt;"{{orders-backend-app-id}}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-func"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- subscription key removal, x-partner header and the POST rate limit from Part 2 --&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://learn.microsoft.com/azure/api-management/validate-azure-ad-token-policy" rel="noopener noreferrer"&gt;&lt;code&gt;validate-azure-ad-token&lt;/code&gt;&lt;/a&gt; (titled "Validate Microsoft Entra token" in the docs) is the Entra-specific validator. It works on every tier, including Basic v2, and reads the token from the &lt;code&gt;Authorization&lt;/code&gt; header unless you tell it otherwise. Each &lt;code&gt;{{...}}&lt;/code&gt; is a &lt;strong&gt;named value&lt;/strong&gt; that &lt;code&gt;infra/apim.bicep&lt;/code&gt; fills from the deployment: &lt;code&gt;tenant-id&lt;/code&gt; from &lt;code&gt;tenant().tenantId&lt;/code&gt;, the three app IDs from the outputs of &lt;code&gt;entra.bicep&lt;/code&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;tenant-id&lt;/code&gt;&lt;/strong&gt; binds the policy to one tenant. The policy fetches the tenant's signing keys and checks the issuer itself; there is no metadata URL or issuer list to get wrong. The attribute also accepts &lt;code&gt;organizations&lt;/code&gt; or &lt;code&gt;common&lt;/code&gt;, and Learn's own sample uses &lt;code&gt;organizations&lt;/code&gt;, which accepts tokens from any Entra tenant. For a partner API, use the GUID.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;audiences&lt;/code&gt;&lt;/strong&gt; is the orders-api client ID, because the registration issues v2 tokens. A token Entra issued for any other API in the tenant fails here, even with a valid signature.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;client-application-ids&lt;/code&gt;&lt;/strong&gt; pins the callers. Only the listed apps get through, so a second partner means a second &lt;code&gt;&amp;lt;application-id&amp;gt;&lt;/code&gt; (and a second role assignment). The policy page doesn't say which claim this element reads; with v2 tokens the caller's ID is in &lt;code&gt;azp&lt;/code&gt;, and pinning the token version keeps that question from coming up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;required-claims&lt;/code&gt;&lt;/strong&gt; demands &lt;code&gt;Orders.ReadWrite&lt;/code&gt; in &lt;code&gt;roles&lt;/code&gt;. &lt;code&gt;match="any"&lt;/code&gt; passes if at least one listed value is present; with a single value, &lt;code&gt;any&lt;/code&gt; and &lt;code&gt;all&lt;/code&gt; behave the same, but &lt;code&gt;any&lt;/code&gt; keeps working when you add a read-only role later.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Assignment required and &lt;code&gt;client-application-ids&lt;/code&gt; look redundant, since both limit which apps get in. They act at different points. Assignment required stops Entra from issuing the token in the first place. The policy's allowlist also rejects an app that got the role some other way, for example a role assigned to the wrong app by mistake. Without either, &lt;code&gt;audiences&lt;/code&gt; alone admits every app in the tenant that can get a token for orders-api, and with Assignment required off, that is every app in the tenant.&lt;/p&gt;

&lt;p&gt;When a check fails, the gateway answers with &lt;code&gt;failed-validation-httpcode&lt;/code&gt;, 401 by default, and the call never reaches the backend. The error message "depends on validation issue"; Learn gives "JWT not present." as one example and documents no other texts, so don't build client logic on the message.&lt;/p&gt;

&lt;p&gt;Position matters twice. The policy sits after &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt;, so the global policy (the correlation ID) and the product's rate limit still run first. And it sits before &lt;code&gt;authentication-managed-identity&lt;/code&gt;, which writes API Management's own token into the &lt;code&gt;Authorization&lt;/code&gt; header: swap the two and the validator checks the gateway's token instead of the partner's. The policy lives at API scope, not global, because another API on the same instance has a different audience.&lt;/p&gt;

&lt;h3&gt;
  
  
  When &lt;code&gt;validate-jwt&lt;/code&gt; is the better fit
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://learn.microsoft.com/azure/api-management/validate-jwt-policy" rel="noopener noreferrer"&gt;&lt;code&gt;validate-jwt&lt;/code&gt;&lt;/a&gt; is the general JWT validator, and Learn's &lt;a href="https://learn.microsoft.com/azure/api-management/mitigate-owasp-api-threats" rel="noopener noreferrer"&gt;OWASP guidance&lt;/a&gt; draws the line: &lt;code&gt;validate-azure-ad-token&lt;/code&gt; for Entra tokens, &lt;code&gt;validate-jwt&lt;/code&gt; "for validating tokens not issued by Microsoft Entra". Reach for it when the issuer is another identity provider, when you use Entra External ID for customers (which &lt;code&gt;validate-azure-ad-token&lt;/code&gt; doesn't support), or when you need knobs the Entra policy lacks, such as &lt;code&gt;clock-skew&lt;/code&gt; or explicit signing keys.&lt;/p&gt;

&lt;p&gt;This is the sample's check written as &lt;code&gt;validate-jwt&lt;/code&gt;. It isn't a committed policy (&lt;code&gt;scripts/verify.sh&lt;/code&gt; generates a similar variant for a few test calls); it shows how much the Entra policy does for you:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;validate-jwt&lt;/span&gt; &lt;span class="na"&gt;header-name=&lt;/span&gt;&lt;span class="s"&gt;"Authorization"&lt;/span&gt; &lt;span class="na"&gt;require-scheme=&lt;/span&gt;&lt;span class="s"&gt;"Bearer"&lt;/span&gt;
    &lt;span class="na"&gt;failed-validation-httpcode=&lt;/span&gt;&lt;span class="s"&gt;"401"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;openid-config&lt;/span&gt; &lt;span class="na"&gt;url=&lt;/span&gt;&lt;span class="s"&gt;"https://login.microsoftonline.com/{{tenant-id}}/v2.0/.well-known/openid-configuration"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;audiences&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;audience&amp;gt;&lt;/span&gt;{{orders-api-app-id}}&lt;span class="nt"&gt;&amp;lt;/audience&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/audiences&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;required-claims&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;claim&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"azp"&lt;/span&gt; &lt;span class="na"&gt;match=&lt;/span&gt;&lt;span class="s"&gt;"all"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;{{orders-test-client-app-id}}&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/claim&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;claim&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"roles"&lt;/span&gt; &lt;span class="na"&gt;match=&lt;/span&gt;&lt;span class="s"&gt;"any"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;Orders.ReadWrite&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/claim&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/required-claims&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/validate-jwt&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;openid-config&lt;/code&gt; URL is where the policy gets the signing keys and the expected issuer. API Management caches the keys for an hour, and when a token references a key it doesn't know (Entra rotates them), it refetches at most once every five minutes. The &lt;code&gt;/v2.0&lt;/code&gt; in that URL is the version decision again: the v2 metadata document publishes the v2 issuer, so this policy only accepts v2 tokens. The caller allowlist becomes a claim check you write yourself, and its name is &lt;code&gt;azp&lt;/code&gt; on v2 but &lt;code&gt;appid&lt;/code&gt; on v1. Watch two defaults: &lt;code&gt;clock-skew&lt;/code&gt; is zero seconds, so a gateway clock running slightly ahead rejects a token in its last moments; and &lt;code&gt;require-scheme&lt;/code&gt; only works on the &lt;code&gt;Authorization&lt;/code&gt; header and is silently ignored when you set a custom &lt;code&gt;header-name&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For a non-Entra issuer the shape stays the same: point &lt;code&gt;openid-config&lt;/code&gt; at the provider's metadata document, put the audience it issues into &lt;code&gt;audiences&lt;/code&gt;, and check whatever claim it uses for permissions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Mistakes that let the wrong token in, or keep the right one out
&lt;/h3&gt;

&lt;p&gt;The failures fall into two groups. Too strict, and every partner gets a 401 after go-live. Too loose, and the gateway accepts tokens it should reject, and nobody notices because nothing breaks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The registration still issues v1 tokens.&lt;/strong&gt; Nobody set &lt;code&gt;requestedAccessTokenVersion&lt;/code&gt;, so it's &lt;code&gt;null&lt;/code&gt;, and Entra issues v1 tokens even though the client calls the v2 token endpoint. The policy uses &lt;code&gt;validate-jwt&lt;/code&gt; with the v2 metadata URL, which expects the &lt;code&gt;https://login.microsoftonline.com/{tenant-id}/v2.0&lt;/code&gt; issuer. Every token carries &lt;code&gt;https://sts.windows.net/{tenant-id}/&lt;/code&gt;. The signature is fine, the issuer isn't, and every call is a 401. The fix is to pick one version and pin it on both sides: &lt;code&gt;requestedAccessTokenVersion: 2&lt;/code&gt; in the registration and the &lt;code&gt;/v2.0&lt;/code&gt; metadata URL in the policy, or v1 on both.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Learn's own example can't pass.&lt;/strong&gt; The &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-protect-backend-with-aad" rel="noopener noreferrer"&gt;API Management tutorial for Entra ID&lt;/a&gt; combines a v2 &lt;code&gt;openid-config&lt;/code&gt; URL, the v1 issuer &lt;code&gt;https://sts.windows.net/{tenant id}/&lt;/code&gt;, an &lt;code&gt;api://&lt;/code&gt; audience, and a required &lt;code&gt;aud&lt;/code&gt; claim equal to the client ID. A token has one &lt;code&gt;aud&lt;/code&gt;. A v2 token carries the client ID and fails the &lt;code&gt;api://&lt;/code&gt; audience; a v1 token requested for &lt;code&gt;api://...&lt;/code&gt; carries that URI and fails the required claim. Copy it literally and no token satisfies it. Take the policy's structure from the tutorial, and the values from the claims reference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The audience has the wrong format.&lt;/strong&gt; A v2 token's &lt;code&gt;aud&lt;/code&gt; is always the bare client ID. A v1 token's &lt;code&gt;aud&lt;/code&gt; is whatever the client asked for, the client ID or the &lt;code&gt;api://&lt;/code&gt; URI, so two partners following different docs present different audiences. If you can't pin v2 yet, list both values in &lt;code&gt;audiences&lt;/code&gt;; the policy tries each until one matches.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No audience check.&lt;/strong&gt; A policy that checks only signature and issuer accepts any token from your tenant, including tokens issued for a completely different API. The &lt;code&gt;validate-jwt&lt;/code&gt; reference marks &lt;code&gt;audiences&lt;/code&gt; as not required while its description says "at least one audience must be specified"; set it every time instead of finding out what the gateway does without it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;No caller check.&lt;/strong&gt; Audience correct, but no &lt;code&gt;roles&lt;/code&gt; requirement, no allowlist, and Assignment required left off: every app registration in the tenant can request a token for orders-api and the gateway accepts it. The gap shows up in an audit, not in a 401. &lt;code&gt;tenant-id="organizations"&lt;/code&gt; widens the same hole to every Entra tenant.&lt;/p&gt;

&lt;p&gt;The safe way to see which group you are in is to send a token that should fail. &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/requests.http" rel="noopener noreferrer"&gt;&lt;code&gt;requests.http&lt;/code&gt;&lt;/a&gt; in the repo has a call with a subscription key and no token, which &lt;code&gt;validate-azure-ad-token&lt;/code&gt; rejects with a 401. Request a second token for the orders-backend app and send it to the gateway as well: it has a valid signature and the right issuer, and the audience check must reject it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Managed identity from API Management to Azure Functions
&lt;/h2&gt;

&lt;p&gt;The inbound section above already contains the line that takes over from the function key:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;authentication-managed-identity&lt;/span&gt; &lt;span class="na"&gt;resource=&lt;/span&gt;&lt;span class="s"&gt;"{{orders-backend-app-id}}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-func"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For that line to work, API Management needs an identity of its own. &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/apim.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;infra/apim.bicep&lt;/code&gt;&lt;/a&gt; turns on the system-assigned one and exports its object ID for the function app:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'apim-orders-&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;resourceToken&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;
  &lt;span class="c1"&gt;// location, tags, sku, publisher ...&lt;/span&gt;
  &lt;span class="py"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'SystemAssigned'&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;output&lt;/span&gt; &lt;span class="n"&gt;principalId&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;principalId&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Entra creates a service principal for it with &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-use-managed-service-identity" rel="noopener noreferrer"&gt;the same name as the instance&lt;/a&gt;, so it shows up as &lt;code&gt;apim-orders-&amp;lt;token&amp;gt;&lt;/code&gt; under Enterprise applications. There is no secret to copy anywhere: the gateway gets its tokens from the platform.&lt;/p&gt;

&lt;p&gt;On each call, &lt;a href="https://learn.microsoft.com/azure/api-management/authentication-managed-identity-policy" rel="noopener noreferrer"&gt;&lt;code&gt;authentication-managed-identity&lt;/code&gt;&lt;/a&gt; gets a token for &lt;code&gt;resource&lt;/code&gt; and sets it as &lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt;. API Management caches the token until it expires, so Entra isn't in the path of every request. Learn defines &lt;code&gt;resource&lt;/code&gt; as "the application ID of the target web API": here it's the client ID of &lt;strong&gt;orders-backend&lt;/strong&gt;, the third registration from the Entra section. &lt;code&gt;entra.bicep&lt;/code&gt; gives orders-backend v2 tokens as well, so the token's &lt;code&gt;aud&lt;/code&gt; is that client ID and its &lt;code&gt;iss&lt;/code&gt; is the tenant's v2 issuer. Pass &lt;code&gt;api://&amp;lt;client-id&amp;gt;&lt;/code&gt; instead and the audience follows; the function app then has to list that URI as an allowed audience. Both sides only have to agree.&lt;/p&gt;

&lt;p&gt;Three properties of this policy decide where it can go:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;It overwrites the partner's token.&lt;/strong&gt; When the request leaves the gateway, the &lt;code&gt;Authorization&lt;/code&gt; header carries API Management's token, which is why the validator has to run first. If the function ever needs the partner's identity, copy the claim into a separate header from &lt;code&gt;validate-azure-ad-token&lt;/code&gt;'s &lt;code&gt;output-token-variable-name&lt;/code&gt; before this line. The sample sends the subscription name as &lt;code&gt;x-partner&lt;/code&gt; instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It doesn't care where the token goes.&lt;/strong&gt; "API Management doesn't validate which backend the token is sent to." The token follows &lt;code&gt;set-backend-service&lt;/code&gt;, so keep the two lines next to each other at API scope. At global scope, Learn warns, the token is "available in the policy execution context for all APIs, including those in workspaces."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Policy authors can mint it.&lt;/strong&gt; Anyone allowed to write policies (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-use-managed-service-identity" rel="noopener noreferrer"&gt;Learn names&lt;/a&gt; the API Management Service Contributor role) can put this line into an API of their own and send the gateway's token anywhere, or log it. Once the function trusts the gateway's identity, write access to policies is access to the function. Hand out that role like a production credential.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Easy Auth: the function app accepts one identity
&lt;/h3&gt;

&lt;p&gt;The other half lives in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/main.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;infra/main.bicep&lt;/code&gt;&lt;/a&gt;: App Service Authentication, usually called &lt;strong&gt;Easy Auth&lt;/strong&gt;, with the Microsoft provider. It runs in front of the Functions host, so a rejected request never starts your code.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;easyAuth&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.Web/sites/config@2024-04-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;functionApp&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'authsettingsV2'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;platform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt; &lt;span class="py"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt; &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="py"&gt;globalValidation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
      &lt;span class="py"&gt;requireAuthentication&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
      &lt;span class="py"&gt;unauthenticatedClientAction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'Return401'&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="py"&gt;identityProviders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
      &lt;span class="py"&gt;azureActiveDirectory&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
        &lt;span class="py"&gt;enabled&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
        &lt;span class="py"&gt;registration&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
          &lt;span class="py"&gt;clientId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;entra&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backendAppId&lt;/span&gt;
          &lt;span class="py"&gt;openIdIssuer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nf"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;authentication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;loginEndpoint&lt;/span&gt;&lt;span class="si"&gt;}${&lt;/span&gt;&lt;span class="nf"&gt;tenant&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="n"&gt;tenantId&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s1"&gt;/v2.0'&lt;/span&gt;
        &lt;span class="pi"&gt;}&lt;/span&gt;
        &lt;span class="py"&gt;validation&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
          &lt;span class="py"&gt;allowedAudiences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;entra&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;backendAppId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
          &lt;span class="py"&gt;defaultAuthorizationPolicy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
            &lt;span class="py"&gt;allowedPrincipals&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
              &lt;span class="py"&gt;identities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;apim&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;outputs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;principalId&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
            &lt;span class="pi"&gt;}&lt;/span&gt;
          &lt;span class="pi"&gt;}&lt;/span&gt;
        &lt;span class="pi"&gt;}&lt;/span&gt;
      &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Read it from the bottom up; the last setting does the most work.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;allowedPrincipals.identities&lt;/code&gt;&lt;/strong&gt; is an allowlist of object IDs, compared with the token's &lt;code&gt;oid&lt;/code&gt; claim, and &lt;code&gt;apim.identity.principalId&lt;/code&gt; is that object ID. Without this block, Easy Auth accepts any valid token for the audience, and &lt;a href="https://learn.microsoft.com/azure/app-service/configure-authentication-provider-aad" rel="noopener noreferrer"&gt;Learn&lt;/a&gt; spells out the default: "it also lets anyone within the tenant access the application." orders-backend doesn't require role assignments, so any app in the tenant can get a token for it. With the block, a token that is correctly signed and addressed but belongs to another identity fails, and "Requests that fail these built-in checks get an HTTP 403 Forbidden response." The sibling setting &lt;code&gt;allowedApplications&lt;/code&gt; checks &lt;code&gt;appid&lt;/code&gt; or &lt;code&gt;azp&lt;/code&gt; and wants the identity's client ID, which Bicep doesn't hand you for a system-assigned identity; the object ID is already a template output. Set both and a token has to pass both. One limit to know before you add more callers: the identities list allows 500 characters in total, about a dozen object IDs.&lt;/p&gt;

&lt;p&gt;Easy Auth doesn't check app roles ("App Service authentication doesn't perform this validation"), so giving orders-backend a role wouldn't gate anything without code in the function. The identity list is the gate. The Container Apps version of this hop in &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Front Door, API Management and Container Apps: What Each Hop Trusts&lt;/a&gt; adds that role check in code as a second line.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;allowedAudiences&lt;/code&gt;&lt;/strong&gt; is the orders-backend client ID, the same string the gateway passes as &lt;code&gt;resource&lt;/code&gt;. A partner's token for orders-api carries a different &lt;code&gt;aud&lt;/code&gt;, and Easy Auth should reject it; Learn doesn't document which status code a wrong audience gets.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;openIdIssuer&lt;/code&gt;&lt;/strong&gt; is the tenant's v2 issuer, built from &lt;code&gt;environment().authentication.loginEndpoint&lt;/code&gt; so the same Bicep works in sovereign clouds. Learn's provider page gives the format as &lt;code&gt;&amp;lt;authentication-endpoint&amp;gt;/&amp;lt;tenant-id&amp;gt;/v2.0&lt;/code&gt; and recommends it over the legacy &lt;code&gt;https://sts.windows.net&lt;/code&gt; issuer that the portal's express setup still writes. The &lt;code&gt;authsettingsV2&lt;/code&gt; template reference shows &lt;code&gt;/v2.0&lt;/code&gt; in front of the tenant ID; follow the provider page and the tenant's metadata document, which put it at the end. Whether a v2 issuer setting also accepts v1 tokens, Learn doesn't say, which is one more reason to pin v2 on the registration.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Return401&lt;/code&gt;&lt;/strong&gt; together with &lt;code&gt;requireAuthentication: true&lt;/code&gt; answers every request without a valid token with 401, the option Learn marks "recommended for APIs". The alternatives are a 302 to a sign-in page, which an API client can't do anything with, 403 and 404.&lt;/p&gt;

&lt;p&gt;There's no client secret in the &lt;code&gt;registration&lt;/code&gt; block. The function never signs anyone in; it only validates bearer tokens, and that takes the issuer's public keys, not a secret.&lt;/p&gt;

&lt;p&gt;The sample runs on Flex Consumption. No Learn page says Easy Auth is unsupported there, and the &lt;a href="https://learn.microsoft.com/azure/azure-functions/migration/migrate-plan-consumption-to-flex" rel="noopener noreferrer"&gt;Consumption-to-Flex migration guide&lt;/a&gt; tells you to "recreate it in your new app" if the old app used it. That is the documentation this setup rests on until the sample has run end to end.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why the function key is still there
&lt;/h3&gt;

&lt;p&gt;The functions in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/src/OrdersApi/OrderFunctions.cs" rel="noopener noreferrer"&gt;&lt;code&gt;OrderFunctions.cs&lt;/code&gt;&lt;/a&gt; are still &lt;code&gt;AuthorizationLevel.Function&lt;/code&gt;, and the &lt;code&gt;orders-func&lt;/code&gt; backend in &lt;code&gt;apim.bicep&lt;/code&gt; still sends the key on every call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"list-orders"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;IActionResult&lt;/span&gt; &lt;span class="nf"&gt;List&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AuthorizationLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;HttpRequest&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;ordersBackend&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/backends@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-func'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;url&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;functionBaseUrl&lt;/span&gt;
    &lt;span class="py"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'http'&lt;/span&gt;
    &lt;span class="py"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
      &lt;span class="py"&gt;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
        &lt;span class="s1"&gt;'x-functions-key'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'{{&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;functionKeyValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives the function two checks in two different components. Easy Auth sees "every incoming HTTP request" before "your application handles it" (&lt;a href="https://learn.microsoft.com/azure/app-service/overview-authentication-authorization" rel="noopener noreferrer"&gt;Learn&lt;/a&gt;). Behind it, the Functions host enforces the key: "Unless the authorization level on an HTTP triggered function is set to &lt;code&gt;anonymous&lt;/code&gt;, requests must include an access key" (&lt;a href="https://learn.microsoft.com/azure/azure-functions/function-keys-how-to" rel="noopener noreferrer"&gt;Learn&lt;/a&gt;). Learn's &lt;a href="https://learn.microsoft.com/azure/azure-functions/security-concepts" rel="noopener noreferrer"&gt;Functions security page&lt;/a&gt; lists access keys and App Service Authentication as steps of one layered approach, not as alternatives. It doesn't describe how the two combine on a single request, but they sit in sequence, so a request has to get past both.&lt;/p&gt;

&lt;p&gt;Each one covers a failure of the other. A leaked key on its own carries no token, so Easy Auth answers 401 before the host looks at the key. And if someone switches Easy Auth off in the portal, or lets unauthenticated requests through while troubleshooting, the host still refuses calls without the key. Learn documents no status code for a missing key, so the most this article claims is that the host rejects the request.&lt;/p&gt;

&lt;p&gt;The price: the key is still a secret in a named value, someone still has to rotate it, and a rotation that forgets the copy in API Management still breaks every call through the gateway. The migration path below ends with the step that removes it.&lt;/p&gt;

&lt;h3&gt;
  
  
  One request, end to end
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd3qiwqjm93fuwa4op7wm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fd3qiwqjm93fuwa4op7wm.png" alt="Request flow from a partner service through API Management to the order function, and what each hop checks" width="799" height="307"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A partner placing an order passes six checks before &lt;code&gt;OrderFunctions&lt;/code&gt; runs. The numbers in the diagram mark where each one happens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The partner's service requests a token for &lt;code&gt;&amp;lt;orders-api client ID&amp;gt;/.default&lt;/code&gt; with client credentials. Entra issues it only because the app has an &lt;code&gt;Orders.ReadWrite&lt;/code&gt; role assignment.&lt;/li&gt;
&lt;li&gt;The service calls the gateway with its subscription key and &lt;code&gt;Authorization: Bearer &amp;lt;token&amp;gt;&lt;/code&gt;. The gateway resolves the subscription (a missing or unknown key is a 401, as in Part 1), then runs the global policy and the product's rate limit.&lt;/li&gt;
&lt;li&gt;The API policy runs &lt;code&gt;ip-filter&lt;/code&gt;, then &lt;code&gt;validate-azure-ad-token&lt;/code&gt;: signature and issuer of your tenant, audience orders-api, &lt;code&gt;azp&lt;/code&gt; on the allowlist, &lt;code&gt;Orders.ReadWrite&lt;/code&gt; in &lt;code&gt;roles&lt;/code&gt;. Any failure is a 401, and the backend is never called.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;authentication-managed-identity&lt;/code&gt; replaces the partner's token with the gateway's token for orders-backend. The policy routes to &lt;code&gt;orders-func&lt;/code&gt;, deletes the subscription key header, adds &lt;code&gt;x-partner&lt;/code&gt; and applies the POST rate limit. The backend entity adds &lt;code&gt;x-functions-key&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Easy Auth on the function app validates the gateway's token: the tenant's v2 issuer, audience orders-backend, &lt;code&gt;oid&lt;/code&gt; equal to API Management's principal ID.&lt;/li&gt;
&lt;li&gt;The Functions host checks &lt;code&gt;x-functions-key&lt;/code&gt; and runs the function. The code sees &lt;code&gt;x-partner&lt;/code&gt;, never a token.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The calls that matter more are the ones that skip the gateway and go straight to the function URL:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;No token at all&lt;/strong&gt;, with or without a leaked function key: 401 from Easy Auth, because of &lt;code&gt;Return401&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A token for orders-backend from another app in the tenant&lt;/strong&gt;: right signature, right audience, wrong &lt;code&gt;oid&lt;/code&gt;. The identity allowlist rejects it, and Learn's status for that is 403.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The partner's own gateway token&lt;/strong&gt;: its audience is orders-api, not orders-backend, so Easy Auth should reject it, with a status Learn doesn't document.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Management's token in the hands of a policy author&lt;/strong&gt;: they can reference the &lt;code&gt;orders-function-key&lt;/code&gt; named value just as easily, so neither layer stops them. The only defense is who holds the policy role.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To see what your deployment actually returns, &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/scripts/verify.sh" rel="noopener noreferrer"&gt;&lt;code&gt;scripts/verify.sh&lt;/code&gt;&lt;/a&gt; in the companion repo sends the first three direct calls plus the gateway cases from the JWT section (no token, wrong audience, tampered signature, no subscription key, and an expired token if you saved one), and prints the status code and the start of the body next to the code Learn documents. For a few calls it swaps the API policy for a &lt;code&gt;validate-jwt&lt;/code&gt; variant and an &lt;code&gt;ip-filter&lt;/code&gt; allow-list, then restores the committed policy, so run it against your own instance only. It needs the &lt;code&gt;azd&lt;/code&gt; environment from &lt;code&gt;azd up&lt;/code&gt; and a secret for the test client:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;eval&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;azd &lt;span class="nb"&gt;env &lt;/span&gt;get-values&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="nb"&gt;export &lt;/span&gt;&lt;span class="nv"&gt;CLIENT_SECRET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;az ad app credential reset &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$TEST_CLIENT_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--display-name&lt;/span&gt; verify &lt;span class="nt"&gt;--years&lt;/span&gt; 1 &lt;span class="nt"&gt;--query&lt;/span&gt; password &lt;span class="nt"&gt;-o&lt;/span&gt; tsv&lt;span class="si"&gt;)&lt;/span&gt;
scripts/verify.sh | &lt;span class="nb"&gt;tee &lt;/span&gt;verify.log
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script hasn't been run against a live deployment yet, so treat the expected codes it prints as Learn's predictions, and the actual codes as the answer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscription keys and managed identity do different jobs
&lt;/h2&gt;

&lt;p&gt;Managed identity removes a key, so it's tempting to read it as the replacement for keys in general. It replaces one of the two, on the hop partners never see. The subscription key sits on the hop partners use, and it answers a different question.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A subscription key says which subscription a call belongs to, not who made it.&lt;/strong&gt; Learn's &lt;a href="https://learn.microsoft.com/azure/api-management/secure-api-management" rel="noopener noreferrer"&gt;deployment security guidance&lt;/a&gt; is direct about it: "Do not rely on subscription keys as an authentication mechanism: A subscription key identifies an API Management subscription, not a user or app, and is prone to being shared or leaked." The &lt;a href="https://learn.microsoft.com/azure/api-management/authentication-authorization-overview#other-options-to-secure-apis" rel="noopener noreferrer"&gt;authentication overview&lt;/a&gt; recommends a key "in addition to another method of authentication or authorization", for "tracking individual customers' API usage or granting access to specific API products."&lt;/p&gt;

&lt;p&gt;That's the job the sample gives it. The product rate limit from Part 2 counts per subscription, the POST limit's counter key is &lt;code&gt;context.Subscription.Id&lt;/code&gt;, and the &lt;code&gt;x-partner&lt;/code&gt; header and the response cache key come from the subscription. Take the key away and all of them lose the thing they count by. So a partner sends both: the token says which app is calling and what it may do, the key says whose quota the call uses. You could rebuild the counters on the token's &lt;code&gt;azp&lt;/code&gt; claim with &lt;code&gt;rate-limit-by-key&lt;/code&gt;, but products, per-subscription analytics and the developer portal in Part 4 are all built around subscriptions.&lt;/p&gt;

&lt;p&gt;A key without a token is enough where a leak costs you quota rather than data: a read-only catalog, a status feed, an internal consumer you'd cut off by cancelling its subscription. Once an API writes orders or returns customer data, the key is metering and a kill switch, and the token does the authentication.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Managed identity fits the backend hop whenever the backend can validate an Entra token.&lt;/strong&gt; Easy Auth does that for Functions and App Service. Azure services with Entra RBAC, such as Storage or Key Vault, take the same policy with their own &lt;code&gt;resource&lt;/code&gt; plus a role assignment for the gateway's identity. Learn's overview marks managed identity as "Recommended for scoped access to a protected backend resource". It doesn't fit a backend outside your tenant's reach, such as a third-party SaaS API; that one keeps a credential, ideally in &lt;a href="https://dev.to/martin_oehlert/configuration-done-right-settings-secrets-and-key-vault-3n7h"&gt;Key Vault&lt;/a&gt; or API Management's credential manager.&lt;/p&gt;

&lt;h3&gt;
  
  
  Moving from the function key to the identity
&lt;/h3&gt;

&lt;p&gt;Step 1 is a query; steps 2 and 3 are one deployment each, and each leaves a working path for the partners:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Find who calls the function without the gateway.&lt;/strong&gt; Today any holder of the key gets in, and step 3 locks them out. Application Insights already has the data: a function request with no gateway request under the same operation ID most likely came from somewhere else.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   requests
   | where timestamp &amp;gt; ago(30d) and cloud_RoleName startswith "func-orders"
   | join kind=leftanti (requests
       | where timestamp &amp;gt; ago(30d) and cloud_RoleName startswith "apim-orders"
       | project operation_Id) on operation_Id
   | summarize calls = count(), last = max(timestamp) by name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every caller that shows up needs a new route before step 3: through the gateway with its own subscription and token, or with its own managed identity added to &lt;code&gt;allowedPrincipals&lt;/code&gt;. Cover your slowest caller with the time range; a month-end job doesn't show up in a week of data.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Give the gateway its identity and send its token.&lt;/strong&gt; Turn on the system-assigned identity, register the backend app and add &lt;code&gt;authentication-managed-identity&lt;/code&gt; to the API policy. Nothing on the function checks the token yet, so this deployment changes no behavior; the key still does the work.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Turn on Easy Auth.&lt;/strong&gt; &lt;code&gt;authsettingsV2&lt;/code&gt; with &lt;code&gt;Return401&lt;/code&gt;, the backend audience and API Management's principal ID. From this deployment on, the key alone gets nobody in, and it becomes the second layer from the previous section. The companion sample stops here.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The last step: drop the key
&lt;/h3&gt;

&lt;p&gt;Once nothing but the gateway calls the function with the key, and Easy Auth has carried production traffic long enough that you trust its configuration, the key only costs you rotations. The trigger change is one word in each of the three functions in &lt;code&gt;OrderFunctions.cs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;// before&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AuthorizationLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;HttpRequest&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;// after&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;HttpTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AuthorizationLevel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Anonymous&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"get"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Route&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;HttpRequest&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Anonymous&lt;/code&gt; sounds alarming, but it only switches off the host's key check. Easy Auth still stands in front with &lt;code&gt;requireAuthentication: true&lt;/code&gt;; from now on it's the only check.&lt;/p&gt;

&lt;p&gt;In &lt;code&gt;apim.bicep&lt;/code&gt;, the secure parameter, the secret named value and the backend credential go away:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight bicep"&gt;&lt;code&gt;&lt;span class="nd"&gt;@secure&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="k"&gt;param&lt;/span&gt; &lt;span class="n"&gt;functionKey&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;

&lt;span class="k"&gt;resource&lt;/span&gt; &lt;span class="n"&gt;functionKeyValue&lt;/span&gt; &lt;span class="s1"&gt;'Microsoft.ApiManagement/service/namedValues@2024-05-01'&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;parent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;apim&lt;/span&gt;
  &lt;span class="py"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-function-key'&lt;/span&gt;
  &lt;span class="py"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
    &lt;span class="py"&gt;displayName&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'orders-function-key'&lt;/span&gt;
    &lt;span class="py"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
    &lt;span class="py"&gt;value&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;functionKey&lt;/span&gt;
  &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;span class="pi"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// inside ordersBackend.properties&lt;/span&gt;
    &lt;span class="n"&gt;credentials&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
      &lt;span class="py"&gt;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;{&lt;/span&gt;
        &lt;span class="s1"&gt;'x-functions-key'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'{{&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="n"&gt;functionKeyValue&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="err"&gt;}}&lt;/span&gt;&lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="pi"&gt;}&lt;/span&gt;
    &lt;span class="pi"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So do the &lt;code&gt;apimKey&lt;/code&gt; host key resource in &lt;code&gt;function.bicep&lt;/code&gt; and the &lt;code&gt;apimFunctionKey&lt;/code&gt; parameter in &lt;code&gt;main.bicep&lt;/code&gt; that feeds both. Deploy the code first. The &lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-bindings-http-webhook-trigger" rel="noopener noreferrer"&gt;HTTP trigger reference&lt;/a&gt; describes &lt;code&gt;anonymous&lt;/code&gt; as "No access key is required"; it doesn't say what the host does with a key that arrives anyway. The host should ignore it, but this step hasn't run against the sample, so watch the first gateway calls after the code deployment before you remove the key from the infrastructure. In the other order, the key disappears while the functions still demand it, and every call through the gateway fails.&lt;/p&gt;

&lt;p&gt;Deleting a resource from Bicep doesn't delete it from Azure. A resource group deployment runs in &lt;a href="https://learn.microsoft.com/azure/azure-resource-manager/templates/deployment-modes" rel="noopener noreferrer"&gt;incremental mode&lt;/a&gt; by default, which "leaves unchanged resources that exist in the resource group but aren't specified in the template". The backend loses its credential because the backend itself is redeployed without it, and a redeployed resource gets exactly the properties in the template. The named value and the host key are no longer in any template, so they survive and have to go by hand (or through a &lt;a href="https://learn.microsoft.com/azure/azure-resource-manager/bicep/deployment-stacks" rel="noopener noreferrer"&gt;deployment stack&lt;/a&gt;, which Learn recommends when removing a resource from the file should delete it):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az apim nv delete &lt;span class="nt"&gt;-g&lt;/span&gt; &amp;lt;rg&amp;gt; &lt;span class="nt"&gt;--service-name&lt;/span&gt; &amp;lt;APIM_NAME&amp;gt; &lt;span class="nt"&gt;--named-value-id&lt;/span&gt; orders-function-key &lt;span class="nt"&gt;--yes&lt;/span&gt;
az functionapp keys delete &lt;span class="nt"&gt;-g&lt;/span&gt; &amp;lt;rg&amp;gt; &lt;span class="nt"&gt;-n&lt;/span&gt; &amp;lt;FUNCTION_APP_NAME&amp;gt; &lt;span class="nt"&gt;--key-type&lt;/span&gt; functionKeys &lt;span class="nt"&gt;--key-name&lt;/span&gt; apim
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What you get: no secret between gateway and function to store, rotate or leak, and no outage when someone rotates it. What you give up: the layer that caught a disabled or loosened Easy Auth. From here on, a change to &lt;code&gt;authsettingsV2&lt;/code&gt; is as sensitive as a change to the gateway policy, so keep it in Bicep, review it like code, and alert on changes made outside a deployment.&lt;/p&gt;

&lt;h2&gt;
  
  
  IP filtering, and what Basic v2 can't do at the network level
&lt;/h2&gt;

&lt;p&gt;The sample's API policy starts with the filter from Part 2:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ip-filter&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"forbid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;address-range&lt;/span&gt; &lt;span class="na"&gt;from=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.0"&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.255"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ip-filter&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It sits before the token check, so a blocked address is turned away before the gateway validates anything. &lt;code&gt;forbid&lt;/code&gt; blocks the listed addresses; &lt;code&gt;allow&lt;/code&gt; blocks everything else. A request that doesn't pass is rejected, with a 403 Forbidden according to &lt;a href="https://learn.microsoft.com/troubleshoot/azure/api-mgmt/availability/request-throttling-http-403" rel="noopener noreferrer"&gt;Microsoft's troubleshooting guide&lt;/a&gt;; the &lt;a href="https://learn.microsoft.com/azure/api-management/ip-filter-policy" rel="noopener noreferrer"&gt;policy reference&lt;/a&gt; itself states no status code. For a partner API, the useful form is usually an &lt;code&gt;allow&lt;/code&gt; list of the partners' egress ranges, and because &lt;code&gt;address&lt;/code&gt; accepts expressions and named values, the list can change without editing the policy.&lt;/p&gt;

&lt;p&gt;Two caveats carry over from &lt;a href="https://dev.to/martin_oehlert/azure-api-management-policies-scopes-rate-limits-and-caching-5c0j"&gt;Part 2&lt;/a&gt;. The reference doesn't say which address the filter compares, so echo &lt;code&gt;context.Request.IpAddress&lt;/code&gt; from a test policy before you trust an allow-list. And behind Azure Front Door or another proxy, the gateway sees the proxy; Learn's &lt;a href="https://learn.microsoft.com/azure/api-management/front-door-api-management" rel="noopener noreferrer"&gt;pattern for Front Door&lt;/a&gt; is a different check, &lt;code&gt;check-header&lt;/code&gt; on the &lt;code&gt;X-Azure-FDID&lt;/code&gt; header, and &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;What Each Hop Trusts&lt;/a&gt; builds that chain with Container Apps behind the gateway. A client address forwarded in a header is only as trustworthy as the hop that wrote it.&lt;/p&gt;

&lt;p&gt;All of that protects the gateway. The function app is a separate public endpoint, and the obvious idea, letting it accept traffic only from API Management's address, doesn't work on Basic v2:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf5clv54z7ax3cj9vpic.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuf5clv54z7ax3cj9vpic.png" alt="Network options for API Management v2 tiers: Basic v2 has no VNet integration, no VNet injection, no inbound private endpoint and no deterministic outbound IP" width="800" height="209"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The v2 tiers and Consumption run "on a shared infrastructure and without a deterministic IP address" (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-ip-addresses" rel="noopener noreferrer"&gt;IP addresses in API Management&lt;/a&gt;). An access restriction on the function app could only allow the whole region's Azure address ranges, which admits every Azure customer in that region. The &lt;code&gt;ApiManagement&lt;/code&gt; service tag doesn't help either: it covers the management endpoint, not the gateway's outgoing calls. The Functions security page suggests restricting the function app to "the IP address of your APIM instance"; that needs a tier with a stable address, and neither Consumption nor any v2 tier has one.&lt;/p&gt;

&lt;p&gt;Network isolation of the backend starts at Standard v2, with VNet integration for reaching private backends and inbound private endpoints; Premium v2 can also put the gateway inside your network. The &lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" rel="noopener noreferrer"&gt;v2 tier overview&lt;/a&gt; answers the obvious follow-up in its FAQ: a Basic v2 or Standard v2 instance can't be deployed entirely inside your virtual network.&lt;/p&gt;

&lt;p&gt;So on Basic v2, &lt;code&gt;ip-filter&lt;/code&gt; decides who may talk to the gateway, and the managed identity with Easy Auth decides who may talk to the function. The second boundary is an identity. Moving to Standard v2 later adds a network layer on top of it, and the identity check stays.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The two shared secrets from Part 2 now carry much less weight. The subscription key still decides whose quota a call uses, but a leaked one gets nobody past the gateway without a token for orders-api from an app on the allowlist. The function key sits behind Easy Auth until you drop it, and on its own it opens nothing. Access is now decided by identity, checked twice: by the gateway for the partner, and by the function app for the gateway. The checks most likely to be missing are also the quietest, because a token policy without a caller allowlist returns 200 for the right partner, and, with Assignment required off, for every other app in your tenant as well.&lt;/p&gt;

&lt;p&gt;Part 4 moves to the partners' side of the gateway: the developer portal and API versioning.&lt;/p&gt;

&lt;p&gt;Does your gateway's token check pin the calling apps, or would a token from any app in your tenant get through?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azureapimanagement</category>
      <category>infrastructure</category>
      <category>api</category>
    </item>
    <item>
      <title>Azure API Management Policies: Scopes, Rate Limits and Caching</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 16 Oct 2026 05:12:29 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-api-management-policies-scopes-rate-limits-and-caching-5c0j</link>
      <guid>https://dev.to/martin_oehlert/azure-api-management-policies-scopes-rate-limits-and-caching-5c0j</guid>
      <description>&lt;p&gt;Why did adding a cache to one operation switch off the partner rate limit for that operation? Policies in API Management don't override each other by scope: the gateway runs the policy at the narrowest scope, and one &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; element decides whether, and where, everything above it runs too. Leave it out and the gateway saves your XML without a warning and skips the product and API rules for that section.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;policy&lt;/strong&gt; is a set of runtime rules the gateway applies to every call: check a limit, rewrite a header, pick a backend, cache a response. It has nothing to do with Azure Policy, which governs how resources are configured; APIM policies act on requests. Microsoft ships &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-policies" rel="noopener noreferrer"&gt;more than 75 of them&lt;/a&gt;. Part 1 already left one in the order API of the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;: it routes calls to the function backend and removes the subscription key header before the call leaves the gateway. This part adds a policy at each of the other scopes and breaks one of them on purpose, on a Basic v2 instance, to see what a missing &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Anatomy of a policy document
&lt;/h2&gt;

&lt;p&gt;This is the API policy as Part 1 left it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-func"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Every policy document has this shape: a &lt;code&gt;&amp;lt;policies&amp;gt;&lt;/code&gt; root and four sections, and the statements inside a section run top to bottom.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;inbound&lt;/code&gt;&lt;/strong&gt; runs on the request first: authentication, rate limits, cache lookups, routing, request rewrites. Here it picks the &lt;code&gt;orders-func&lt;/code&gt; backend, which carries the function key, and deletes the subscription key header so the function never logs it.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;backend&lt;/code&gt;&lt;/strong&gt; runs right before the gateway forwards the request. The forward itself is a policy, &lt;code&gt;&amp;lt;forward-request /&amp;gt;&lt;/code&gt;, and it sits in this section at global scope, which is why the API policy has nothing but &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; there.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;outbound&lt;/code&gt;&lt;/strong&gt; runs on the response: response headers, &lt;code&gt;cache-store&lt;/code&gt;, body transformations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;on-error&lt;/code&gt;&lt;/strong&gt; runs only when something above fails. The gateway skips the rest of the pipeline and jumps here, with the failure in &lt;code&gt;context.LastError&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Not every policy works in every section or at every scope: &lt;a href="https://learn.microsoft.com/azure/api-management/rate-limit-policy" rel="noopener noreferrer"&gt;&lt;code&gt;rate-limit&lt;/code&gt;&lt;/a&gt; is allowed in &lt;code&gt;inbound&lt;/code&gt; only, and at product, API and operation scope but not globally. Each policy's reference page has a &lt;strong&gt;Usage&lt;/strong&gt; block listing the sections, scopes and gateway types it supports; read it before you write the element.&lt;/p&gt;

&lt;p&gt;In the portal, every scope has its own code editor, and it saves whatever parses. It doesn't tell you that a section lost its &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt;. The sample keeps one XML file per scope in &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo/infra/policies" rel="noopener noreferrer"&gt;&lt;code&gt;infra/policies/&lt;/code&gt;&lt;/a&gt; and loads each into a policy resource in &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/apim.bicep" rel="noopener noreferrer"&gt;&lt;code&gt;infra/apim.bicep&lt;/code&gt;&lt;/a&gt;. Every scope has its own resource type, and all of them are named &lt;code&gt;policy&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource globalPolicy 'Microsoft.ApiManagement/service/policies@2024-05-01' = {
  parent: apim
  name: 'policy'
  properties: {
    format: 'rawxml'
    value: loadTextContent('policies/global.xml')
  }
}

resource getOrder 'Microsoft.ApiManagement/service/apis/operations@2024-05-01' existing = {
  parent: ordersApi
  name: 'get-order'
}

resource getOrderPolicy 'Microsoft.ApiManagement/service/apis/operations/policies@2024-05-01' = {
  parent: getOrder
  name: 'policy'
  properties: {
    format: 'rawxml'
    value: loadTextContent('policies/operation-get-order.xml')
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Product and API policies are &lt;code&gt;service/products/policies&lt;/code&gt; and &lt;code&gt;service/apis/policies&lt;/code&gt;, same body. The operation is declared &lt;code&gt;existing&lt;/code&gt; because the OpenAPI import created it. Use &lt;code&gt;rawxml&lt;/code&gt;, not &lt;code&gt;xml&lt;/code&gt;: with &lt;code&gt;xml&lt;/code&gt;, the &lt;code&gt;"&lt;/code&gt; and &lt;code&gt;&amp;lt;&lt;/code&gt; inside policy expressions have to be XML-encoded, and the file stops looking like the policy the portal shows. A diff on a policy then stays a diff on XML, which is what Parts 5 and 6 build on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four scopes, one pipeline
&lt;/h2&gt;

&lt;p&gt;The sample now has a policy at every scope. The product &lt;code&gt;orders-partners&lt;/code&gt; limits each partner subscription to 10 calls a minute with &lt;code&gt;&amp;lt;rate-limit calls="10" renewal-period="60" /&amp;gt;&lt;/code&gt;. The operation &lt;code&gt;GET /orders/{orderId}&lt;/code&gt; caches responses for 30 seconds, separately for each subscription (the &lt;code&gt;x-partner&lt;/code&gt; header comes from the API policy; the caching section shows why the cache needs it):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;cache-lookup&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer-groups=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;vary-by-header&amp;gt;&lt;/span&gt;x-partner&lt;span class="nt"&gt;&amp;lt;/vary-by-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/cache-lookup&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;cache-store&lt;/span&gt; &lt;span class="na"&gt;duration=&lt;/span&gt;&lt;span class="s"&gt;"30"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; is where the parent runs
&lt;/h3&gt;

&lt;p&gt;The scopes go from broadest to narrowest: &lt;strong&gt;global&lt;/strong&gt; (all APIs), &lt;strong&gt;workspace&lt;/strong&gt; (only if you use workspaces), &lt;strong&gt;product&lt;/strong&gt;, &lt;strong&gt;API&lt;/strong&gt;, &lt;strong&gt;operation&lt;/strong&gt;. When Contoso calls &lt;code&gt;GET /orders/{orderId}&lt;/code&gt;, the gateway doesn't run four policies and let the narrow ones win. It runs one: the operation's. Each &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; in it is a placeholder for the same section one scope up, and that section's &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; pulls in the next one, up to global.&lt;/p&gt;

&lt;p&gt;Resolved, the &lt;code&gt;inbound&lt;/code&gt; the gateway runs for that call looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- global --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"x-correlation-id"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"skip"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.RequestId.ToString())&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- product: orders-partners --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;rate-limit&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"10"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- API: orders --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ip-filter&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"forbid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;address-range&lt;/span&gt; &lt;span class="na"&gt;from=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.0"&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.255"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ip-filter&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-func"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"x-partner"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Subscription?.Id ?? "none")&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@(context.Request.Method == "&lt;/span&gt;&lt;span class="err"&gt;POST")"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;rate-limit-by-key&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt;
          &lt;span class="na"&gt;counter-key=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;create-order:"&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;context.Subscription.Id)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
  &lt;span class="c"&gt;&amp;lt;!-- operation: get-order --&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;cache-lookup&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer-groups=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;vary-by-header&amp;gt;&lt;/span&gt;x-partner&lt;span class="nt"&gt;&amp;lt;/vary-by-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/cache-lookup&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The policy editor in the portal has a &lt;strong&gt;Calculate effective policy&lt;/strong&gt; button that shows the merged result for the scope you're on. The management API returns the same thing if you add &lt;code&gt;effective=true&lt;/code&gt; to a policy GET, which is handy in a pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az rest &lt;span class="nt"&gt;--method&lt;/span&gt; get &lt;span class="nt"&gt;--url&lt;/span&gt; &lt;span class="s2"&gt;".../service/&amp;lt;apim&amp;gt;/apis/orders/operations/get-order/policies/policy?api-version=2024-05-01&amp;amp;effective=true"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the sample it came back with &lt;code&gt;&amp;lt;!--base: Begin Api scope--&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;!--base: Begin Global scope--&amp;gt;&lt;/code&gt; comments around each spliced section, and without the product's rate limit. Which product applies depends on the subscription key of the call, so a view from the operation can't know it.&lt;/p&gt;

&lt;p&gt;Where &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; sits decides the order. The sample puts it first in every section, as &lt;a href="https://learn.microsoft.com/azure/api-management/set-edit-policies#use-base-element-to-set-policy-evaluation-order" rel="noopener noreferrer"&gt;Microsoft recommends&lt;/a&gt;, so the rate limit runs before the cache lookup and a cached response still costs the partner a call. On the live instance, Contoso created one order and then read it back twelve times: the first read went to the function, the next nine came from the cache (all with the first response's correlation ID), and calls 11 and 12 got &lt;code&gt;429 Too Many Requests&lt;/code&gt; with &lt;code&gt;Retry-After: 4&lt;/code&gt;. Counting the POST, that's 11 calls through a limit of 10; the token bucket below explains the extra one. Move &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; below &lt;code&gt;cache-lookup&lt;/code&gt; and the operation's own statement runs first: cache hits skip the rate limit, and the lookup builds its key before the API policy has set &lt;code&gt;x-partner&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove it and the parent is gone
&lt;/h3&gt;

&lt;p&gt;This is the operation policy someone writes when they add the cache by hand and start &lt;code&gt;inbound&lt;/code&gt; from an empty section:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;cache-lookup&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer-groups=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;vary-by-header&amp;gt;&lt;/span&gt;x-partner&lt;span class="nt"&gt;&amp;lt;/vary-by-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/cache-lookup&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;cache-store&lt;/span&gt; &lt;span class="na"&gt;duration=&lt;/span&gt;&lt;span class="s"&gt;"30"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I pushed it to the Basic v2 instance with &lt;code&gt;az rest --method put&lt;/code&gt; on the operation's &lt;code&gt;policies/policy&lt;/code&gt; resource. The management API answered 200 and echoed the policy back. No warning, no validation error.&lt;/p&gt;

&lt;p&gt;Twelve calls to &lt;code&gt;GET /orders/{orderId}&lt;/code&gt; with Contoso's key then returned twelve &lt;code&gt;401 Unauthorized&lt;/code&gt; responses with an empty body, and no 429. The gateway didn't produce those 401s. With the API's &lt;code&gt;inbound&lt;/code&gt; gone, &lt;code&gt;set-backend-service&lt;/code&gt; never ran, so the gateway sent the call to the API's plain service URL, without the &lt;code&gt;x-functions-key&lt;/code&gt; header the backend entity adds, and the function host rejected it. &lt;code&gt;GET /orders&lt;/code&gt;, which has no operation policy, kept answering 200 at the same time.&lt;/p&gt;

&lt;p&gt;A 401 is the lucky case, because someone notices. The likely fix is to copy &lt;code&gt;&amp;lt;set-backend-service backend-id="orders-func" /&amp;gt;&lt;/code&gt; into the operation's &lt;code&gt;inbound&lt;/code&gt;, see 200s again, and move on. I did that too: 20 calls in 8 seconds, 20 times &lt;code&gt;200 OK&lt;/code&gt;, against a product limit of 10 per minute. Nothing in the response, the portal or the deployment tells you the partner limit is off for this one operation, and it's the one partners poll.&lt;/p&gt;

&lt;p&gt;Only the section without &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; loses its parent. The operation above still has it in &lt;code&gt;outbound&lt;/code&gt; and &lt;code&gt;on-error&lt;/code&gt;, so those chains run as before.&lt;/p&gt;

&lt;p&gt;Two checks catch this before production: the effective policy view shows an &lt;code&gt;inbound&lt;/code&gt; without the API and global statements, and Azure Policy has a &lt;a href="https://learn.microsoft.com/azure/api-management/policy-reference" rel="noopener noreferrer"&gt;built-in definition&lt;/a&gt;, &lt;em&gt;API Management policies should inherit parent scope policies using &lt;code&gt;&amp;lt;base/&amp;gt;&lt;/code&gt;&lt;/em&gt;, that audits or denies policy documents without it. Part 5 puts that into the pipeline.&lt;/p&gt;

&lt;h3&gt;
  
  
  Which subscription you call with changes which scopes run
&lt;/h3&gt;

&lt;p&gt;Product policies run only for calls made with a product-scoped subscription. Learn says it in a note on the &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" rel="noopener noreferrer"&gt;subscriptions page&lt;/a&gt;: "If you're using an API-scoped subscription, an all-APIs subscription, or the built-in all-access subscription, policies configured at the product scope aren't applied to requests from that subscription."&lt;/p&gt;

&lt;p&gt;On the sample, 20 calls to &lt;code&gt;GET /orders&lt;/code&gt; with the built-in all-access key all returned 200. The same 20 calls with Contoso's product key: 11 times 200, then 429. The portal's test console uses the all-access key by default, so a product rate limit you hammer from there never fires, and it looks broken when it isn't. Test product policies with a product subscription key from outside the portal.&lt;/p&gt;

&lt;p&gt;The count wasn't exactly 10 either; two separate bursts got 11 calls through. The v2 tiers rate-limit with a token bucket, and &lt;a href="https://learn.microsoft.com/azure/api-management/rate-limit-policy" rel="noopener noreferrer"&gt;Learn warns&lt;/a&gt; that rate limiting "is never completely accurate". Write "about 10 a minute" into the partner contract, not "the 11th call fails".&lt;/p&gt;

&lt;h3&gt;
  
  
  Picking a scope
&lt;/h3&gt;

&lt;p&gt;Global runs for every API on the instance, so keep it to what applies everywhere: the correlation ID, response headers that leak your stack, and the &lt;code&gt;&amp;lt;forward-request /&amp;gt;&lt;/code&gt; that sends every call on. The product is where the consumer lives, so per-partner limits and quotas go there, and a second product for internal tools can carry different numbers for the same API. The API owns what's true for the backend regardless of caller: routing to &lt;code&gt;orders-func&lt;/code&gt;, stripping the key header, later the managed identity from Part 3. Operations are for exceptions, and each one is another place where a missing &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; switches the scopes above it off.&lt;/p&gt;

&lt;h2&gt;
  
  
  Policies the order API needs
&lt;/h2&gt;

&lt;p&gt;Most of what the order API needs is true no matter who calls it, so it goes into &lt;a href="https://github.com/MO2k4/azure-functions-samples/blob/main/ApimOrdersDemo/infra/policies/api-orders.xml" rel="noopener noreferrer"&gt;&lt;code&gt;api-orders.xml&lt;/code&gt;&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ip-filter&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"forbid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;address-range&lt;/span&gt; &lt;span class="na"&gt;from=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.0"&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.255"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ip-filter&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-func"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"x-partner"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Subscription?.Id ?? "none")&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@(context.Request.Method == "&lt;/span&gt;&lt;span class="err"&gt;POST")"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;rate-limit-by-key&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt;
            &lt;span class="na"&gt;counter-key=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;create-order:"&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;context.Subscription.Id)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All of it was deployed through Bicep to the Basic v2 instance, which doubles as the schema check: the management API compiles every expression when it saves a policy. The status codes below are the ones that instance returned.&lt;/p&gt;

&lt;h3&gt;
  
  
  A second limit for placing orders
&lt;/h3&gt;

&lt;p&gt;Reading an order is cheap; placing one writes to the store and, in a real system, starts fulfillment. So &lt;code&gt;POST /orders&lt;/code&gt; gets its own limit of 3 a minute per partner, on top of the product's 10. That can't be a second &lt;code&gt;rate-limit&lt;/code&gt;: Learn says the policy "can be used only once per policy definition", and the product's is already part of every partner call. &lt;a href="https://learn.microsoft.com/azure/api-management/rate-limit-by-key-policy" rel="noopener noreferrer"&gt;&lt;code&gt;rate-limit-by-key&lt;/code&gt;&lt;/a&gt; counts per key, and the key is whatever string you compute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;rate-limit-by-key&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt;
    &lt;span class="na"&gt;counter-key=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;create-order:"&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;context.Subscription.Id)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For Contoso the key evaluates to &lt;code&gt;create-order:contoso-shop&lt;/code&gt;. The prefix is there because counters belong to the key, not to the policy: every &lt;code&gt;rate-limit-by-key&lt;/code&gt; that produces the same string, at any scope, draws from the same bucket. Key a second limit on the bare subscription ID somewhere else and the two quietly share one counter.&lt;/p&gt;

&lt;p&gt;Contoso placed five orders in a row. Four came back &lt;code&gt;201 Created&lt;/code&gt;, the fifth got &lt;code&gt;429&lt;/code&gt; with &lt;code&gt;Retry-After: 19&lt;/code&gt;; the token bucket let one extra call through, as it did for the product limit. Two &lt;code&gt;GET /orders&lt;/code&gt; right after the 429 returned 200, because the limit only runs for POST. Fabrikam, a second partner subscription on the same product, placed an order at the same moment and got 201: its key is &lt;code&gt;create-order:fabrikam&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Plain &lt;code&gt;rate-limit&lt;/code&gt; counts per subscription only, but it runs on every tier. &lt;code&gt;rate-limit-by-key&lt;/code&gt; can count per anything (the subscription, &lt;code&gt;context.Request.IpAddress&lt;/code&gt; for anonymous APIs, a claim, a tenant header) and also works at global scope, but not on Consumption, and you find out at save time: the management API refused it on a Consumption instance with &lt;code&gt;Policy is not allowed in 'Consumption' sku&lt;/code&gt;. From this part on, the sample deploys Basic v2 by default.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching &lt;code&gt;GET /orders/{orderId}&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;My first version of the operation policy cached with &lt;code&gt;vary-by-developer="true"&lt;/code&gt;, which reads like "one cache per partner". It isn't. &lt;a href="https://learn.microsoft.com/azure/api-management/cache-lookup-policy" rel="noopener noreferrer"&gt;Learn defines it&lt;/a&gt; as caching "per developer account that owns [the] subscription key". Contoso's subscription comes from Bicep, and I added Fabrikam's on the same product through the management API. Neither has an owner, so to the cache they are the same developer.&lt;/p&gt;

&lt;p&gt;On the live instance Contoso read an order, a cache miss with a fresh correlation ID. Fabrikam read the same order a second later and got &lt;code&gt;200&lt;/code&gt; with Contoso's cached response, correlation ID included. The sample returns the same order to everyone, so nothing leaked here. In an API that filters by caller, Fabrikam would have been reading Contoso's data, and nothing in the response would have told either of them. Partners who sign up through the developer portal own their subscriptions, so this stays hidden until the day subscriptions come from a pipeline, which is where Parts 5 and 6 are going.&lt;/p&gt;

&lt;p&gt;The fix keys the cache on the subscription itself, through the &lt;code&gt;x-partner&lt;/code&gt; header the API policy sets:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;cache-lookup&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt; &lt;span class="na"&gt;vary-by-developer-groups=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;vary-by-header&amp;gt;&lt;/span&gt;x-partner&lt;span class="nt"&gt;&amp;lt;/vary-by-header&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/cache-lookup&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; comes first in the operation's &lt;code&gt;inbound&lt;/code&gt;, so the API's &lt;code&gt;set-header&lt;/code&gt; has already written &lt;code&gt;x-partner&lt;/code&gt; when the lookup builds its key. Varying on &lt;code&gt;Ocp-Apim-Subscription-Key&lt;/code&gt; instead would put the secret into the cache key, and it wouldn't work here anyway: the API policy deletes that header before the lookup runs. Because &lt;code&gt;x-partner&lt;/code&gt; is set with &lt;code&gt;exists-action="override"&lt;/code&gt;, a caller can't send its own value to borrow someone else's entry.&lt;/p&gt;

&lt;p&gt;After the redeploy, Contoso's first read was a miss and the next three were hits (same correlation ID, 0.21 to 0.25 seconds instead of 0.52). Fabrikam's first read was a miss with its own correlation ID. Fabrikam sending &lt;code&gt;x-partner: contoso-shop&lt;/code&gt; got Fabrikam's entry back.&lt;/p&gt;

&lt;p&gt;Only GET requests are cached, and only &lt;code&gt;200 OK&lt;/code&gt; responses unless you set &lt;code&gt;cache-response="true"&lt;/code&gt; on &lt;code&gt;cache-store&lt;/code&gt;. A hit returns the stored headers too, so per-request tracing headers such as the correlation ID are stale on cached responses. On Consumption the cache policies save, but there's &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-howto-cache" rel="noopener noreferrer"&gt;no built-in cache&lt;/a&gt; behind them.&lt;/p&gt;

&lt;h3&gt;
  
  
  Headers
&lt;/h3&gt;

&lt;p&gt;The global &lt;code&gt;outbound&lt;/code&gt; returns the correlation ID and removes a header that gives away the stack:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"x-correlation-id"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Request.Headers.GetValueOrDefault("x-correlation-id", ""))&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"X-Powered-By"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no &lt;code&gt;remove-header&lt;/code&gt; policy. Removing a header is &lt;a href="https://learn.microsoft.com/azure/api-management/set-header-policy" rel="noopener noreferrer"&gt;&lt;code&gt;set-header&lt;/code&gt;&lt;/a&gt; with &lt;code&gt;exists-action="delete"&lt;/code&gt;; the other values are &lt;code&gt;override&lt;/code&gt; (the default), &lt;code&gt;skip&lt;/code&gt; and &lt;code&gt;append&lt;/code&gt;. In &lt;code&gt;inbound&lt;/code&gt; the statement changes the request the backend receives, in &lt;code&gt;outbound&lt;/code&gt; the response the caller receives. The function doesn't send &lt;code&gt;X-Powered-By&lt;/code&gt;, but ASP.NET on IIS does, which is why the line sits at global scope, ready for the next backend.&lt;/p&gt;

&lt;p&gt;Called directly, the function answered with a &lt;code&gt;Server&lt;/code&gt; header; through the gateway it didn't, with no policy involved. The Application Insights &lt;code&gt;Request-Context&lt;/code&gt; header went the other way: it survived a &lt;code&gt;delete&lt;/code&gt;, because the gateway adds it after &lt;code&gt;outbound&lt;/code&gt; has run. A policy can only remove what's there when it runs.&lt;/p&gt;

&lt;h3&gt;
  
  
  Blocking callers with &lt;code&gt;ip-filter&lt;/code&gt;
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;ip-filter&lt;/span&gt; &lt;span class="na"&gt;action=&lt;/span&gt;&lt;span class="s"&gt;"forbid"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;address-range&lt;/span&gt; &lt;span class="na"&gt;from=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.0"&lt;/span&gt; &lt;span class="na"&gt;to=&lt;/span&gt;&lt;span class="s"&gt;"203.0.113.255"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/ip-filter&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://learn.microsoft.com/azure/api-management/ip-filter-policy" rel="noopener noreferrer"&gt;&lt;code&gt;forbid&lt;/code&gt;&lt;/a&gt; blocks the listed addresses and lets everything else through. &lt;code&gt;allow&lt;/code&gt; is the opposite: anything not listed gets &lt;code&gt;403 Forbidden&lt;/code&gt;. The sample forbids a documentation range (203.0.113.0/24 is reserved for examples) so it works for whoever deploys it; replace it with what you want to block, or switch to &lt;code&gt;allow&lt;/code&gt; with your partners' ranges.&lt;/p&gt;

&lt;p&gt;Switching the sample to &lt;code&gt;allow&lt;/code&gt; with that range locked me out within 20 seconds. The reverse test, a &lt;code&gt;forbid&lt;/code&gt; with my public address as a lookup service reported it, changed nothing for five minutes: the gateway saw a different address. Before you write an allow-list, echo &lt;code&gt;context.Request.IpAddress&lt;/code&gt; into a response header from a test policy and use what the gateway reports. Behind Azure Front Door or any other proxy, the gateway sees the proxy, not the partner; &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;What Each Hop Trusts&lt;/a&gt; covers which address each hop can rely on.&lt;/p&gt;

&lt;h2&gt;
  
  
  Policy expressions: C# inside the XML
&lt;/h2&gt;

&lt;p&gt;These are the expressions in the sample:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.RequestId.ToString())&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Subscription?.Id ?? "none")&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@(context.Request.Method == "&lt;/span&gt;&lt;span class="err"&gt;POST")"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
counter-key="@("create-order:" + context.Subscription.Id)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;@(...)&lt;/code&gt; holds one C# expression, and its value becomes the attribute value or the element text. Most attributes accept one; the reference page says when an attribute doesn't (&lt;code&gt;rate-limit&lt;/code&gt; takes none in &lt;code&gt;calls&lt;/code&gt; or &lt;code&gt;renewal-period&lt;/code&gt;). Everything the gateway knows about the call is on &lt;code&gt;context&lt;/code&gt;: the request and response, the subscription, product and user, the API and operation, your own &lt;code&gt;context.Variables&lt;/code&gt;, and &lt;code&gt;context.LastError&lt;/code&gt; in &lt;code&gt;on-error&lt;/code&gt;. &lt;code&gt;Subscription&lt;/code&gt; is &lt;code&gt;null&lt;/code&gt; on APIs that don't require a key, hence the &lt;code&gt;?.&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@{ ... }&lt;/code&gt; holds a block of statements, and every path through it has to end in &lt;code&gt;return&lt;/code&gt;. This one, tried on the live instance but not in the sample, forwards the customer ID from the order body as a header:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"x-customer-id"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@{
    if (context.Request.Method != "POST") { return ""; }
    var order = context.Request.Body.As&lt;span class="nt"&gt;&amp;lt;JObject&amp;gt;&lt;/span&gt;(preserveContent: true);
    return (string)order["customerId"] ?? "";
  }&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading the body consumes it. With &lt;code&gt;preserveContent: false&lt;/code&gt; the header still came out right (&lt;code&gt;C-2001&lt;/code&gt;), but the function received an empty body and answered &lt;code&gt;500&lt;/code&gt;. The XML saved without complaint; only the call failed.&lt;/p&gt;

&lt;p&gt;The language is C# 7, not the C# 14 the function is written in, and only an allow-listed set of .NET types is available: &lt;code&gt;System.Linq&lt;/code&gt;, &lt;code&gt;System.Text.RegularExpressions&lt;/code&gt;, &lt;code&gt;Newtonsoft.Json.Linq&lt;/code&gt; (where &lt;code&gt;JObject&lt;/code&gt; comes from) and a few dozen more, listed on the &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-policy-expressions" rel="noopener noreferrer"&gt;policy expressions page&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  What the save checks, and what it doesn't
&lt;/h3&gt;

&lt;p&gt;The save compiles the expressions. A typo in the &lt;code&gt;&amp;lt;choose&amp;gt;&lt;/code&gt; condition (&lt;code&gt;context.Request.Methd&lt;/code&gt;) got a &lt;code&gt;400 ValidationError&lt;/code&gt; back: "'IRequest' does not contain a definition for 'Methd'".&lt;/p&gt;

&lt;p&gt;An expression that compiles but throws gets through. &lt;code&gt;@(context.Request.Headers["x-tenant"][0])&lt;/code&gt; saved fine. Every call without an &lt;code&gt;x-tenant&lt;/code&gt; header then returned &lt;code&gt;500 Internal server error&lt;/code&gt; with no correlation ID; calls with the header returned 200. Learn calls the save-time check "limited verification", and any exception at runtime goes to &lt;code&gt;on-error&lt;/code&gt;. Use &lt;code&gt;GetValueOrDefault&lt;/code&gt; on headers and &lt;code&gt;?.&lt;/code&gt; on anything that can be missing, and test the paths where the input is absent.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conditions with &lt;code&gt;&amp;lt;choose&amp;gt;&lt;/code&gt;
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@(context.Request.Method == "&lt;/span&gt;&lt;span class="err"&gt;POST")"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rate-limit-by-key&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"3"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt;
        &lt;span class="na"&gt;counter-key=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;create-order:"&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;context.Subscription.Id)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://learn.microsoft.com/azure/api-management/choose-policy" rel="noopener noreferrer"&gt;&lt;code&gt;&amp;lt;choose&amp;gt;&lt;/code&gt;&lt;/a&gt; takes one or more &lt;code&gt;&amp;lt;when&amp;gt;&lt;/code&gt; elements and an optional &lt;code&gt;&amp;lt;otherwise&amp;gt;&lt;/code&gt;. The gateway runs the first &lt;code&gt;when&lt;/code&gt; whose condition is &lt;code&gt;true&lt;/code&gt; and skips the rest, so put the narrow cases first. If nothing matches and there's no &lt;code&gt;otherwise&lt;/code&gt;, nothing happens. The body can hold any policy allowed in that section, including another &lt;code&gt;&amp;lt;choose&amp;gt;&lt;/code&gt;, and it works in all four sections, at every scope, on every tier.&lt;/p&gt;

&lt;p&gt;The same limit could have gone into an operation policy on &lt;code&gt;create-order&lt;/code&gt;. That adds one more operation-scope file, with its own &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; in every section to get right. The &lt;code&gt;&amp;lt;choose&amp;gt;&lt;/code&gt; keeps the rule in the API policy, next to the routing it belongs with.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The management API refused two things in this part: a misspelled property and a policy the tier doesn't support. Everything else saved, including an &lt;code&gt;inbound&lt;/code&gt; without &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; that switched off the partner limit, a &lt;code&gt;vary-by-developer="true"&lt;/code&gt; that shared one cache entry between two partners, and a header lookup that turned every call without the header into a 500. The save checks syntax and compiles expressions; it doesn't know who owns a subscription, which address the gateway sees, or what the gateway adds after &lt;code&gt;outbound&lt;/code&gt;. A call with each partner's key, read for status codes and headers, does. Part 3 builds on these files: &lt;code&gt;validate-jwt&lt;/code&gt; in front of the order API and a managed identity to the function instead of the key in a named value.&lt;/p&gt;

&lt;p&gt;Do your partner subscriptions have an owner in API Management, or does a pipeline create them?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>azureapimanagement</category>
      <category>api</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>Introduction to Azure API Management</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 09 Oct 2026 18:12:54 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/introduction-to-azure-api-management-4jmn</link>
      <guid>https://dev.to/martin_oehlert/introduction-to-azure-api-management-4jmn</guid>
      <description>&lt;p&gt;Which API Management tier goes in front of an order API that gets 5 million calls a month and none at night? Consumption bills about $14 for that month and nothing while the API sits idle, Basic v2 bills about $150, and you can't move from one to the other later without building a new instance. That last part turns a pricing choice into a day-one architecture decision.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Azure API Management&lt;/strong&gt; (APIM) is a managed gateway between the callers of your API and the backends that serve it: Azure Functions, Container Apps, App Service, or anything else that answers HTTP. Callers see one hostname and one contract. The gateway takes over the jobs that otherwise end up scattered: function keys mailed to partners and never rotated, rate limiting copied into every function, an API reference in a wiki that drifted two releases ago, a reverse proxy on a VM you patch yourself.&lt;/p&gt;

&lt;p&gt;The running example for this series is an order API: an Azure Functions app on the isolated worker model and .NET 10, in the &lt;code&gt;ApimOrdersDemo&lt;/code&gt; folder of the &lt;a href="https://github.com/MO2k4/azure-functions-samples" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;. It starts small and public on purpose. If you already need the enterprise version (Front Door at the edge, APIM Standard v2 on a private endpoint, Container Apps behind it), &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;What Each Hop Trusts&lt;/a&gt; walks that chain one hop at a time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Pick the tier before you deploy anything
&lt;/h2&gt;

&lt;p&gt;The sentence that decides most of this section sits in the scaling docs: "Currently, you cannot upgrade from or downgrade to the Consumption tier" (&lt;a href="https://learn.microsoft.com/azure/api-management/upgrade-and-scale" rel="noopener noreferrer"&gt;upgrade and scale&lt;/a&gt;). The other families have walls too. Classic tiers change among themselves in place, Basic v2 and Standard v2 change between each other, and nothing crosses from classic or Consumption into v2, because v2 is &lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" rel="noopener noreferrer"&gt;available for newly created service instances only&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Crossing a wall means a new instance, with a new &lt;code&gt;*.azure-api.net&lt;/code&gt; hostname and new subscription keys. The cheap insurance is a &lt;strong&gt;custom domain&lt;/strong&gt; on the gateway from the first deploy (&lt;code&gt;api.contoso.com&lt;/code&gt; instead of &lt;code&gt;apim-orders.azure-api.net&lt;/code&gt;), which turns a later move into a DNS change on your side. The keys still change unless you copy their values across; subscriptions accept explicit primary and secondary key values, which is the escape hatch for that day.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three families, eight tiers
&lt;/h3&gt;

&lt;p&gt;APIM comes in three families (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-key-concepts" rel="noopener noreferrer"&gt;key concepts&lt;/a&gt;):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Consumption&lt;/strong&gt;: a "serverless gateway ... that scales based on demand and bills per execution". No units, no idle cost.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Classic&lt;/strong&gt;: Developer, Basic, Standard, Premium. You pay per unit per hour and calls are unlimited.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;v2&lt;/strong&gt;: Basic v2, Standard v2, Premium v2. Also billed per unit; Basic v2 and Standard v2 include a call allowance and meter the calls past it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;v2 does not replace classic. The &lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" rel="noopener noreferrer"&gt;v2 overview&lt;/a&gt; says "there are no changes to the classic Developer, Basic, Standard, or Premium tiers", and there is no retirement date. If you start fresh, "classic is legacy" is not a reason to pick v2; the features further down are.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbmxzbb6oj0richg689mt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbmxzbb6oj0richg689mt.png" alt="Price, included calls, SLA and maximum units for the eight API Management tiers, West Europe list prices, October 2026" width="800" height="474"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Prices are pay-as-you-go list prices in USD for West Europe, an hourly unit price times 730 hours, from the &lt;a href="https://azure.microsoft.com/pricing/details/api-management/" rel="noopener noreferrer"&gt;pricing page&lt;/a&gt; and the Azure Retail Prices API on 2026-10-02. SLAs come from the same pricing page, unit limits from the &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-features" rel="noopener noreferrer"&gt;feature comparison&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Developer is the tier without an SLA.&lt;/strong&gt; It has almost every feature, VNet injection included, but Microsoft scopes it to "non-production use cases and evaluations", it can't scale past one unit, and moving to or from it causes downtime. Labs only.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Consumption has an SLA&lt;/strong&gt;: 99.95%, the same number as Basic, Standard, Basic v2 and Standard v2. What it doesn't have is a unit that stays warm. Capacity is assigned when traffic arrives, so the first call after a quiet spell waits for the gateway. Microsoft publishes no number for that delay; the closest thing to an official statement is an &lt;a href="https://learn.microsoft.com/answers/questions/2133461/understanding-api-manegment-performance" rel="noopener noreferrer"&gt;accepted answer on Microsoft Q&amp;amp;A&lt;/a&gt; that says it "spins up resources on-demand. This can lead to cold start delays, especially if there are infrequent or intermittent requests." An availability SLA promises that the gateway answers, not how long the first answer takes.&lt;/p&gt;

&lt;p&gt;So I measured it on the sample from this article: a Consumption gateway in front of a Flex Consumption function, West Europe, 2 October 2026, curl from outside Azure with a new TLS connection per call, and Application Insights on both layers so every call splits into gateway time and backend time. Warm, a call through the gateway took a median of 0.29 seconds (29 calls), against 0.20 seconds straight to the function. After 31 minutes without traffic, five times: with both layers cold, the first call took 46.0, 9.4 and 17.0 seconds. With the function woken first, so only the gateway was cold, it took 50.5 seconds once; the other time the call hung in the TLS handshake for 120 seconds and failed, and the retry took 51.9 seconds.&lt;/p&gt;

&lt;p&gt;Application Insights shows where the time went. The function added about 2 seconds whenever it was cold, and the gateway's own processing never took more than a third of a second (333 ms at worst, 0 to 2 ms warm). The rest, 15 to 50 seconds in four of the five windows, passed after the TLS handshake and before the gateway logged the request at all, which points at the Consumption gateway getting capacity assigned. The 9.4-second call was the exception, mostly my own DNS lookup. An earlier run the same day without Application Insights saw 59.8 seconds once, which fits that pattern, but also gateway-only cold calls of 1.3 and 1.5 seconds, so the long wait doesn't happen every time. Nine cold windows on two deployments are not a distribution, but they put the tail on the gateway side, at tens of seconds, and nothing in the SLA bounds it.&lt;/p&gt;

&lt;p&gt;The 99.99% on Premium and Premium v2 isn't automatic either: it needs the instance spread across two or more availability zones (or, on classic Premium, regions), which means at least two units on the bill.&lt;/p&gt;

&lt;h3&gt;
  
  
  The capabilities that decide it
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwsu0xjy23biumo15m9h3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwsu0xjy23biumo15m9h3.png" alt="Inbound private endpoint, VNet, availability zones, multi-region, self-hosted gateway, cache, developer portal and per-key limits for each API Management tier" width="800" height="536"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sources: &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-features" rel="noopener noreferrer"&gt;feature comparison&lt;/a&gt;, &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-gateways-overview" rel="noopener noreferrer"&gt;gateways overview&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The network rows decide more often than price does. If the backend lives in a VNet, Consumption, Basic, Basic v2 and classic Standard are out. Standard v2 is the cheapest tier that takes an inbound private endpoint and also reaches into a VNet outbound, which is why the enterprise chain in What Each Hop Trusts runs on it. Zones leave the two Premium tiers, and multi-region or a self-hosted gateway in your own datacenter leaves classic Premium alone.&lt;/p&gt;

&lt;p&gt;The Consumption column has gaps that come back later in this series. The per-key policies &lt;code&gt;rate-limit-by-key&lt;/code&gt; and &lt;code&gt;quota-by-key&lt;/code&gt; don't run there, so "100 calls per minute per partner" needs another tier (plain &lt;code&gt;rate-limit&lt;/code&gt; and &lt;code&gt;quota&lt;/code&gt; scoped to a subscription do work; Part 2 covers the difference). There's no built-in cache, no developer portal, which is all of Part 4, and request logs go to Application Insights only.&lt;/p&gt;

&lt;h3&gt;
  
  
  Where the per-call meter stops winning
&lt;/h3&gt;

&lt;p&gt;The usual advice is "Consumption for low volume, a unit-based tier once traffic grows". The crossover sits much higher than that suggests, because Basic v2 and Standard v2 meter calls too once the allowance runs out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;monthly cost in USD, n = millions of calls per month

Consumption  = 3.50 * (n - 1)
Basic v2     = 150 + 3.00 * max(0, n - 10)
Standard v2  = 700 + 2.50 * max(0, n - 50)

Consumption = Basic v2     when  n = ~247
Consumption = Standard v2  when  n = ~579
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At 5M calls that's $14 against $150 against $700. The Consumption and Basic v2 lines only meet at about 247M calls a month, roughly 95 requests per second around the clock, and by then one Basic v2 unit may need a second. On list price alone, very few APIs leave Consumption to save money. You leave it for the first call, for the features above, or because the network forces you to.&lt;/p&gt;

&lt;h3&gt;
  
  
  Basic v2, and the order the constraints bite
&lt;/h3&gt;

&lt;p&gt;Microsoft positions Basic v2 as "designed for development and testing scenarios, and it comes with an SLA" (&lt;a href="https://learn.microsoft.com/azure/api-management/v2-service-tiers-overview" rel="noopener noreferrer"&gt;v2 overview&lt;/a&gt;). The label is narrower than the product: Basic v2 is the cheapest tier with an SLA and a unit that stays warm, and it runs the full policy set and the developer portal. For a low-volume production API where a person waits on the first call of the morning, it's what I'd run. Its ceiling is no private endpoint, no VNet, no zones and 10 units, and the way past it is the one in-place move v2 allows: Basic v2 to Standard v2, same instance, same hostname, same keys. Consumption has no such path.&lt;/p&gt;

&lt;p&gt;Put together, the tier falls out of three questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Does the backend live in a VNet, or must the gateway be private?&lt;/strong&gt; Standard v2. Add zones or very high scale and it's Premium v2. Multi-region or a self-hosted gateway means classic Premium, the only tier with either.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Does a person wait on the first call after a quiet period, or do you need per-key limits, the developer portal or Log Analytics request logs?&lt;/strong&gt; Basic v2.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Neither?&lt;/strong&gt; Consumption. Machine-to-machine traffic, spiky or idle most of the day, in front of a serverless backend, is what it was built for.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Classic Basic and Standard still make sense when you need something v2 lacks today, such as backup and restore or a static IP. The order API in this series starts on Consumption because it costs nothing while you read, and the sample's &lt;code&gt;apimSku&lt;/code&gt; parameter switches it to Basic v2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four nouns: API, operation, product, subscription
&lt;/h2&gt;

&lt;p&gt;Everything you configure hangs off one service resource, and the nesting already tells you most of the model:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Microsoft.ApiManagement/service     the instance: gateway, management plane, developer portal
├── apis                            API: a facade over one backend
│   └── operations                  operation: GET /orders/{orderId}
├── products                        product: what a consumer signs up for
│   └── apis                        which APIs the product contains
└── subscriptions                   subscription: two keys, scoped to a product, an API or all APIs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1aqgwqose93ngb38goc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fe1aqgwqose93ngb38goc.png" alt="A partner request passes the API Management gateway, which maps its key to a subscription, the subscription to a product, the product to the orders API and the URL to an operation before forwarding to the function app" width="712" height="2004"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  APIs and operations
&lt;/h3&gt;

&lt;p&gt;An &lt;strong&gt;API&lt;/strong&gt; in APIM is a facade in front of the service. Its two most important settings point in opposite directions: &lt;code&gt;path&lt;/code&gt; is the URL suffix callers see after the gateway host (&lt;code&gt;apim-orders.azure-api.net/sales&lt;/code&gt;), and &lt;code&gt;serviceUrl&lt;/code&gt; is where the gateway forwards (&lt;code&gt;func-orders.azurewebsites.net/api&lt;/code&gt;). Because they're separate, you can move the backend from Functions to Container Apps without a caller noticing; &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;the migration article&lt;/a&gt; uses APIM backends for exactly that. Every API also carries &lt;code&gt;subscriptionRequired&lt;/code&gt;, which defaults to &lt;code&gt;true&lt;/code&gt;: a freshly imported API rejects calls without a key.&lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;operation&lt;/strong&gt; is one method plus one URL template, such as &lt;code&gt;GET /orders/{orderId}&lt;/code&gt;. You rarely create them by hand, because an OpenAPI import creates one per spec operation and names it after the &lt;code&gt;operationId&lt;/code&gt;. Operations are also the narrowest scope a policy attaches to: a cache on &lt;code&gt;GET /orders/{orderId}&lt;/code&gt; without touching &lt;code&gt;POST /orders&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Products and subscriptions
&lt;/h3&gt;

&lt;p&gt;These two get confused because they always appear together. The split is access versus credential.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;product&lt;/strong&gt; is what a consumer gets access to: one or more APIs, plus the rules for joining. "Requires subscription" decides whether a key is needed at all, and "requires approval" whether a person signs off on new subscriptions. Partners, internal teams and a free trial can be three products over the same API, each with its own limits. Some tiers create two sample products, &lt;strong&gt;Starter&lt;/strong&gt; and &lt;strong&gt;Unlimited&lt;/strong&gt;, on a new instance; lock them down or delete them. Consumption doesn't create them.&lt;/p&gt;

&lt;p&gt;A &lt;strong&gt;subscription&lt;/strong&gt; is the credential: a named pair of keys, primary and secondary, scoped to a product, a single API or all APIs. Despite the name, it has nothing to do with your Azure subscription. Every instance, Consumption included, also has a built-in all-access subscription called &lt;code&gt;master&lt;/code&gt; for the portal's test console. It opens every API, so never hand its keys to anyone.&lt;/p&gt;

&lt;p&gt;One trap inverts the model: a product that doesn't require a subscription makes its APIs callable without a key, and APIM then ignores an invalid key instead of rejecting it. &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;What Each Hop Trusts&lt;/a&gt; has the details and the fix.&lt;/p&gt;

&lt;h3&gt;
  
  
  The gateway and where policies live
&lt;/h3&gt;

&lt;p&gt;An APIM instance has three parts (&lt;a href="https://learn.microsoft.com/azure/api-management/api-management-key-concepts" rel="noopener noreferrer"&gt;key concepts&lt;/a&gt;). The &lt;strong&gt;gateway&lt;/strong&gt; is the data plane: the &lt;code&gt;*.azure-api.net&lt;/code&gt; endpoint that receives every call, checks the key, runs policies and forwards. The &lt;strong&gt;management plane&lt;/strong&gt; is Azure Resource Manager, so the portal, the CLI and Bicep all configure the same resources from the tree above. The &lt;strong&gt;developer portal&lt;/strong&gt; is the generated site where consumers read docs and request keys.&lt;/p&gt;

&lt;p&gt;What the gateway does to a request is defined in &lt;strong&gt;policies&lt;/strong&gt;: XML documents attached at four main scopes (all APIs, product, API, operation). Every one has the same skeleton:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;inbound&lt;/code&gt; runs before the call reaches the backend, &lt;code&gt;backend&lt;/code&gt; around the forward itself, &lt;code&gt;outbound&lt;/code&gt; on the response, and &lt;code&gt;on-error&lt;/code&gt; when anything above fails. &lt;code&gt;&amp;lt;base /&amp;gt;&lt;/code&gt; runs the policies from the next scope up, so an operation policy without it silently drops everything defined for its API and product. That one element is where Part 2 starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Import the order API from its OpenAPI spec
&lt;/h2&gt;

&lt;p&gt;The contract comes first. The sample keeps a hand-written OpenAPI 3.0 file next to the code, and everything APIM knows about the order API comes from it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# openapi/orders.yaml (excerpt)&lt;/span&gt;
&lt;span class="na"&gt;openapi&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;3.0.3&lt;/span&gt;
&lt;span class="na"&gt;info&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;title&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Orders API&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.0.0&lt;/span&gt;
&lt;span class="na"&gt;servers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="c1"&gt;# APIM replaces this with the API's serviceUrl on import.&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;url&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;https://func-orders.azurewebsites.net/api&lt;/span&gt;
&lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;/orders&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;post&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;operationId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;create-order&lt;/span&gt;
      &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Place an order&lt;/span&gt;
      &lt;span class="na"&gt;requestBody&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="na"&gt;content&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;application/json&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
              &lt;span class="na"&gt;$ref&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;#/components/schemas/CreateOrderRequest'&lt;/span&gt;
      &lt;span class="na"&gt;responses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;201'&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Order accepted.&lt;/span&gt;
  &lt;span class="s"&gt;/orders/{orderId}&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;get&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;operationId&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;get-order&lt;/span&gt;
      &lt;span class="na"&gt;summary&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Get one order&lt;/span&gt;
      &lt;span class="na"&gt;parameters&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;orderId&lt;/span&gt;
          &lt;span class="na"&gt;in&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;path&lt;/span&gt;
          &lt;span class="na"&gt;required&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
          &lt;span class="na"&gt;schema&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
            &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;string&lt;/span&gt;
      &lt;span class="na"&gt;responses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;200'&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;The order.&lt;/span&gt;
        &lt;span class="s1"&gt;'&lt;/span&gt;&lt;span class="s"&gt;404'&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;description&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;No order with that id.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full file also has &lt;code&gt;GET /orders&lt;/code&gt; and the schemas. Keep the &lt;code&gt;operationId&lt;/code&gt;s stable: renaming one later looks like a delete plus an add. The backend is an isolated-worker Functions app on .NET 10 whose function names and routes match the spec one to one (&lt;code&gt;create-order&lt;/code&gt; on &lt;code&gt;POST orders&lt;/code&gt;, and so on); the code is in &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;ApimOrdersDemo&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  With Bicep
&lt;/h3&gt;

&lt;p&gt;This is the path the sample deploys, and the one to keep once the API is real:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource apim 'Microsoft.ApiManagement/service@2024-05-01' = {
  name: 'apim-orders-${resourceToken}'
  location: location
  tags: tags
  sku: {
    name: apimSku
    capacity: apimSku == 'Consumption' ? 0 : 1
  }
  properties: {
    publisherEmail: publisherEmail
    publisherName: 'Orders demo'
  }
}

resource ordersApi 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
  parent: apim
  name: 'orders'
  properties: {
    displayName: 'Orders API'
    path: 'sales'
    protocols: ['https']
    format: 'openapi'
    value: loadTextContent('../openapi/orders.yaml')
    serviceUrl: functionBaseUrl
    subscriptionRequired: true
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;format: 'openapi'&lt;/code&gt; means "OpenAPI 3, inline YAML", and &lt;code&gt;loadTextContent&lt;/code&gt; reads the file at compile time, so the spec travels inside the deployment and APIM never has to fetch it. &lt;code&gt;serviceUrl&lt;/code&gt; overrides the spec's &lt;code&gt;servers&lt;/code&gt; entry, which is why the placeholder hostname in the YAML never matters. &lt;code&gt;path: 'sales'&lt;/code&gt; puts the operations at &lt;code&gt;apim-orders-&amp;lt;token&amp;gt;.azure-api.net/sales/orders/{orderId}&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;capacity&lt;/code&gt; must be &lt;code&gt;0&lt;/code&gt; on Consumption and &lt;code&gt;1&lt;/code&gt; or more on every other tier; the conditional keeps the switch to &lt;code&gt;BasicV2&lt;/code&gt; a one-parameter change. On Consumption the service resource took 2 minutes 48 seconds to provision in West Europe, and the whole template, function app included, under five minutes.&lt;/p&gt;

&lt;h3&gt;
  
  
  With the Azure CLI, or the portal
&lt;/h3&gt;

&lt;p&gt;For an instance that already exists, or to try an import before you commit it to a template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az apim api import &lt;span class="nt"&gt;-g&lt;/span&gt; rg-apim-orders &lt;span class="nt"&gt;-n&lt;/span&gt; apim-orders-&amp;lt;token&amp;gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--api-id&lt;/span&gt; orders &lt;span class="nt"&gt;--path&lt;/span&gt; sales &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--specification-format&lt;/span&gt; OpenApi &lt;span class="nt"&gt;--specification-path&lt;/span&gt; openapi/orders.yaml &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--service-url&lt;/span&gt; https://func-orders-&amp;lt;token&amp;gt;.azurewebsites.net/api
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An API imported this way belongs to no product yet, so the partner key from the next section gets a 401 on it ("invalid subscription key") even though the key is valid: a key only opens the APIs in its scope. The &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;sample README&lt;/a&gt; covers the other spec formats and the display-name clash you hit when you import the same file twice.&lt;/p&gt;

&lt;p&gt;The portal does the same import under &lt;strong&gt;APIs&lt;/strong&gt; &amp;gt; &lt;strong&gt;Add API&lt;/strong&gt; &amp;gt; &lt;strong&gt;OpenAPI&lt;/strong&gt;, but nothing records what you clicked; use it to explore and to check the result. Under &lt;strong&gt;APIs&lt;/strong&gt; &amp;gt; &lt;strong&gt;Orders API&lt;/strong&gt; you should see three operations named after the spec's &lt;code&gt;operationId&lt;/code&gt;s (&lt;code&gt;list-orders&lt;/code&gt;, &lt;code&gt;get-order&lt;/code&gt;, &lt;code&gt;create-order&lt;/code&gt;), and the &lt;strong&gt;Settings&lt;/strong&gt; tab should show the &lt;code&gt;serviceUrl&lt;/code&gt; from Bicep with &lt;strong&gt;Subscription required&lt;/strong&gt; checked. The &lt;strong&gt;Test&lt;/strong&gt; tab sends a call with a key from the built-in &lt;code&gt;master&lt;/code&gt; subscription, so a 200 there proves the import and the backend, not your product setup. That gets its own test below.&lt;/p&gt;

&lt;h3&gt;
  
  
  The backend credential
&lt;/h3&gt;

&lt;p&gt;The function keeps &lt;code&gt;AuthorizationLevel.Function&lt;/code&gt;, so a caller who finds the &lt;code&gt;*.azurewebsites.net&lt;/code&gt; hostname still needs a function key. APIM holds that key in a secret named value and sends it on every forwarded call through a &lt;code&gt;backend&lt;/code&gt; entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource functionKeyValue 'Microsoft.ApiManagement/service/namedValues@2024-05-01' = {
  parent: apim
  name: 'orders-function-key'
  properties: {
    displayName: 'orders-function-key'
    secret: true
    value: functionKey
  }
}

resource ordersBackend 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
  parent: apim
  name: 'orders-func'
  properties: {
    url: functionBaseUrl
    protocol: 'http'
    credentials: {
      header: {
        'x-functions-key': ['{{${functionKeyValue.name}}}']
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A backend entity does nothing until a policy routes to it, so the API policy has one line for that, &lt;code&gt;&amp;lt;set-backend-service backend-id="orders-func" /&amp;gt;&lt;/code&gt;. Function keys are still shared secrets; Part 3 replaces them with the gateway's managed identity.&lt;/p&gt;

&lt;p&gt;Before you re-import a changed spec into an existing API, know that the import replaces the operation set. An operation that disappeared from the spec disappears from APIM, policies attached to it included. That's why Parts 5 and 6 put the spec and the policies in Git and deploy them together.&lt;/p&gt;

&lt;h2&gt;
  
  
  Subscription keys: the first thing a caller hits
&lt;/h2&gt;

&lt;p&gt;The sample's access model is three resources: a product that requires a subscription, the order API inside it, and one subscription for one partner.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource partnerProduct 'Microsoft.ApiManagement/service/products@2024-05-01' = {
  parent: apim
  name: 'orders-partners'
  properties: {
    displayName: 'Orders for partners'
    description: 'Order intake for partner shops. One subscription per partner.'
    subscriptionRequired: true
    approvalRequired: false
    state: 'published'
  }
}

resource partnerProductOrders 'Microsoft.ApiManagement/service/products/apis@2024-05-01' = {
  parent: partnerProduct
  name: ordersApi.name
}

resource contosoShop 'Microsoft.ApiManagement/service/subscriptions@2024-05-01' = {
  parent: apim
  name: 'contoso-shop'
  properties: {
    displayName: 'Contoso Shop'
    scope: '/products/${partnerProduct.name}'
    state: 'active'
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;APIM generates the keys and never returns them as deployment outputs. Read them through the management API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az rest &lt;span class="nt"&gt;--method&lt;/span&gt; post &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--url&lt;/span&gt; &lt;span class="s2"&gt;"https://management.azure.com/subscriptions/&amp;lt;azure-subscription-id&amp;gt;/resourceGroups/rg-apim-orders/providers/Microsoft.ApiManagement/service/apim-orders-&amp;lt;token&amp;gt;/subscriptions/contoso-shop/listSecrets?api-version=2024-05-01"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; primaryKey &lt;span class="nt"&gt;-o&lt;/span&gt; tsv
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then call the gateway the way a partner would. These come from the sample's &lt;code&gt;requests.http&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="err"&gt;### No key: 401 from the gateway, the function never sees the call
GET {{gateway}}/orders

### Key in the header: 200
GET {{gateway}}/orders
Ocp-Apim-Subscription-Key: {{key}}

### Key in the query string: also 200, but now the key sits in every access log on the way
GET {{gateway}}/orders?subscription-key={{key}}
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Against the deployed sample, the first call came back as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;HTTP 401
{ "statusCode": 401, "message": "Access denied due to missing subscription key. Make sure to include subscription key when making requests to an API." }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second and third returned 200 with the order list. A made-up key gets a 401 with "Access denied due to invalid subscription key", and the function's own hostname without &lt;code&gt;x-functions-key&lt;/code&gt; gets a 401 from the Functions host, so nobody gets around the gateway without a secret you never gave them.&lt;/p&gt;

&lt;p&gt;APIM reads the &lt;code&gt;Ocp-Apim-Subscription-Key&lt;/code&gt; header and only falls back to the &lt;code&gt;subscription-key&lt;/code&gt; query parameter when the header is missing. Use the header: a key in a URL ends up in proxy logs, browser history and your own request logs. Both names can be changed per API if a partner's client already sends something else; the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/ApimOrdersDemo" rel="noopener noreferrer"&gt;sample README&lt;/a&gt; shows how.&lt;/p&gt;

&lt;p&gt;Give partners product-scoped subscriptions, as the sample does. API-scoped and all-APIs keys skip product-scope policies, where per-partner &lt;code&gt;rate-limit&lt;/code&gt; and &lt;code&gt;quota&lt;/code&gt; usually live, and an all-APIs key also opens every API you add later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rotating and revoking keys
&lt;/h3&gt;

&lt;p&gt;Two keys exist so you can rotate without an outage: partners run on the primary, you regenerate the secondary and hand it over, and once they've switched you regenerate the primary, which becomes the spare. Nothing schedules that for you: APIM &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" rel="noopener noreferrer"&gt;"doesn't provide built-in features to manage the lifecycle of subscription keys, such as setting expiration dates or automatically rotating keys"&lt;/a&gt;, so the schedule lives in your runbook or a pipeline. To cut a partner off, set the subscription's state to &lt;code&gt;cancelled&lt;/code&gt;; in the test their next call got a 401 within five seconds, as long as no open product contained the API.&lt;/p&gt;

&lt;p&gt;One default catches people: APIM forwards the subscription key header to your backend, where it lands in whatever the backend logs. The sample's API policy removes it before the call leaves the gateway:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Almost everything in this article is configuration you'll redeploy many times: the import, the product, the keys, the backend credential, and from Part 5 on all of it lives in a Git repository. The tier is the exception. Consumption can't become Basic v2 or Standard v2 in place, so the one decision to make before the first &lt;code&gt;az deployment&lt;/code&gt; is how the gateway may behave after a quiet night. Part 2 opens the policy file this sample already has and starts putting real rules in it.&lt;/p&gt;

&lt;p&gt;Would you put a Consumption-tier gateway in front of an API a person calls first thing in the morning: yes or no?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>api</category>
      <category>dotnet</category>
      <category>infrastructure</category>
    </item>
    <item>
      <title>The Complete Picture: Azure Container Apps + Dapr Reference Architecture for .NET</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 02 Oct 2026 05:26:19 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/the-complete-picture-azure-container-apps-dapr-reference-architecture-for-net-cik</link>
      <guid>https://dev.to/martin_oehlert/the-complete-picture-azure-container-apps-dapr-reference-architecture-for-net-cik</guid>
      <description>&lt;p&gt;What does the finished stack buy for its floor, and which seam between its layers breaks first? Priced in West Europe, the layers in front of the code cost about $1,730 a month before the first container starts, while the .NET API behind them costs $20 to $140 across 1M to 100M requests. So the compute bill cannot be the argument: on compute alone, Container Apps never beats Functions. The seams are where the series' own parts handed off: Part 4 maps the health endpoints only in Development while Part 7 probes them in production, and the &lt;code&gt;daprAIConnectionString&lt;/code&gt; Part 5 told you to set splits the trace pipeline.&lt;/p&gt;

&lt;p&gt;Seven parts built the stack one layer at a time. Stacked, it is Front Door Premium at the edge, API Management Standard v2 behind a Private Link origin, and an internal Container Apps environment in your own VNet running two ASP.NET Core services on .NET 10, each with a managed Dapr sidecar. Cosmos DB and a Service Bus Premium namespace sit behind private endpoints and take no keys, only managed identities. Aspire runs the two services and their sidecars on your laptop with one F5, and Terraform writes down everything else.&lt;/p&gt;

&lt;p&gt;Every C# and HCL block below is lifted from the &lt;a href="https://github.com/MO2k4/azure-functions-samples" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;, trimmed but not edited. The Bicep fragment for the telemetry settings, the health endpoint fix, the dead-letter fix, the alert command and the KQL are not in the repo, and each one says so where it appears. One naming note: this article calls the services &lt;code&gt;orders-api&lt;/code&gt; and &lt;code&gt;inventory-api&lt;/code&gt;, the state store &lt;code&gt;statestore&lt;/code&gt; and the broker &lt;code&gt;orders-pubsub&lt;/code&gt;. The Aspire sample from &lt;a href="https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3"&gt;Part 4&lt;/a&gt; says &lt;code&gt;order-service&lt;/code&gt; and &lt;code&gt;inventory-service&lt;/code&gt;, and Part 3's sample calls its state store &lt;code&gt;orderstore&lt;/code&gt;. The strings differ; the wiring is the same.&lt;/p&gt;

&lt;h2&gt;
  
  
  One request, seven hops
&lt;/h2&gt;

&lt;p&gt;Follow one &lt;code&gt;POST /orders&lt;/code&gt; from a partner system to Cosmos DB and back. The numbers on the diagram are the order it happens in:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpr4v8jb1rb3193irp4e7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fpr4v8jb1rb3193irp4e7.png" alt="Reference architecture: Front Door Premium, API Management Standard v2 and an internal Container Apps environment with two Dapr-enabled services, Cosmos DB and Service Bus behind private endpoints, and the managed OpenTelemetry agent, with the seven request hops numbered" width="712" height="758"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Front Door ends TLS and runs the WAF.&lt;/strong&gt; Premium, not Standard, for two reasons that each settle it alone: the managed rule sets are Premium only, and so are Private Link origins (&lt;a href="https://learn.microsoft.com/azure/frontdoor/standard-premium/tier-comparison" rel="noopener noreferrer"&gt;tier comparison&lt;/a&gt;). The request leaves Front Door carrying an &lt;code&gt;X-Azure-FDID&lt;/code&gt; header and nothing that proves who sent it. &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Part 6&lt;/a&gt; is the long version of every hop up to the container.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Private Link into API Management.&lt;/strong&gt; Standard v2 is the cheapest tier that takes an inbound private endpoint and also &lt;a href="https://learn.microsoft.com/azure/api-management/virtual-network-concepts" rel="noopener noreferrer"&gt;integrates outbound into a VNet&lt;/a&gt;, and this topology needs both. The gateway trusts the hop because of the network path and a &lt;code&gt;check-header&lt;/code&gt; on &lt;code&gt;X-Azure-FDID&lt;/code&gt;, not because of a credential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. API Management calls the app with its own identity.&lt;/strong&gt; It validates the caller's token and applies per-caller limits, then &lt;code&gt;authentication-managed-identity&lt;/code&gt; fetches a token for &lt;code&gt;orders-api&lt;/code&gt; with the gateway's system-assigned identity. The environment's internal ingress routes on the host header, and Container Apps authentication checks the app role. Set "assignment required" on the service principal so identities without the role are refused a token. Part 6 lists that as something to verify on first deploy: Entra documents it for applications, never for managed identities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;code&gt;orders-api&lt;/code&gt; asks &lt;code&gt;inventory-api&lt;/code&gt; whether it can fill the order&lt;/strong&gt;, through its sidecar. This is the handler from &lt;a href="https://dev.to/martin_oehlert/building-your-first-dapr-web-api-service-3p2g"&gt;Part 3&lt;/a&gt;, trimmed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;IResult&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;CreateOrderAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;CreateOrderRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;InventoryClient&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;DaprClient&lt;/span&gt; &lt;span class="n"&gt;dapr&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;ILogger&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;CancellationToken&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stockRequest&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StockCheckRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;[..&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Select&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StockLine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Sku&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Quantity&lt;/span&gt;&lt;span class="p"&gt;))]);&lt;/span&gt;

    &lt;span class="c1"&gt;// Service invocation. The failure is a value, so both interesting branches (inventory&lt;/span&gt;
    &lt;span class="c1"&gt;// said no; inventory could not be asked) are visible in the same switch.&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stock&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CheckStockAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stockRequest&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stock&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;StockCheckResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;Failure&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;ToProblem&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;error&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="n"&gt;Result&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;StockCheckResponse&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;.&lt;/span&gt;&lt;span class="nf"&gt;Success&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="n"&gt;Available&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Conflict&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;OutOfStockResponse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;answer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Shortfalls&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Sum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;line&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UnitPrice&lt;/span&gt; &lt;span class="p"&gt;*&lt;/span&gt; &lt;span class="n"&gt;line&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Quantity&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;OrderStatus&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Placed&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;DateTimeOffset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;UtcNow&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;ConfirmedAt&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;dapr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;SaveStateAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;StateStore&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;OrderPartition&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;For&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Created&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;$"/orders/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CustomerId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;/&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="s"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;InventoryClient&lt;/code&gt; wraps an &lt;code&gt;HttpClient&lt;/code&gt; whose base address is the Dapr app id, not a host. The two sidecars resolve each other inside the environment and wrap the call in mutual TLS without any configuration from you, and the platform &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-authentication-token" rel="noopener noreferrer"&gt;injects &lt;code&gt;APP_API_TOKEN&lt;/code&gt;&lt;/a&gt; so &lt;code&gt;inventory-api&lt;/code&gt; can check that the call came through its own sidecar. Nothing checks which app sent it: Dapr's access control policies live in the Configuration spec, which Container Apps &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-overview#limitations" rel="noopener noreferrer"&gt;does not support&lt;/a&gt;, so any Dapr-enabled app in the environment can call &lt;code&gt;inventory-api&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. &lt;code&gt;SaveStateAsync&lt;/code&gt; writes to Cosmos DB.&lt;/strong&gt; The code names a component, &lt;code&gt;StateStore.Name&lt;/code&gt;, and never an account. The component carries the account URL plus &lt;code&gt;azureClientId&lt;/code&gt;, the client ID of &lt;code&gt;orders-api&lt;/code&gt;'s user-assigned identity, and the grant behind it is the data-plane role Cosmos DB Built-in Data Contributor. That role does not come from &lt;code&gt;azurerm_role_assignment&lt;/code&gt;; &lt;a href="https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3"&gt;Part 7&lt;/a&gt; covers the resource that actually grants it, and the green apply you get from the one that does not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. The order is announced on a Service Bus topic.&lt;/strong&gt; Part 3's handler stops at the write; the publish is one line in &lt;a href="https://dev.to/martin_oehlert/introduction-to-dapr-for-azure-developers-1l9h"&gt;Part 2&lt;/a&gt;'s sample, after the same save:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;dapr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PublishEventAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PubSubName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;OrderCreatedTopic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;orderCreated&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;orders-pubsub&lt;/code&gt; component is &lt;code&gt;pubsub.azure.servicebus.topics&lt;/code&gt;, authenticated with the same &lt;code&gt;azureClientId&lt;/code&gt; pattern. The publisher's identity holds Azure Service Bus Data Sender, the subscriber's holds Data Receiver, and &lt;code&gt;consumerID&lt;/code&gt; defaults to the app id and becomes the subscription name, which &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;Part 5&lt;/a&gt; showed matters as soon as two runtimes share a topic. On the receiving side, &lt;code&gt;inventory-api&lt;/code&gt;'s sidecar pulls the message and POSTs it to the subscription route, while a KEDA &lt;code&gt;azure-servicebus&lt;/code&gt; rule scales &lt;code&gt;inventory-api&lt;/code&gt; on subscription depth. The scale rule needs an identity reference of its own, even when it names the same identity the sidecar uses, or it cannot read the depth it scales on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;7. Every span goes to the environment's OpenTelemetry agent.&lt;/strong&gt; The app's spans and the &lt;code&gt;daprd&lt;/code&gt; spans leave each replica over OTLP to one managed agent per environment, which forwards them to Application Insights. It is the one hop in the chain that does not run on managed identity: the agent authenticates with a connection string, so the Application Insights resource has to keep local authentication switched on. The operations section below is mostly about this hop.&lt;/p&gt;

&lt;p&gt;Seven hops, and the identity at each one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuq7jnxnocsgbok9s75rq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fuq7jnxnocsgbok9s75rq.png" alt="The seven hops and the identity at each one: what the caller proves itself with and what the receiver checks, from Front Door to Application Insights" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The image pull does not appear on the diagram and uses the same user-assigned identity with &lt;code&gt;AcrPull&lt;/code&gt; on the registry.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who owns what: Aspire, Dapr, Container Apps, Terraform
&lt;/h2&gt;

&lt;p&gt;Four tools touch this stack, and each one owns a different stage of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Aspire owns dev time.&lt;/strong&gt; The AppHost starts both services, both sidecars and a Redis-backed state store with one F5, and hands every process its OTLP endpoint so the dashboard draws one trace across all of them. It stops at the deployment boundary: nothing in Azure runs the AppHost, as &lt;a href="https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3"&gt;Part 4&lt;/a&gt; made clear. What survives into production from Aspire is ServiceDefaults, compiled into every service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Dapr owns the contract between the app and the platform.&lt;/strong&gt; Component names and app ids are the whole API your code sees. &lt;code&gt;statestore&lt;/code&gt; is Redis on your laptop and Cosmos DB in Azure, and the handler in hop 4 does not change, because the swap happens in a YAML file on one side and a Terraform resource on the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Apps owns everything at run time that is not your code&lt;/strong&gt;: ingress, revisions, scaling on HTTP rate or KEDA queue depth, and the sidecar itself. That last one is managed in both directions. You do not install &lt;code&gt;daprd&lt;/code&gt;, and you do not pick its version either; the platform runs 1.16 while &lt;code&gt;dapr init&lt;/code&gt; on your machine gives you 1.18.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Terraform owns what the AppHost saved you from writing down&lt;/strong&gt;: the VNet, the environment, the identities and every grant, the components with their scopes. &lt;a href="https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3"&gt;Part 7&lt;/a&gt; is that tree. It deploys &lt;code&gt;orders-api&lt;/code&gt; and nothing else: there is no &lt;code&gt;inventory-api&lt;/code&gt;, no Front Door and no API Management in it, and this article does not add them.&lt;/p&gt;

&lt;p&gt;Nobody owns the seams between them, and the first one shows up as soon as you put Part 7's container definition next to Part 4's ServiceDefaults. The Terraform side, trimmed to the environment variable and the probes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
  &lt;span class="nx"&gt;image&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;
  &lt;span class="nx"&gt;cpu&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cpu&lt;/span&gt;
  &lt;span class="nx"&gt;memory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;memory&lt;/span&gt;

  &lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ASPNETCORE_ENVIRONMENT"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Production"&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Development"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;liveness_probe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;transport&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HTTP"&lt;/span&gt;
    &lt;span class="nx"&gt;port&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target_port&lt;/span&gt;
    &lt;span class="nx"&gt;path&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/healthz/live"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;readiness_probe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;transport&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HTTP"&lt;/span&gt;
    &lt;span class="nx"&gt;port&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target_port&lt;/span&gt;
    &lt;span class="nx"&gt;path&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/healthz/ready"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the method every service calls on startup:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="nf"&gt;MapDefaultEndpoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Adding health checks endpoints to applications in non-development environments has security implications.&lt;/span&gt;
    &lt;span class="c1"&gt;// See https://aka.ms/aspire/healthchecks for details before enabling these endpoints in non-development environments.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsDevelopment&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// All health checks must pass for app to be considered ready to accept traffic after starting&lt;/span&gt;
        &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HealthEndpointPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Only health checks tagged with the "live" tag must pass for app to be considered alive&lt;/span&gt;
        &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AlivenessEndpointPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;HealthCheckOptions&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Predicate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Tags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"live"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neither file is wrong on its own terms, and together they never pass a probe. In &lt;code&gt;prod&lt;/code&gt; the app runs as Production and maps no health endpoint at all. In every other environment it runs as Development and maps &lt;code&gt;/health&lt;/code&gt; and &lt;code&gt;/alive&lt;/code&gt;, which are not the paths Terraform probes either. Container Apps &lt;a href="https://learn.microsoft.com/azure/container-apps/health-probes" rel="noopener noreferrer"&gt;counts anything from 200 to 399 as healthy&lt;/a&gt;, so a 404 fails both probes in every environment: liveness restarts the container, readiness keeps the revision out of rotation, and the first sign is a revision that never goes healthy while nothing in the app's own logs mentions a health check. Part 4 warned that the endpoints disappear outside Development; Part 7 probed &lt;code&gt;/healthz/*&lt;/code&gt;, the shape Dapr's app health default and most Kubernetes examples use, and no part checked one against the other. The fix is in the operations section, because it is also the health strategy.&lt;/p&gt;

&lt;p&gt;The second seam is telemetry, and it is worse because it fails quietly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Operating it: traces, health checks and alerts
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Traces: one pipeline, and the setting that splits it
&lt;/h3&gt;

&lt;p&gt;The app side needs no change. ServiceDefaults already decides where telemetry goes from one environment variable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="n"&gt;AddOpenTelemetryExporters&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;TBuilder&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IHostApplicationBuilder&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;useOtlpExporter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"OTEL_EXPORTER_OTLP_ENDPOINT"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddOpenTelemetry&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;UseOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// Uncomment the following lines to enable the Azure Monitor exporter (requires the Azure.Monitor.OpenTelemetry.AspNetCore package)&lt;/span&gt;
    &lt;span class="c1"&gt;//if (!string.IsNullOrEmpty(builder.Configuration["APPLICATIONINSIGHTS_CONNECTION_STRING"]))&lt;/span&gt;
    &lt;span class="c1"&gt;//{&lt;/span&gt;
    &lt;span class="c1"&gt;//    builder.Services.AddOpenTelemetry()&lt;/span&gt;
    &lt;span class="c1"&gt;//       .UseAzureMonitor();&lt;/span&gt;
    &lt;span class="c1"&gt;//}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Locally the AppHost sets &lt;code&gt;OTEL_EXPORTER_OTLP_ENDPOINT&lt;/code&gt; to the dashboard. In Azure, when the environment has the &lt;a href="https://learn.microsoft.com/azure/container-apps/opentelemetry-agents" rel="noopener noreferrer"&gt;managed OpenTelemetry agent&lt;/a&gt; switched on, Container Apps injects the same variable pointing at the agent, plus &lt;code&gt;OTEL_EXPORTER_OTLP_PROTOCOL=grpc&lt;/code&gt; and &lt;code&gt;OTEL_RESOURCE_ATTRIBUTES&lt;/code&gt;. Turning on tracing in production is an environment change, not a code change, and the commented-out &lt;code&gt;UseAzureMonitor()&lt;/code&gt; should stay commented out: with both active, every span and log line is exported twice, once directly and once through the agent.&lt;/p&gt;

&lt;p&gt;The environment side is the part no sample carries. Part 7's environment resource sets &lt;code&gt;logs_destination = "log-analytics"&lt;/code&gt; and nothing about traces, so as deployed, the spans never leave the replica. This fragment is not in the companion repo; the property names are checked against the &lt;a href="https://learn.microsoft.com/azure/templates/microsoft.app/managedenvironments?pivots=deployment-language-bicep" rel="noopener noreferrer"&gt;&lt;code&gt;2026-07-01&lt;/code&gt; template reference&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource env 'Microsoft.App/managedEnvironments@2026-07-01' = {
  name: 'cae-orders-prod'
  location: location
  properties: {
    appInsightsConfiguration: {
      connectionString: appi.properties.ConnectionString
    }
    openTelemetryConfiguration: {
      tracesConfiguration: {
        destinations: [ 'appInsights' ]
        includeDapr: true
      }
      logsConfiguration: {
        destinations: [ 'appInsights' ]
      }
    }
    // no daprAIConnectionString, no daprAIInstrumentationKey
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;includeDapr: true&lt;/code&gt; puts the &lt;code&gt;daprd&lt;/code&gt; spans on the same path as the app's spans, so the hop 4 call shows up as one trace with the sidecar in the middle instead of two traces with a gap. The comment at the bottom is the line that matters.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;Part 5&lt;/a&gt; set &lt;code&gt;daprAIConnectionString&lt;/code&gt; next to &lt;code&gt;includeDapr: true&lt;/code&gt;, and that combination splits the pipeline. When either &lt;code&gt;daprAIConnectionString&lt;/code&gt; or &lt;code&gt;daprAIInstrumentationKey&lt;/code&gt; is set, Container Apps sends the Dapr spans straight to Application Insights and skips the agent, whatever &lt;code&gt;includeDapr&lt;/code&gt; says. Your app spans go through the agent to its destinations, the sidecar spans go somewhere else, and if the agent's destination is anything but that same Application Insights resource, the sidecar hop is missing from the trace. This is not in the Learn docs. It is confirmed in a &lt;a href="https://learn.microsoft.com/en-my/answers/questions/5826605/dapr-sidecars-not-sending-trace-telemetry-to-open" rel="noopener noreferrer"&gt;Microsoft Q&amp;amp;A thread&lt;/a&gt; by an Azure Container Apps engineer answering for the product group, who gives the fix as setting both properties to null. The platform also enforces a version of the rule on its own: an environment that already has &lt;code&gt;appInsightsConfiguration&lt;/code&gt; rejects &lt;code&gt;daprAIConnectionString&lt;/code&gt; with "DaprAIConnectionString can not be set when AppInsightsConfiguration has been set" (&lt;a href="https://github.com/microsoft/azure-container-apps/issues/1771" rel="noopener noreferrer"&gt;azure-container-apps#1771&lt;/a&gt;), and in that same issue the product team confirms that the CLI has no supported way to clear the value once it is set.&lt;/p&gt;

&lt;p&gt;That is also where Part 7's Terraform walks into it. &lt;code&gt;azurerm_container_app_environment&lt;/code&gt; in azurerm 5.6.0 has &lt;code&gt;dapr_application_insights_connection_string&lt;/code&gt;, marked &lt;code&gt;ForceNew&lt;/code&gt; in the &lt;a href="https://github.com/hashicorp/terraform-provider-azurerm/blob/v5.6.0/internal/services/containerapps/container_app_environment_resource.go" rel="noopener noreferrer"&gt;provider source&lt;/a&gt;, and nothing at all for &lt;code&gt;appInsightsConfiguration&lt;/code&gt; or &lt;code&gt;openTelemetryConfiguration&lt;/code&gt;; native support is still an open request (&lt;a href="https://github.com/hashicorp/terraform-provider-azurerm/issues/28217" rel="noopener noreferrer"&gt;terraform-provider-azurerm#28217&lt;/a&gt;). So the one telemetry knob the provider offers is the legacy one that bypasses the agent, and taking it back out replaces the environment and every app and component inside it. Leave that variable null, and set the fragment above through &lt;code&gt;azapi_update_resource&lt;/code&gt; against the environment's ID, which is what the Terraform tab on the Learn page does.&lt;/p&gt;

&lt;p&gt;The agent has four limits to know before you rely on it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Application Insights destination takes logs and traces, not metrics.&lt;/strong&gt; The runtime and ASP.NET Core metrics ServiceDefaults records go nowhere unless you add an OTLP metrics destination, or skip the agent and use the Azure Monitor distro in the app instead.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;It is one replica&lt;/strong&gt; (0.5 vCPU, 1.5 GB), not scalable, with no high availability and no health metrics of its own. It buffers for up to five minutes and then drops the oldest batches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Its configuration is per environment.&lt;/strong&gt; Every app in the environment sends to the same destinations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You cannot set the Dapr sampling rate.&lt;/strong&gt; Sampling lives in the Dapr Configuration spec, which Container Apps does not support. Part 5 already said to count the spans that arrive rather than trust a documented default; that advice still holds.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Health checks that exist outside Development
&lt;/h3&gt;

&lt;p&gt;Given the two files above, pick one set of paths and map it everywhere. The probes already name &lt;code&gt;/healthz/live&lt;/code&gt; and &lt;code&gt;/healthz/ready&lt;/code&gt;, so the app moves to them. This is the fix, and it is not in the companion repo, which still has the Development-only version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;HealthEndpointPath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"/healthz"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="nf"&gt;MapDefaultEndpoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Mapped in every environment: the Container Apps probes run in production. The paths are&lt;/span&gt;
    &lt;span class="c1"&gt;// unreachable from outside the VNet unless an API Management operation forwards them.&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;probes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HealthEndpointPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Readiness: every registered check.&lt;/span&gt;
    &lt;span class="n"&gt;probes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/ready"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Liveness: only the "live" self check, so a dependency outage never triggers a restart.&lt;/span&gt;
    &lt;span class="n"&gt;probes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/live"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;HealthCheckOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;Predicate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Tags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"live"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tracing filter in &lt;code&gt;ConfigureOpenTelemetry&lt;/code&gt; already excludes anything under &lt;code&gt;HealthEndpointPath&lt;/code&gt;, so with the constant changed it covers both probes, and the &lt;code&gt;/alive&lt;/code&gt; constant and its clause can go.&lt;/p&gt;

&lt;p&gt;Part 4's objection to mapping these outside Development was an unauthenticated endpoint that fans out to every dependency on each request. On this topology the paths are not reachable from the internet: ingress is internal and API Management forwards only the operations you define. If your API uses a wildcard operation, block &lt;code&gt;/healthz&lt;/code&gt; in the gateway policy or apply Part 4's timeout, output cache and host filter to the group.&lt;/p&gt;

&lt;p&gt;Then decide what goes into each check. Liveness must never touch a dependency, because restarting a container cannot fix Cosmos DB. Readiness is where a dependency check would go, and on a shared dependency I would still leave it out: a Cosmos DB brownout then fails readiness on every replica of &lt;code&gt;orders-api&lt;/code&gt; at the same moment, and the endpoints that never touch Cosmos go down with the ones that do. The template registers only the &lt;code&gt;self&lt;/code&gt; check, and for shared dependencies that is the right default.&lt;/p&gt;

&lt;p&gt;Dapr can also probe your app's health, and that probe has the sharpest edge. Container Apps can have the sidecar probe the app (&lt;a href="https://learn.microsoft.com/azure/container-apps/enable-dapr" rel="noopener noreferrer"&gt;&lt;code&gt;dapr.appHealth&lt;/code&gt;&lt;/a&gt;, off by default, path &lt;code&gt;/healthz&lt;/code&gt;, a 3 second interval, a 500 ms timeout, a threshold of 3). When that check fails, Dapr &lt;a href="https://docs.dapr.io/operations/resiliency/health-checks/app-health/" rel="noopener noreferrer"&gt;unsubscribes from every topic and stops input bindings&lt;/a&gt; until it passes again. A subscriber under a heavy backlog that answers its probe in 600 ms stops consuming at exactly the moment the backlog is biggest. If you turn it on, point it at &lt;code&gt;/healthz/live&lt;/code&gt; (the default &lt;code&gt;/healthz&lt;/code&gt; is not mapped by the group above), keep that check free of dependencies, and raise the timeout.&lt;/p&gt;

&lt;h3&gt;
  
  
  Alerts worth waking up for
&lt;/h3&gt;

&lt;p&gt;Container Apps publishes a short list of &lt;a href="https://learn.microsoft.com/azure/container-apps/metrics" rel="noopener noreferrer"&gt;platform metrics&lt;/a&gt;, and three of them, plus two from Service Bus, cover most of what pages you. The thresholds are opinions; the metric names are not:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk6ieonvdg4xlile70dig.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fk6ieonvdg4xlile70dig.png" alt="Six alert rules worth waking up for: Container Apps Requests, Replicas and RestartCount, and Service Bus ActiveMessages and DeadletteredMessages, with what each catches" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A metric alert from the CLI, for the scale ceiling on &lt;code&gt;orders-api&lt;/code&gt; with the &lt;code&gt;max_replicas = 30&lt;/code&gt; from Part 7's production tfvars:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az monitor metrics alert create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; &lt;span class="s2"&gt;"orders-api-at-max-replicas"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;rg&amp;gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--scopes&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;orders-api resource id&amp;gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--condition&lt;/span&gt; &lt;span class="s2"&gt;"max Replicas &amp;gt;= 30"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--window-size&lt;/span&gt; 15m &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--evaluation-frequency&lt;/span&gt; 5m &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--action&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;action group id&amp;gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The 5xx rule is the same command with &lt;code&gt;--condition "total Requests &amp;gt; 50 where statusCodeCategory includes 5xx"&lt;/code&gt;; check the category values in metrics explorer before you rely on the filter.&lt;/p&gt;

&lt;p&gt;Two of those rows hide caveats. &lt;code&gt;RestartCount&lt;/code&gt; is &lt;a href="https://learn.microsoft.com/azure/azure-monitor/reference/supported-metrics/microsoft-app-containerapps-metrics" rel="noopener noreferrer"&gt;cumulative per replica&lt;/a&gt;, so a threshold of zero keeps firing as long as a replica that restarted once is still alive; treat it as "some replica has restarted" rather than "a replica is restarting now". It also counts &lt;a href="https://learn.microsoft.com/azure/container-apps/metrics" rel="noopener noreferrer"&gt;app containers only&lt;/a&gt;, excluding platform-managed sidecars, so a crash-looping &lt;code&gt;daprd&lt;/code&gt; never moves it. And the Service Bus metrics split by &lt;code&gt;EntityName&lt;/code&gt;, which is the topic, not the subscription: a topic with two subscribers shows one number for both.&lt;/p&gt;

&lt;p&gt;The sidecar and the probes need log search alerts instead. These queries are not in the companion repo. They use the &lt;code&gt;_CL&lt;/code&gt; tables because Part 7 sets &lt;code&gt;logs_destination = "log-analytics"&lt;/code&gt;; with &lt;code&gt;azure-monitor&lt;/code&gt; and diagnostic settings the tables and columns lose their suffixes and neither query runs unchanged. Probe failures and Dapr component errors land in the system logs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ContainerAppSystemLogs_CL
| where TimeGenerated &amp;gt; ago(15m)
| where Reason_s == "Unhealthy" or Log_s has_any ("BackOff", "Error creating dapr component")
| summarize Events = count() by ContainerAppName_s, RevisionName_s, Reason_s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That query would have caught the health path mismatch on the first deploy. For the sidecar itself, filter the console logs on the container name, which is always &lt;code&gt;daprd&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ContainerAppConsoleLogs_CL
| where TimeGenerated &amp;gt; ago(15m)
| where ContainerName_s == "daprd"
| where Log_s has_any ("level=error", "level=fatal", "\"level\":\"error\"", "\"level\":\"fatal\"")
| summarize Errors = count(), Sample = take_any(Log_s) by ContainerAppName_s, bin(TimeGenerated, 5m)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;has_any&lt;/code&gt; list covers both logfmt and JSON, because I have not confirmed which format the managed sidecar writes. Component initialization failures and authorization errors against Cosmos DB or Service Bus, which is what a missing grant looks like from inside the sidecar, are what this query is for.&lt;/p&gt;

&lt;h3&gt;
  
  
  Logs from two containers in one replica
&lt;/h3&gt;

&lt;p&gt;The app and its sidecar write to the same console log table from the same replica, and the replica name is the join key: &lt;code&gt;ContainerGroupName_g&lt;/code&gt; in the &lt;code&gt;_CL&lt;/code&gt; tables. To read both sides of one incident in order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;ContainerAppConsoleLogs_CL
| where TimeGenerated &amp;gt; ago(10m)
| where ContainerAppName_s == "ca-orders-api-prod"
| project TimeGenerated, Replica = ContainerGroupName_g, ContainerName_s, Log_s
| order by Replica asc, TimeGenerated asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Console logs are the fallback. Once the agent delivers traces, one operation is one query across the workspace-based Application Insights tables, where &lt;code&gt;OperationId&lt;/code&gt; is the W3C trace id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let op = "&amp;lt;trace id&amp;gt;";
union AppRequests, AppDependencies, AppTraces, AppExceptions
| where OperationId == op
| project TimeGenerated, Type, AppRoleName, Name, Message, ResultCode, DurationMs
| order by TimeGenerated asc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;AppRoleName&lt;/code&gt; separates &lt;code&gt;orders-api&lt;/code&gt; from &lt;code&gt;inventory-api&lt;/code&gt;, and the dependency rows show where the time went. If the rows between the two services are missing, check the environment for a &lt;code&gt;daprAIConnectionString&lt;/code&gt; before you check anything else.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs: Container Apps vs Functions in West Europe
&lt;/h2&gt;

&lt;p&gt;Every price in this section is West Europe, US dollars, pay-as-you-go list price from the &lt;a href="https://learn.microsoft.com/rest/api/cost-management/retail-prices/azure-retail-prices" rel="noopener noreferrer"&gt;Azure Retail Prices API&lt;/a&gt;, checked on 25 September 2026: no reservations, no savings plans, no enterprise agreement, and a 730-hour month. The region matters more than it looks. Container Apps vCPU is about 40% dearer in West Europe than in East US, while Functions is priced the same in both, so a comparison run on East US defaults flatters Container Apps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Compute: one API, six ways to host it
&lt;/h3&gt;

&lt;p&gt;The workload is one .NET API: 100 ms per request at 512 MB, about 10 ms of it on the CPU and the rest waiting on Cosmos DB and Service Bus. Requests arrive during 12 busy hours a day and not at all during the other 12. Everything scales out at 60% CPU; the Container Apps replicas are 0.5 vCPU and 1 GiB on the default HTTP rule of 10 concurrent requests; each column gets the subscription's whole monthly free grant, which in a real subscription it would share with every other app. The model is my arithmetic, not a Microsoft calculator's:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwya3jbxsxc10skvpd2c6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fwya3jbxsxc10skvpd2c6.png" alt="Monthly compute cost of one .NET API at 1M to 100M requests, West Europe: Functions Consumption, Flex Consumption, Premium EP1, and Container Apps with min 0, min 1 and a dedicated D4 node" width="799" height="241"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Functions Consumption wins every row, and at the bottom it is not close: $3.40 against $24.51 at 10M requests. It bills 0.05 GB-seconds per request and nothing for the gaps between requests, and its $0.20 per million executions undercuts the $0.56 per million that Container Apps charges for requests from outside the environment. The catch is the plan. Learn now titles it "Consumption plan hosting (legacy)", Linux hosting on it &lt;a href="https://learn.microsoft.com/azure/azure-functions/consumption-plan" rel="noopener noreferrer"&gt;retires on 30 September 2028&lt;/a&gt; (Linux apps still on runtime v3 stopped running on 30 September 2026), and it has no VNet integration, so it cannot sit behind the private topology this series built. The column is priced as Windows Consumption, which the retirement does not touch.&lt;/p&gt;

&lt;p&gt;That leaves Flex as the Functions column that competes in practice, and one rule decides what Flex costs for a 100 ms API: a &lt;a href="https://learn.microsoft.com/azure/azure-functions/flex-consumption-plan#billing" rel="noopener noreferrer"&gt;minimum billable execution period of 1,000 ms&lt;/a&gt;. Learn states the minimum and says nothing about what it applies to. The most specific statement I found is an &lt;a href="https://learn.microsoft.com/answers/a/12389275" rel="noopener noreferrer"&gt;accepted answer on Microsoft Q&amp;amp;A&lt;/a&gt;, from a community moderator rather than the product group: requests that overlap on one instance share a 1,000 ms block, and requests that do not overlap are each rounded up to 1,000 ms on their own. The table uses that reading, which makes steady but sparse traffic the worst case.&lt;/p&gt;

&lt;p&gt;At 10M requests one instance sees a request about every 130 ms, only about half of them overlap another, and every one that starts a new block bills a full second for 100 ms of work. If Flex turns out to bill an instance's wall-clock busy time instead, the 10M cell drops from $62.03 to $18.38. The Flex column is the cheaper of the two instance sizes that fit: 512 MB up to 10M, 2,048 MB above that, where a per-instance concurrency of 16 packs more requests into each shared block.&lt;/p&gt;

&lt;p&gt;The Container Apps columns have their own surprise: scale to zero saves almost nothing on a daytime API. The last replica waits out a &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app" rel="noopener noreferrer"&gt;300-second cooldown&lt;/a&gt; before it goes, and even at 1M requests a month a request arrives every 1.3 seconds during the busy hours, so a &lt;code&gt;minReplicas = 0&lt;/code&gt; app runs all day and scales down only at night. Keeping one replica overnight at the idle rate costs about $8 a month, which is cheap insurance against the cold starts in the next section. Service invocation from &lt;code&gt;orders-api&lt;/code&gt; to &lt;code&gt;inventory-api&lt;/code&gt; adds nothing to the request line, because only requests from outside the environment are &lt;a href="https://learn.microsoft.com/azure/container-apps/billing" rel="noopener noreferrer"&gt;billable&lt;/a&gt;. The sidecar is on no meter either; the only statement about it I found is a Container Apps PM &lt;a href="https://github.com/microsoft/azure-container-apps/issues/693" rel="noopener noreferrer"&gt;writing in 2023&lt;/a&gt; that you are not billed for &lt;code&gt;daprd&lt;/code&gt;, which is old and is not documentation.&lt;/p&gt;

&lt;p&gt;The last column is a warning, not a recommendation, about &lt;a href="https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3"&gt;Part 7&lt;/a&gt;'s production tfvars. They declare a D4 workload profile with &lt;code&gt;minimum_count = 1&lt;/code&gt;, and a dedicated profile brings the $0.10 an hour management fee with it: one D4 node plus that fee is $386.64 a month, whether or not an app is placed on it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flat, daytime or bursty: where the lines cross
&lt;/h3&gt;

&lt;p&gt;The shape of the traffic moves the answer more than the volume does. The same model, with the traffic spread flat over 24 hours and packed into two hours a day:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv74clo2e8jh80828oivz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv74clo2e8jh80828oivz.png" alt="The same API under flat 24-hour, daytime 12-hour and bursty 2-hour traffic at 10M and 100M requests a month, across Functions Consumption, Flex, EP1, Container Apps min 0 and D4. Break-even points in the model: a D4 node beats Container Apps Consumption from about 312M requests a month on flat traffic and 790M on the daytime shape, EP1 beats Functions Consumption from about 470M flat and 3.9 billion daytime, neither crosses below 5 billion on the bursty shape, where the D4 column is already three nodes at 100M, and Container Apps with scale to zero undercuts Flex from about 2M daytime and 4.6M flat" width="800" height="349"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Flat traffic is where fixed capacity pays off, and even there it takes a lot of traffic: a dedicated D4 node gets cheaper than Container Apps Consumption only at about &lt;strong&gt;312M requests a month&lt;/strong&gt;. Squeeze the same volume into fewer hours and the crossover moves further out, until on the bursty shape the model never reaches it, because two busy hours need so many instances at once that the fixed-capacity options scale out as well.&lt;/p&gt;

&lt;p&gt;Functions Consumption stays cheaper than Container Apps Consumption at every volume in the flat and daytime shapes. Flex does not: under the per-request reading of the 1,000 ms rule, Container Apps with scale to zero costs less than Flex from about &lt;strong&gt;2M requests a month&lt;/strong&gt; on the daytime shape. Bursty traffic is the one shape where scale to zero earns its name, since the replica is gone 22 hours a day, and at 2M requests the whole month fits inside the Container Apps free grant. The bursty rows leave one thing out: every burst starts cold, and you pay for that in latency rather than dollars.&lt;/p&gt;

&lt;h3&gt;
  
  
  The floor, and the lines that grow under it
&lt;/h3&gt;

&lt;p&gt;The compute column is the small number. This is what sits in front of it at 1M requests a month:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm165b67d5gnx77i4z6iv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fm165b67d5gnx77i4z6iv.png" alt="The platform floor at 1M requests a month: Front Door Premium, API Management Standard v2, Service Bus Premium, Cosmos DB serverless and Log Analytics, about $1,727" width="799" height="331"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Three of those lines are there because the stack is private. Front Door Standard is $35, but it cannot use a Private Link origin. API Management Basic v2 is $150, but it has no outbound VNet integration, so it cannot reach an internal environment. Service Bus Standard is $9.81 with 13M operations included, but &lt;a href="https://learn.microsoft.com/azure/service-bus-messaging/private-link-service" rel="noopener noreferrer"&gt;private endpoints need Premium&lt;/a&gt;. Each "keep it off the internet" decision costs roughly $300 to $670 a month, and together they are 99% of the floor. The public variant (Standard tiers throughout and a public Container Apps ingress that trusts a header instead of a network path) comes to about $215 a month; &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Part 6&lt;/a&gt; is what that trades away.&lt;/p&gt;

&lt;p&gt;The floor is also not flat. At 100M requests on the daytime shape, four lines grow with traffic:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Front Door&lt;/strong&gt; bills $1.50 per million requests plus egress: $150 for the requests and $41 for 5 KB responses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API Management&lt;/strong&gt; includes 50M calls and charges $2.50 per million after that: $125.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Cosmos DB&lt;/strong&gt; serverless at $0.305 per million RU: a 1 KB point read costs 1 RU and a 1 KB write 5 RU with indexing off (&lt;a href="https://learn.microsoft.com/azure/cosmos-db/key-value-store-cost" rel="noopener noreferrer"&gt;Learn&lt;/a&gt;), so an order that reads once and writes once is 600M RU, or $183. At that volume serverless is the wrong model; 1,000 RU/s provisioned is $58.40.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log Analytics&lt;/strong&gt; at $2.99 per GB: every kilobyte of telemetry per request is $284 a month at 100M requests. A traced order through two services and two sidecars writes several rows, not one, and the Dapr side cannot be sampled down on Container Apps (the operations section explains why).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With one kilobyte of telemetry per request, the stack at 100M requests costs about $2,490 a month plus $138 of compute. Compute is about 5% of the bill. Nothing in this section makes the migration pay for itself; if it pays, it pays where &lt;a href="https://dev.to/martin_oehlert/why-move-beyond-azure-functions-the-enterprise-ceiling-4mpp"&gt;Part 1&lt;/a&gt; said it would, in teams that stop deploying and rolling back together.&lt;/p&gt;

&lt;h2&gt;
  
  
  What did not survive contact with production
&lt;/h2&gt;

&lt;p&gt;The seams earlier in this article came from reading the samples side by side. These come from the Dapr source, the Container Apps issue tracker and the places where the series' own samples would break once they ran for a month, and each one fails differently from its Functions equivalent.&lt;/p&gt;

&lt;h3&gt;
  
  
  The subscriber that never wakes up
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;inventory-api&lt;/code&gt; has no public ingress and nothing calls it over HTTP. Deploy it with the default scale rule, which is HTTP, and &lt;code&gt;minReplicas = 0&lt;/code&gt;, and the first quiet night takes it to zero replicas. The next morning orders pile up in its subscription and nothing happens, because the component that would pull them is the Dapr sidecar, and the sidecar runs inside the replica that no longer exists. Learn says it without hedging: with ingress disabled and no &lt;code&gt;minReplicas&lt;/code&gt; or custom scale rule, the app &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app#default-scale-rule" rel="noopener noreferrer"&gt;"scales to zero and has no way of starting back up"&lt;/a&gt;. A Functions developer has never had to think about this, because the Service Bus trigger is its own scale controller.&lt;/p&gt;

&lt;p&gt;The fix is the KEDA &lt;code&gt;azure-servicebus&lt;/code&gt; rule from &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;Part 5&lt;/a&gt;, with its own identity and a &lt;code&gt;subscriptionName&lt;/code&gt; equal to the component's &lt;code&gt;consumerID&lt;/code&gt;, or &lt;code&gt;minReplicas = 1&lt;/code&gt;, which the cost model prices at about $8 a month. Even with the rule, the cold path is long: KEDA polls every 30 seconds, then the image is pulled, the app starts, the sidecar starts, and Dapr delivers nothing until the app channel is up. &lt;code&gt;minReplicas = 1&lt;/code&gt; does not cure everything either: &lt;a href="https://github.com/microsoft/azure-container-apps/issues/1701" rel="noopener noreferrer"&gt;one report&lt;/a&gt; has the first Event Hubs publish after one to two idle hours taking around 15 seconds on a warm replica, because the broker closes idle AMQP links and the sidecar reconnects with backoff. Measure first-call latency after an idle hour, not only after a deploy.&lt;/p&gt;

&lt;h3&gt;
  
  
  A 404 is not a retry
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://dev.to/martin_oehlert/introduction-to-dapr-for-azure-developers-1l9h"&gt;Part 2&lt;/a&gt;'s subscriber, lifted from the sample:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/events/order-created"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;OnOrderCreatedAsync&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;PubSubName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;OrderCreatedTopic&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;null&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogWarning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"No stored order for {OrderId}; dropping the event."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;orderCreated&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;NotFound&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To an ASP.NET Core developer, &lt;code&gt;NotFound()&lt;/code&gt; is the natural answer for a missing order. To the sidecar, the status code is the delivery verdict, and on the Dapr version Container Apps runs today, a 404 is the one verdict that none of the safety nets see. I read the &lt;a href="https://github.com/dapr/dapr/blob/release-1.16/pkg/runtime/subscription/postman/http/http.go" rel="noopener noreferrer"&gt;runtime&lt;/a&gt; and the &lt;a href="https://github.com/dapr/components-contrib/blob/release-1.16/common/component/azure/servicebus/subscription.go" rel="noopener noreferrer"&gt;Service Bus component&lt;/a&gt; source for the managed 1.16 line and for 1.17, because the &lt;a href="https://docs.dapr.io/reference/api/pubsub_api/" rel="noopener noreferrer"&gt;docs&lt;/a&gt; only say that a 404 is logged and the message dropped:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2zm0tpsrr58nhwtk42i1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2zm0tpsrr58nhwtk42i1.png" alt="How the Dapr sidecar treats each subscriber answer on managed Dapr 1.16 versus Dapr 1.17 and later: a 404 is completed and skips the dead-letter topic on 1.16" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On 1.16 the 404 row is lost data; 1.17 treats a 404 as &lt;code&gt;DROP&lt;/code&gt; (&lt;a href="https://github.com/dapr/dapr/pull/9401" rel="noopener noreferrer"&gt;dapr#9401&lt;/a&gt;), but Container Apps does not run 1.17. The message is completed, so Service Bus's own dead-letter queue never sees it, and the Dapr &lt;code&gt;deadLetterTopic&lt;/code&gt; Part 2 introduced as the safety net is skipped as well. The same bug in a Functions Service Bus trigger throws, exhausts &lt;code&gt;MaxDeliveryCount&lt;/code&gt; and parks the message where you can find it. The fix, which is not in the companion repo, is to say what you mean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapPost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/events/order-created"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;OnOrderCreatedAsync&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithTopic&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;TopicOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;PubsubName&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;PubSubName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;Name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;OrderCreatedTopic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;DeadLetterTopic&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"orders-deadletter"&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="c1"&gt;// in the handler: DROP is copied to the dead-letter topic; a 404 on 1.16 is not&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"DROP"&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the order might not be written yet, return a 500 instead and let redelivery try again. Either way, a missing route produces the same 404 as a missing order, so a contract test that every route in &lt;code&gt;/dapr/subscribe&lt;/code&gt; answers something other than 404 is worth its few lines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cosmos DB is not the Redis you tested against
&lt;/h3&gt;

&lt;p&gt;Aspire runs &lt;code&gt;statestore&lt;/code&gt; on a local Redis, and a local Redis answers before you can measure it. In Azure the same &lt;code&gt;SaveStateAsync&lt;/code&gt; goes from the app to its sidecar, from the sidecar through a private endpoint to Cosmos DB, and back, and the middle leg is the one that surprises people. Dapr's Cosmos DB component is built on the Go SDK, and the Cosmos DB SDKs other than .NET and Java &lt;a href="https://learn.microsoft.com/azure/cosmos-db/conceptual-resilient-sdk-applications" rel="noopener noreferrer"&gt;only connect in Gateway mode&lt;/a&gt;, so every state call takes the extra gateway hop that a .NET &lt;code&gt;CosmosClient&lt;/code&gt; in Direct mode would skip. Cosmos DB's &lt;a href="https://learn.microsoft.com/azure/cosmos-db/monitor-server-side-latency" rel="noopener noreferrer"&gt;under-10 ms guarantee at the 99th percentile&lt;/a&gt; is stated for point operations with direct connectivity. I have no benchmark to give you for the gateway path, and a number measured on someone else's network would not be yours anyway: with &lt;code&gt;includeDapr&lt;/code&gt; on, the sidecar's call to Cosmos DB is its own span, so the trace from the operations section shows you the figure for your stack.&lt;/p&gt;

&lt;p&gt;Latency is half of it; the other half is what the component does with keys. The Dapr Cosmos DB component &lt;a href="https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-azure-cosmosdb/" rel="noopener noreferrer"&gt;uses the state key as the partition key&lt;/a&gt; unless the request says otherwise, so every order is its own logical partition, and a transaction across keys fails unless they share one. That is why the handler in hop 4 passes &lt;code&gt;OrderPartition.For(order.CustomerId)&lt;/code&gt; on every write, and why every read of that order has to pass the same metadata or look in the wrong partition and come back empty. Put that together with the previous section and you get this failure: a subscriber that reads without the partition, gets nothing, returns 404, and on 1.16 completes the message. For write-heavy containers, also exclude every path except &lt;code&gt;id&lt;/code&gt; and &lt;code&gt;partitionKey&lt;/code&gt; from indexing: Dapr's state API reads by key, and the default policy indexes every property of every write.&lt;/p&gt;

&lt;h3&gt;
  
  
  The sidecar version is not yours
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;dapr init&lt;/code&gt; on your laptop installs 1.18. Container Apps runs 1.16.4-msft.N, and on 13 August 2026 a Container Apps engineer &lt;a href="https://github.com/microsoft/azure-container-apps/issues/1808" rel="noopener noreferrer"&gt;answered the question about 1.17&lt;/a&gt; with "No plan for v1.17 for now". You cannot pin the managed version and you cannot hold it back; planned maintenance windows only choose when an upgrade lands. The last forced upgrade, to 1.16, &lt;a href="https://github.com/microsoft/azure-container-apps/issues/1690" rel="noopener noreferrer"&gt;broke Service Bus delivery&lt;/a&gt; for messages carrying URI-like application properties, and the fix for session messages being delivered in parallel shipped in 1.17 and reaches Container Apps only if you ask for a backport through a support ticket.&lt;/p&gt;

&lt;p&gt;The companion repo is on the wrong side of this: it references &lt;code&gt;Dapr.AspNetCore&lt;/code&gt; 1.18.5 against a 1.16 sidecar. Three habits close most of the gap:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Match your local runtime to the cloud with &lt;code&gt;dapr init --runtime-version&lt;/code&gt;, so that 1.17 and 1.18 behaviour (the 404 row above, for one) never reaches your laptop and misleads you.&lt;/li&gt;
&lt;li&gt;Pin the Dapr .NET packages to the platform's minor version, and move them when the platform moves, not when NuGet does.&lt;/li&gt;
&lt;li&gt;Watch the Container Apps issue tracker (&lt;a href="https://aka.ms/dapr-aca-updates" rel="noopener noreferrer"&gt;aka.ms/dapr-aca-updates&lt;/a&gt;) rather than the Dapr release notes, which describe a runtime you do not have.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Timers and workflows have no Dapr home
&lt;/h3&gt;

&lt;p&gt;Two Functions features have no managed Dapr equivalent. The cron input binding runs inside the sidecar, so it &lt;a href="https://github.com/dapr/components-contrib/issues/1249" rel="noopener noreferrer"&gt;fires once per replica&lt;/a&gt; and not at all at zero replicas, where a Functions timer trigger is a singleton. And Dapr Workflow, the orchestration building block that &lt;a href="https://github.com/dapr/dapr/releases/tag/v1.18.0" rel="noopener noreferrer"&gt;1.18 was mostly about&lt;/a&gt;, is &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-overview" rel="noopener noreferrer"&gt;not supported&lt;/a&gt; on Container Apps; the &lt;a href="https://github.com/microsoft/azure-container-apps/issues/762" rel="noopener noreferrer"&gt;request for it&lt;/a&gt; has been open since May 2023. Container Apps Jobs &lt;a href="https://learn.microsoft.com/azure/container-apps/jobs#jobs-restrictions" rel="noopener noreferrer"&gt;cannot use Dapr&lt;/a&gt; at all. That leaves a scheduled Container Apps Job with the plain Azure SDKs, the Durable Task SDKs with Durable Task Scheduler, or keeping the timer and the orchestration exactly where they are.&lt;/p&gt;

&lt;h3&gt;
  
  
  What .NET developers find different
&lt;/h3&gt;

&lt;p&gt;The code changes less than the debugging does. A Service Bus trigger used to be one attribute; now it is an endpoint in C#, a component in Terraform, a scale rule with its own identity, and a &lt;code&gt;consumerID&lt;/code&gt; that has to match a string in two other places. When a message goes missing, the question is no longer "what does the invocation log say" but which of four things dropped it: the app, the sidecar, the component or KEDA. You can step through the app under Aspire, but not through &lt;code&gt;daprd&lt;/code&gt;; its &lt;code&gt;enableApiLogging&lt;/code&gt; setting is the nearest thing to seeing the binding call. Service invocation gets no platform resiliency (Container Apps &lt;a href="https://learn.microsoft.com/azure/container-apps/service-discovery-resiliency" rel="noopener noreferrer"&gt;says so explicitly&lt;/a&gt;, and the Dapr resiliency spec does not deploy there, as Part 5 found), so retries and timeouts go back into the &lt;code&gt;HttpClient&lt;/code&gt; pipeline you thought the sidecar owned. And ASP.NET Core asks questions the Functions host answered for you: Data Protection keys have to be &lt;a href="https://learn.microsoft.com/aspnet/core/security/data-protection/configuration/overview" rel="noopener noreferrer"&gt;shared across replicas&lt;/a&gt;, and health endpoints, as this article showed, have to exist outside Development.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3"&gt;Part 4&lt;/a&gt;'s AppHost is what makes it learnable. With one F5 that starts both services and both sidecars and draws one trace across all of them, a team learns the sidecar model in a week. Without it, &lt;code&gt;daprd&lt;/code&gt; stays someone else's problem until the first incident.&lt;/p&gt;

&lt;h2&gt;
  
  
  What stays on Functions
&lt;/h2&gt;

&lt;p&gt;Not everything should move, and the cost model above is a large part of why. A queue-triggered function that validates a message and writes a row is a dozen lines and, on Consumption, costs nothing at a million executions a month. Its Container Apps equivalent is an endpoint, a component, a scale rule and an identity, a replica that bills while it waits for the scale-in cooldown, and no new capability in return. Event glue with no business logic, webhook receivers, blob triggers (which have no Dapr binding with the same semantics) and low-traffic internal endpoints all land in the same place.&lt;/p&gt;

&lt;p&gt;Timers and orchestrations stay too, for the reasons in the previous section: a timer trigger is a singleton and a cron binding is not, and Durable Functions has a home that Dapr Workflow does not have on Container Apps yet. If what you want is one environment rather than one programming model, &lt;a href="https://learn.microsoft.com/azure/container-apps/functions-overview" rel="noopener noreferrer"&gt;Azure Functions on Container Apps&lt;/a&gt; runs function apps inside the same Container Apps environment, next to &lt;code&gt;orders-api&lt;/code&gt;, on the same VNet and the same logs. This series did not take that path, and it is the one I would look at first for the functions that remain; the one thing to check is that Durable Functions only autoscales there with the MSSQL or Durable Task Scheduler backends.&lt;/p&gt;

&lt;h2&gt;
  
  
  When to start this journey
&lt;/h2&gt;

&lt;p&gt;The stack in this article is the end state, not the starting point, and I would build it again in the order the series did. &lt;a href="https://dev.to/martin_oehlert/why-move-beyond-azure-functions-the-enterprise-ceiling-4mpp"&gt;Part 1&lt;/a&gt; gave the reason to leave, the &lt;a href="https://dev.to/martin_oehlert/preparing-for-migration-decoupling-your-function-logic-2clh"&gt;prerequisite&lt;/a&gt; pulled the business logic out of the function bodies, &lt;a href="https://dev.to/martin_oehlert/introduction-to-dapr-for-azure-developers-1l9h"&gt;Part 2&lt;/a&gt; and &lt;a href="https://dev.to/martin_oehlert/building-your-first-dapr-web-api-service-3p2g"&gt;Part 3&lt;/a&gt; swapped bindings for Dapr building blocks inside two ASP.NET Core services, and &lt;a href="https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3"&gt;Part 4&lt;/a&gt; kept the inner loop to one F5. &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;Part 5&lt;/a&gt; moved production traffic one endpoint at a time, &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Part 6&lt;/a&gt; put a private edge in front, and &lt;a href="https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3"&gt;Part 7&lt;/a&gt; wrote it all down in Terraform. Each step works on its own: you can stop after Part 5 with services on Container Apps and no private edge, and pay a fraction of the floor.&lt;/p&gt;

&lt;p&gt;Whether to start is a narrower question than any of those steps, and the answer comes from outside the compute bill:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Start&lt;/strong&gt; when the ceiling is organizational: two or more teams release through one function app, or through one Premium plan whose always-ready floor they share. Or when it is structural: a working set above the &lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-scale#service-limits" rel="noopener noreferrer"&gt;4 GB a Flex instance allows&lt;/a&gt; (only Premium, up to 14 GB on EP3, and Dedicated clear it), dependencies that need a container, or a scale-out curve that cannot keep up with your spikes. Start sooner if a private edge is already a requirement, because then the floor above is not the migration's cost; you would pay most of it on Functions too.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stay&lt;/strong&gt; when the workload is event-driven and bursty and one team owns it. Functions Consumption is the cheaper host for that shape at every volume in the tables above, and the migration costs a team two quarters it could spend on the product.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stay&lt;/strong&gt; when the reason is price. The model never finds a volume where moving saves more than cents of compute against Functions Consumption, and the platform in front of it dwarfs the difference either way.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a second opinion from the other direction, the Azure Architecture Center's &lt;a href="https://learn.microsoft.com/azure/architecture/example-scenario/serverless/microservices-with-container-apps-dapr" rel="noopener noreferrer"&gt;Deploy microservices with Azure Container Apps and Dapr&lt;/a&gt; is Microsoft's own version of this stack, without the private edge.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In Part 1 the argument for leaving Functions was a set of limits, and the finished stack shows the limits were the easy part. The expensive decisions came where two correct pieces met, and none of them showed up in a single sample run on its own. So put each layer into production before the next one goes on.&lt;/p&gt;

&lt;p&gt;Functions did not lose this comparison. It is cheaper on compute at every volume in the tables above, and for event glue it is still the better programming model. Container Apps wins where the questions are about who deploys what and what runs next to it, and it asks for about $1,730 a month of platform before it answers.&lt;/p&gt;

&lt;p&gt;If you started a new Azure API tomorrow, would it go on Functions or on Container Apps?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>cloudnative</category>
      <category>architecture</category>
      <category>dotnet</category>
    </item>
    <item>
      <title>Infrastructure as Code: Terraform for Your New Stack</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 25 Sep 2026 06:46:19 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3</link>
      <guid>https://dev.to/martin_oehlert/infrastructure-as-code-terraform-for-your-new-stack-49m3</guid>
      <description>&lt;p&gt;The first &lt;code&gt;terraform apply&lt;/code&gt; against a fresh subscription created the Container Apps environment, created the app, and then the revision failed to pull its image. The second apply, with nothing changed, succeeded. The &lt;code&gt;AcrPull&lt;/code&gt; role assignment existed both times; what was missing on the first run was an edge in Terraform's dependency graph, because the container app references the identity and the registry login server and has no reason to reference the grant. Terraform orders what you reference, Azure requires things you would never reference, and that gap is where most of the production failures in a Container Apps stack live.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Part 6&lt;/a&gt; described that architecture as a chain of hops and asked what each one trusts. Written down as Terraform it is fifteen resources in the root module before a single &lt;code&gt;module&lt;/code&gt; block runs, and four modules under it holding the VNet, the private endpoints, the environment, the apps, the Dapr components, the identities and their grants.&lt;/p&gt;

&lt;p&gt;Every HCL block below is lifted out of a tree that &lt;code&gt;terraform validate&lt;/code&gt;s on &lt;strong&gt;Terraform 1.16.3&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;hashicorp/azurerm&lt;/code&gt; 5.6.0&lt;/strong&gt;, published 2026-09-17, and the whole tree is in the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/TerraformContainerAppsDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;. The pair is pinned in one place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;terraform&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;required_version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;gt;= 1.16.0"&lt;/span&gt;

  &lt;span class="nx"&gt;required_providers&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;azurerm&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;source&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"hashicorp/azurerm"&lt;/span&gt;
      &lt;span class="nx"&gt;version&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"5.6.0"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# Partial configuration. The rest comes from envs/&amp;lt;env&amp;gt;.backend.hcl at init time:&lt;/span&gt;
  &lt;span class="c1"&gt;#   terraform init -reconfigure -backend-config=envs/prod.backend.hcl&lt;/span&gt;
  &lt;span class="nx"&gt;backend&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;provider&lt;/span&gt; &lt;span class="s2"&gt;"azurerm"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;features&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;

  &lt;span class="nx"&gt;subscription_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;subscription_id&lt;/span&gt;

  &lt;span class="c1"&gt;# v5 defaults this to "none". On a fresh subscription the first apply then fails on an&lt;/span&gt;
  &lt;span class="c1"&gt;# unregistered Microsoft.App, and the error reads like a permissions problem.&lt;/span&gt;
  &lt;span class="nx"&gt;resource_provider_registrations&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"legacy"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One thing about that validation matters before you trust your own: &lt;code&gt;terraform init&lt;/code&gt; without &lt;code&gt;-upgrade&lt;/code&gt; happily resolved an azurerm 4.x build out of the local plugin cache with a 5.x constraint sitting in &lt;code&gt;required_providers&lt;/code&gt;, and the three v4-shaped errors that followed read as though the configuration was wrong. &lt;code&gt;terraform version -json&lt;/code&gt; prints &lt;code&gt;provider_selections&lt;/code&gt;; check it before you start editing code that was fine.&lt;/p&gt;

&lt;h2&gt;
  
  
  Four modules, drawn where the lifetime changes
&lt;/h2&gt;

&lt;p&gt;A module boundary is a &lt;strong&gt;lifetime&lt;/strong&gt; boundary, not a service boundary. Here is the root module wiring the four of them together, with the arguments that only carry data trimmed out:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"networking"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"./modules/networking"&lt;/span&gt;

  &lt;span class="nx"&gt;address_space&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address_space&lt;/span&gt;

  &lt;span class="c1"&gt;# 7 newbits on a /16 gives a /23. /27 is the legal minimum for workload profiles, but the&lt;/span&gt;
  &lt;span class="c1"&gt;# subnet cannot be resized afterwards and a /27 caps at 9 Dedicated nodes.&lt;/span&gt;
  &lt;span class="nx"&gt;aca_subnet_newbits&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"container_apps"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"./modules/container-apps"&lt;/span&gt;

  &lt;span class="nx"&gt;log_analytics_workspace_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_log_analytics_workspace&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;infrastructure_subnet_id&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;networking&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps_subnet_id&lt;/span&gt;
  &lt;span class="nx"&gt;internal_only&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

  &lt;span class="nx"&gt;container_registry_login_server&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_container_registry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;login_server&lt;/span&gt;

  &lt;span class="nx"&gt;app_identities&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;id&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identity_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nx"&gt;client_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;

  &lt;span class="nx"&gt;depends_on&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;networking&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;module&lt;/span&gt; &lt;span class="s2"&gt;"dapr_components"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;source&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"./modules/dapr-components"&lt;/span&gt;

  &lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment_id&lt;/span&gt;
  &lt;span class="nx"&gt;dapr_identity_client_id&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;client_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;state_store_scopes&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_app_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
  &lt;span class="nx"&gt;pubsub_scopes&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_app_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;orders_app_id&lt;/span&gt;&lt;span class="p"&gt;]]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The VNet outlives the architecture: you will still be running that address space after the apps inside it have been rewritten twice. The environment is near-permanent for reasons the next section is entirely about. The apps change every time somebody merges. Cut along those rates and each module has one reason to be applied. Cut by Azure service instead and you get a &lt;code&gt;cosmos&lt;/code&gt; module that has to be planned every time an image tag moves.&lt;/p&gt;

&lt;p&gt;What crosses each boundary is an &lt;code&gt;output&lt;/code&gt; feeding a &lt;code&gt;var&lt;/code&gt;, and that reference is the only thing Terraform needs to order the two. &lt;code&gt;module.networking&lt;/code&gt; exports the delegated subnet ID; &lt;code&gt;module.container_apps&lt;/code&gt; exports the environment ID, its default domain, its static IP, the app FQDNs and the Dapr app ids; &lt;code&gt;module.identity&lt;/code&gt; exports identity IDs, client IDs and principal IDs as three separate maps, because they are not interchangeable and a swap fails at runtime with nothing visible at plan time. &lt;code&gt;module.dapr_components&lt;/code&gt; exports nothing anyone consumes, which is a fine thing for a leaf module to do.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqo519ls040dq43ex9jqm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fqo519ls040dq43ex9jqm.png" alt="Module dependency graph: solid edges are outputs wired into the next module's variables, dashed edges are explicit depends_on for the AcrPull grant and the NSG association" width="712" height="818"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The two dashed edges are the ones Terraform cannot draw, and the &lt;code&gt;depends_on&lt;/code&gt; on &lt;code&gt;module.container_apps&lt;/code&gt; is where you write them down by hand. &lt;code&gt;module.identity&lt;/code&gt; is there for the failed image pull in the first paragraph of this article. &lt;code&gt;module.networking&lt;/code&gt; is there because the environment references the subnet and never the NSG association, so without the edge the environment can come up against an unprotected subnet. The sample puts both on the module call rather than on the resource, since the identities and the apps live in different modules; inside a single module the same fix is &lt;code&gt;depends_on = [azurerm_role_assignment.acr_pull]&lt;/code&gt; on the &lt;code&gt;azurerm_container_app&lt;/code&gt; resource itself. The identity chain gets taken apart properly further down.&lt;/p&gt;

&lt;p&gt;Three patterns would fail a module review at a stricter shop, and they are worth naming because most Terraform repos contain all three. A module wrapping a single resource with a rename is a rename. A resource you configure once and never vary does not need a variable, let alone a module. And a passthrough module, where every variable maps one-to-one onto a provider argument, has added a file and taken away the provider documentation. &lt;code&gt;dapr-components&lt;/code&gt; survives that test by a narrow margin: it hard-codes the component types and versions, it refuses an empty &lt;code&gt;scopes&lt;/code&gt; list, and it hides the &lt;code&gt;azureClientId&lt;/code&gt; plumbing. A generic "any Dapr component" module would do none of those things and would be worse than writing the resource directly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The environment: every interesting argument is a one-way door
&lt;/h2&gt;

&lt;p&gt;The resource that decides the entire network posture of this stack has no required network argument at all. Omit &lt;code&gt;infrastructure_subnet_id&lt;/code&gt; and you get a public environment outside your VNet, and it plans clean:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;missing_identities&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;setsubtract&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_container_app_environment"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cae-${var.workload}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;

  &lt;span class="nx"&gt;logs_destination&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"log-analytics"&lt;/span&gt;
  &lt;span class="nx"&gt;log_analytics_workspace_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log_analytics_workspace_id&lt;/span&gt;

  &lt;span class="nx"&gt;infrastructure_subnet_id&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;infrastructure_subnet_id&lt;/span&gt;
  &lt;span class="nx"&gt;infrastructure_resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"rg-${var.workload}-${var.environment}-aca-infra"&lt;/span&gt;
  &lt;span class="nx"&gt;internal_load_balancer_enabled&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;internal_only&lt;/span&gt;
  &lt;span class="nx"&gt;zone_redundancy_enabled&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt;

  &lt;span class="nx"&gt;dapr_application_insights_connection_string&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_application_insights_connection_string&lt;/span&gt;

  &lt;span class="nx"&gt;workload_profile&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Consumption"&lt;/span&gt;
    &lt;span class="nx"&gt;workload_profile_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Consumption"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="s2"&gt;"workload_profile"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dedicated_workload_profiles&lt;/span&gt;

    &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workload_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
      &lt;span class="nx"&gt;workload_profile_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workload_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profile_type&lt;/span&gt;
      &lt;span class="nx"&gt;minimum_count&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workload_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minimum_count&lt;/span&gt;
      &lt;span class="nx"&gt;maximum_count&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;workload_profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maximum_count&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;

  &lt;span class="nx"&gt;lifecycle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;precondition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;missing_identities&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
      &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Every app needs an identity: ${join("&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;", local.missing_identities)} are in apps but not in app_identities."&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nearly every argument above forces replacement when it changes: &lt;code&gt;infrastructure_subnet_id&lt;/code&gt;, &lt;code&gt;infrastructure_resource_group_name&lt;/code&gt;, &lt;code&gt;internal_load_balancer_enabled&lt;/code&gt;, &lt;code&gt;zone_redundancy_enabled&lt;/code&gt;, &lt;code&gt;dapr_application_insights_connection_string&lt;/code&gt;, the &lt;code&gt;workload_profile&lt;/code&gt; blocks, and the size of the subnet the first one points at. Replacing a Container Apps environment takes every container app and every Dapr component inside it along, so those are decisions you make once, on day one, with the same weight you would give a database engine choice.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;workload_profile&lt;/code&gt; is the trap, because nothing about it looks final. It is an optional repeatable block with optional arguments, the shape Terraform uses everywhere for things you tune later. The &lt;a href="https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app_environment" rel="noopener noreferrer"&gt;provider note&lt;/a&gt; is explicit: "Environments created without an initial Workload Profile cannot have them added at a later time and must be recreated. Similarly, an environment created with Profiles must always have at least one defined Profile, removing all profiles will force a recreation of the resource." That is why the static &lt;code&gt;Consumption&lt;/code&gt; block sits above the &lt;code&gt;dynamic&lt;/code&gt; one rather than inside it. A &lt;code&gt;Consumption&lt;/code&gt; profile must be named &lt;code&gt;Consumption&lt;/code&gt;, there can only be one, and keeping it out of the map means an operator who empties &lt;code&gt;dedicated_workload_profiles&lt;/code&gt; removes a dedicated profile instead of destroying the environment.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;logs_destination = "log-analytics"&lt;/code&gt; is there because v5 stopped computing it. A v4 configuration that set only &lt;code&gt;log_analytics_workspace_id&lt;/code&gt; and got log analytics by default now drops to Streaming Only on upgrade, with no error, and you find out when you go looking for a query result that is not there.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;dedicated_workload_profiles&lt;/code&gt; variable is where the environment's rules get written down, and the third validation on it is a different kind of rule from the first two:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"dedicated_workload_profiles"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;profile_type&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;minimum_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;maximum_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}))&lt;/span&gt;
  &lt;span class="nx"&gt;default&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
  &lt;span class="nx"&gt;nullable&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Dedicated profiles keyed by profile name. A Consumption profile is always added, because removing the last profile recreates the environment."&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dedicated_workload_profiles&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"^(D4|D8|D16|D32|E4|E8|E16|E32)$"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;profile_type&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"profile_type must be one of D4, D8, D16, D32, E4, E8, E16, E32."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dedicated_workload_profiles&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;maximum_count&lt;/span&gt; &lt;span class="err"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;profile&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;minimum_count&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"maximum_count must be greater than or equal to minimum_count."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dedicated_workload_profiles&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s2"&gt;"Consumption"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"The Consumption profile is added by the module; do not declare it here."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first two encode Azure rules, and Azure would have rejected the apply anyway; all the validation buys you is a readable error twenty minutes earlier. The third encodes a rule Azure has never heard of. It exists because this module chose to add the &lt;code&gt;Consumption&lt;/code&gt; profile itself, and a caller who declares one would get a duplicate name from a design decision they had no way to see. Validation blocks are most useful for exactly that: the constraints your module invented, which no provider schema and no API will ever check for you.&lt;/p&gt;

&lt;h2&gt;
  
  
  The app: one variable is the whole interface
&lt;/h2&gt;

&lt;p&gt;Callers of the container-apps module never touch a resource. They fill in one map, and the key of that map is the &lt;strong&gt;Dapr app id&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"apps"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="nx"&gt;image&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
    &lt;span class="nx"&gt;target_port&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;
    &lt;span class="nx"&gt;cpu&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;memory&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"1Gi"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;min_replicas&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;max_replicas&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;workload_profile_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Consumption"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;key_vault_secrets&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;

    &lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="nx"&gt;external_enabled&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nx"&gt;allowed_ip_ranges&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt;

    &lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;object&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="nx"&gt;queue_name&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;namespace&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;
      &lt;span class="nx"&gt;message_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;optional&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}))&lt;/span&gt;
  &lt;span class="p"&gt;}))&lt;/span&gt;
  &lt;span class="nx"&gt;nullable&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Apps keyed by Dapr app id. The map key becomes the dapr app_id and the container app name suffix, so a Dapr component can never be scoped to a string that does not exist."&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;can&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;regex&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"^[a-z][a-z0-9-]{1,30}[a-z0-9]$"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;))])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"App keys become Dapr app ids and container app names; use lower-case alphanumeric and hyphens, 3-32 chars."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min_replicas&lt;/span&gt; &lt;span class="err"&gt;&amp;lt;=&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max_replicas&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"min_replicas must be less than or equal to max_replicas."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="mf"&gt;0.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;1.75&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;2.0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cpu&lt;/span&gt;&lt;span class="p"&gt;)])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"cpu must be one of the allocations the Consumption profile accepts: 0.25 through 2.0 in 0.25 steps."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# KEDA's namespace metadata is the bare name. Dapr's namespaceName, two modules over, is the&lt;/span&gt;
  &lt;span class="c1"&gt;# FQDN. Same concept, two formats, and neither one fails at plan time.&lt;/span&gt;
  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;alltrue&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
      &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;
      &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt; &lt;span class="err"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;||&lt;/span&gt; &lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;strcontains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;try&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="s2"&gt;"."&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;])&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"The Service Bus scale rule namespace is the bare namespace name, not the FQDN. Drop the .servicebus.windows.net suffix."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keying on the Dapr app id rather than on the container app name is the one design decision in this module that changes what can go wrong later. A Dapr component's &lt;code&gt;scopes&lt;/code&gt; list matches on app ids, the app id is otherwise just a string somebody typed twice, and the next section is about what happens when the two copies drift. Making it the map key means it is typed once, in tfvars, and everything else is derived.&lt;/p&gt;

&lt;p&gt;Of the four validations, the character-set rule is the one that pays for itself. Azure enforces a name format on the container app and Dapr enforces its own on the app id, and the map key has to satisfy both, so checking it at the interface beats reading two different rejections from two different services. The CPU one covers an allocation set the provider does not check at all. The last one is the &lt;code&gt;namespaceName&lt;/code&gt; versus &lt;code&gt;namespace&lt;/code&gt; split: Dapr's Service Bus component wants the fully qualified namespace and KEDA's scaler wants the bare name, the two live two modules apart in the same stack, and neither one fails at plan time if you supply the other format.&lt;/p&gt;

&lt;p&gt;Cross-variable validation is why the module needs Terraform 1.9 as a floor. The networking module's subnet check reads &lt;code&gt;tonumber(split("/", var.address_space)[1]) + var.aca_subnet_newbits &amp;lt;= 27&lt;/code&gt;, and a &lt;code&gt;validation&lt;/code&gt; block that references a second variable was an error before 1.9.&lt;/p&gt;

&lt;p&gt;Then the resource, which is mostly &lt;code&gt;each.value&lt;/code&gt; plumbing plus four things worth stopping on:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_container_app"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apps&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ca-${each.key}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_container_app_environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;revision_mode&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Single"&lt;/span&gt;
  &lt;span class="nx"&gt;workload_profile_name&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;workload_profile_name&lt;/span&gt;
  &lt;span class="nx"&gt;max_inactive_revisions&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;

  &lt;span class="nx"&gt;identity&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;type&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"UserAssigned"&lt;/span&gt;
    &lt;span class="nx"&gt;identity_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;registry&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;server&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_registry_login_server&lt;/span&gt;
    &lt;span class="nx"&gt;identity&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# A Key Vault reference, not a copy of the value into state. The identity here has to be the&lt;/span&gt;
  &lt;span class="c1"&gt;# same one the AcrPull grant went to, or the revision fails to start on secret resolution.&lt;/span&gt;
  &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="s2"&gt;"secret"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key_vault_secrets&lt;/span&gt;

    &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
      &lt;span class="nx"&gt;identity&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
      &lt;span class="nx"&gt;key_vault_secret_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;secret&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# app_id is the string Dapr component scopes match on. It is deliberately the map key, so the&lt;/span&gt;
  &lt;span class="c1"&gt;# dapr-components module can read it back off this resource instead of guessing a convention.&lt;/span&gt;
  &lt;span class="nx"&gt;dapr&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;app_id&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
    &lt;span class="nx"&gt;app_port&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target_port&lt;/span&gt;
    &lt;span class="nx"&gt;app_protocol&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="s2"&gt;"ingress"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ingress&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

    &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;external_enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ingress&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;external_enabled&lt;/span&gt;
      &lt;span class="nx"&gt;target_port&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target_port&lt;/span&gt;
      &lt;span class="nx"&gt;transport&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"auto"&lt;/span&gt;

      &lt;span class="nx"&gt;traffic_weight&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;latest_revision&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
        &lt;span class="nx"&gt;percentage&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;template&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;min_replicas&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;min_replicas&lt;/span&gt;
    &lt;span class="nx"&gt;max_replicas&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;max_replicas&lt;/span&gt;
    &lt;span class="nx"&gt;polling_interval_in_seconds&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;
    &lt;span class="nx"&gt;cooldown_period_in_seconds&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
    &lt;span class="nx"&gt;termination_grace_period_seconds&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;

    &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;
      &lt;span class="nx"&gt;image&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;image&lt;/span&gt;
      &lt;span class="nx"&gt;cpu&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cpu&lt;/span&gt;
      &lt;span class="nx"&gt;memory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;memory&lt;/span&gt;

      &lt;span class="c1"&gt;# The client ID, not the principal ID. Both are GUIDs on the same identity and swapping&lt;/span&gt;
      &lt;span class="c1"&gt;# them fails at runtime with nothing to see at plan time.&lt;/span&gt;
      &lt;span class="nx"&gt;env&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"AZURE_CLIENT_ID"&lt;/span&gt;
        &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;client_id&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;

      &lt;span class="nx"&gt;readiness_probe&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;transport&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"HTTP"&lt;/span&gt;
        &lt;span class="nx"&gt;port&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target_port&lt;/span&gt;
        &lt;span class="nx"&gt;path&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/healthz/ready"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="s2"&gt;"http_scale_rule"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

      &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"http-rps"&lt;/span&gt;
        &lt;span class="nx"&gt;concurrent_requests&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"50"&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;# identity_id on custom_scale_rule landed in azurerm 4.69.0. Below that floor a Service Bus&lt;/span&gt;
    &lt;span class="c1"&gt;# scale rule needs a connection string secret instead of the workload identity.&lt;/span&gt;
    &lt;span class="nx"&gt;dynamic&lt;/span&gt; &lt;span class="s2"&gt;"custom_scale_rule"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

      &lt;span class="nx"&gt;content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;name&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"sb-queue-depth"&lt;/span&gt;
        &lt;span class="nx"&gt;custom_rule_type&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azure-servicebus"&lt;/span&gt;
        &lt;span class="nx"&gt;identity_id&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_identities&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;key&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;

        &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="nx"&gt;queueName&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;custom_scale_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue_name&lt;/span&gt;
          &lt;span class="nx"&gt;namespace&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;custom_scale_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;namespace&lt;/span&gt;
          &lt;span class="nx"&gt;messageCount&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;tostring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;custom_scale_rule&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;message_count&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
      &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;lifecycle&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;precondition&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ingress&lt;/span&gt; &lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_scale_rule&lt;/span&gt; &lt;span class="err"&gt;!&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;
      &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"App ${each.key} has neither ingress nor a queue scale rule, so nothing can ever wake it."&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;precondition&lt;/code&gt; catches what no &lt;code&gt;validation&lt;/code&gt; block can reach, because it depends on two optional attributes of the same object rather than on one variable. An app with no &lt;code&gt;ingress&lt;/code&gt; and no scale rule is legal HCL, legal Azure, and applies green. It then sits at zero replicas forever, because nothing can wake it: no ingress means no HTTP traffic, and no queue rule means no backlog signal. The failure is silence, which is the worst shape a failure can take in infrastructure code.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AZURE_CLIENT_ID&lt;/code&gt; carries the &lt;strong&gt;client ID&lt;/strong&gt;. The role assignments that give this identity its Cosmos, Service Bus and Key Vault access take the &lt;strong&gt;principal ID&lt;/strong&gt;. Both are GUIDs hanging off the same &lt;code&gt;azurerm_user_assigned_identity&lt;/code&gt;, they look identical in a plan diff, and swapping them produces a clean apply and a 401 at runtime. That is the reason the identity module exports &lt;code&gt;client_ids&lt;/code&gt; and &lt;code&gt;principal_ids&lt;/code&gt; as two separately named maps instead of one convenient map of identity objects.&lt;/p&gt;

&lt;p&gt;Three more things in that resource only start mattering after the first apply.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Revisions.&lt;/strong&gt; &lt;code&gt;revision_mode = "Single"&lt;/code&gt; here pairs with a &lt;code&gt;traffic_weight&lt;/code&gt; block that just says &lt;code&gt;latest_revision = true&lt;/code&gt; at 100 percent. Switch to &lt;code&gt;Multiple&lt;/code&gt; and that block becomes a list you own: percentages have to sum to exactly 100, nothing is defaulted for you, and &lt;code&gt;traffic_weight&lt;/code&gt; has no meaning at all in &lt;code&gt;Single&lt;/code&gt; mode. &lt;code&gt;max_inactive_revisions = 3&lt;/code&gt; is the knob almost nobody sets. Container Apps keeps inactive revisions around, they show up in every listing and every diff, and three is enough history to roll back to while staying readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scaling.&lt;/strong&gt; What &lt;code&gt;concurrent_requests = "50"&lt;/code&gt; actually counts is the thing &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik#the-http-rule-counts-a-rate-not-concurrency"&gt;Part 6 settled with arithmetic&lt;/a&gt;, against a Microsoft page that contradicts itself two paragraphs apart; this article is about the packaging, so take the number from there.&lt;/p&gt;

&lt;p&gt;The packaging detail is &lt;code&gt;custom_scale_rule.identity_id&lt;/code&gt;, which landed in azurerm &lt;strong&gt;4.69.0&lt;/strong&gt;. Below that floor a Service Bus scale rule has to authenticate with a connection string, which means a shared access key in a secret, which means the one credential the rest of this architecture went out of its way not to have. Copy that argument name out of the registry page and you will also get &lt;code&gt;Error: Unsupported argument&lt;/code&gt;: the rendered docs spell it &lt;code&gt;ìdentity_id&lt;/code&gt;, with a Latin i-grave, and in most editors it looks exactly like &lt;code&gt;identity_id&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;polling_interval_in_seconds&lt;/code&gt; and &lt;code&gt;cooldown_period_in_seconds&lt;/code&gt; are &lt;code&gt;template&lt;/code&gt; arguments rather than scale-rule ones, and 4.51.0 itself had neither; &lt;code&gt;~&amp;gt; 4.51&lt;/code&gt; floats up to 4.81.0, which has both. They decide how quickly a scaled-to-zero worker notices a message and how long it lingers afterwards, so set them rather than inherit 30 and 300 by accident.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Secrets.&lt;/strong&gt; The &lt;code&gt;secret&lt;/code&gt; block takes either a literal &lt;code&gt;value&lt;/code&gt;, which puts the secret in state in cleartext, or a &lt;code&gt;key_vault_secret_id&lt;/code&gt;, which does not. The reference form needs an &lt;code&gt;identity&lt;/code&gt; alongside it, and it has to be an identity that actually holds a secrets-read grant on the vault, or the revision fails to start on secret resolution rather than on the image pull. The sample passes &lt;code&gt;versionless_id&lt;/code&gt; so that rotating the secret in Key Vault does not require a Terraform run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Dapr components: &lt;code&gt;scopes&lt;/code&gt; is the security boundary, and both ways of getting it wrong are silent
&lt;/h2&gt;

&lt;p&gt;Get &lt;code&gt;scopes&lt;/code&gt; wrong in either direction and &lt;code&gt;terraform apply&lt;/code&gt; is green. Microsoft states the rule plainly: component scopes "correspond to the Dapr application ID of a container app, not the container app name", and "by default, all Dapr-enabled container apps in the same environment load the full set of deployed components" (&lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-components#component-scopes" rel="noopener noreferrer"&gt;dapr-components&lt;/a&gt;). Those are the two failure shapes.&lt;/p&gt;

&lt;p&gt;Put the container app name in the list, or the Terraform resource name, or the app id with the environment suffix somebody added to the naming convention last quarter, and the component matches nothing. It is deployed, it is visible in the portal, it loads into no sidecar, and the first &lt;code&gt;POST /v1.0/state/statestore&lt;/code&gt; comes back 500 at runtime. Leave &lt;code&gt;scopes&lt;/code&gt; out entirely and the component loads into every Dapr-enabled app in the environment, including the ones with no business holding a connection to the orders database. The security argument for the second case is obvious; the cost argument is not. Dapr's Cosmos reference warns that Cosmos enforces a metadata request rate limit &lt;a href="https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-azure-cosmosdb/" rel="noopener noreferrer"&gt;shared across the whole account&lt;/a&gt; and that new connections eat a large slice of it, then recommends scoping components to specific applications. Every sidecar in the environment opens its connection at startup whether it will ever read state or not.&lt;/p&gt;

&lt;p&gt;The fix inside one module is to make the scope an attribute reference, &lt;code&gt;scopes = [azurerm_container_app.orders.dapr[0].app_id]&lt;/code&gt;, so the two strings cannot drift. Across module boundaries the reference has to survive the trip, which is why the container-apps module reads its own resource back rather than reusing the input map:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;output&lt;/span&gt; &lt;span class="s2"&gt;"dapr_app_ids"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;value&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;azurerm_container_app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;app_id&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Dapr app ids read back off the container app resource. This is what the scopes list on a Dapr component expects; the container app name is not."&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;keys(var.apps)&lt;/code&gt; would have produced the same strings today and would have gone on producing them after someone added a prefix inside the module. Reading the attribute makes it an edge in the graph as well as a value.&lt;/p&gt;

&lt;p&gt;On the receiving side the components module refuses to accept the omission at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;variable&lt;/span&gt; &lt;span class="s2"&gt;"state_store_scopes"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;type&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;description&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Dapr app ids allowed to load the state store. Not container app names, and not Terraform resource names."&lt;/span&gt;

  &lt;span class="nx"&gt;validation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;condition&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state_store_scopes&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="nx"&gt;error_message&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Set scopes explicitly; an unscoped component is loaded by every Dapr-enabled app in the environment."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no default. An unscoped component is a decision, and a module that lets you make it by forgetting to type something is a module that will make it for you.&lt;/p&gt;

&lt;p&gt;The three components themselves carry no credentials:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# init_timeout is documented as an ISO 8601 string with the example "5s". Real ISO 8601 durations&lt;/span&gt;
&lt;span class="c1"&gt;# look like PT30S, and PT30S is not what the provider accepts. The Go-style form is correct.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_container_app_environment_dapr_component"&lt;/span&gt; &lt;span class="s2"&gt;"state_cosmos"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"statestore"&lt;/span&gt;
  &lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt;
  &lt;span class="nx"&gt;component_type&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"state.azure.cosmosdb"&lt;/span&gt;
  &lt;span class="nx"&gt;version&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"v1"&lt;/span&gt;
  &lt;span class="nx"&gt;init_timeout&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"30s"&lt;/span&gt;
  &lt;span class="nx"&gt;ignore_errors&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;scopes&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state_store_scopes&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"url"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cosmos_endpoint&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"database"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cosmos_database&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"collection"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cosmos_container&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azureClientId"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_identity_client_id&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"actorStateStore"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"true"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# v2, not the v1 in the provider's own registry example. v1 strips the state key prefix as though&lt;/span&gt;
&lt;span class="c1"&gt;# keyPrefix were always none, and there is no migration path from v1 to v2.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_container_app_environment_dapr_component"&lt;/span&gt; &lt;span class="s2"&gt;"state_blob"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;blob_state_store&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt; &lt;span class="err"&gt;?&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"checkpoints"&lt;/span&gt;
  &lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt;
  &lt;span class="nx"&gt;component_type&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"state.azure.blobstorage"&lt;/span&gt;
  &lt;span class="nx"&gt;version&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"v2"&lt;/span&gt;
  &lt;span class="nx"&gt;scopes&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;state_store_scopes&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azureClientId"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_identity_client_id&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_container_app_environment_dapr_component"&lt;/span&gt; &lt;span class="s2"&gt;"pubsub_servicebus"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"orders-pubsub"&lt;/span&gt;
  &lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_app_environment_id&lt;/span&gt;
  &lt;span class="nx"&gt;component_type&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pubsub.azure.servicebus.topics"&lt;/span&gt;
  &lt;span class="nx"&gt;version&lt;/span&gt;                      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"v1"&lt;/span&gt;
  &lt;span class="nx"&gt;scopes&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pubsub_scopes&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"namespaceName"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_namespace_fqdn&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"azureClientId"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dapr_identity_client_id&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;metadata&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"consumerID"&lt;/span&gt;
    &lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"{appID}"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No &lt;code&gt;masterKey&lt;/code&gt;, no &lt;code&gt;connectionString&lt;/code&gt;, no &lt;code&gt;accountKey&lt;/code&gt;, and no &lt;code&gt;secret&lt;/code&gt; block backing any of them. The whole authentication story is &lt;code&gt;azureClientId&lt;/code&gt; plus the client ID of a user-assigned identity that holds data-plane role assignments, which is the point at which this stops being a Terraform question and becomes the role assignment question further down the page.&lt;/p&gt;

&lt;p&gt;Two lines in that sample disagree with the documentation on purpose. The blob component is &lt;code&gt;version = "v2"&lt;/code&gt; where the provider's own registry example writes &lt;code&gt;v1&lt;/code&gt;; Dapr's reference says users "should always use v2 by default" and that &lt;a href="https://docs.dapr.io/reference/components-reference/supported-state-stores/setup-azure-blobstorage/" rel="noopener noreferrer"&gt;there is no migration path from v1 to v2&lt;/a&gt;, because v1 strips the state key prefix as though &lt;code&gt;keyPrefix&lt;/code&gt; were always &lt;code&gt;none&lt;/code&gt;. Copy the registry example into a new module and you have inherited a legacy component you cannot upgrade in place. And &lt;code&gt;init_timeout&lt;/code&gt; is documented as "an &lt;code&gt;ISO8601&lt;/code&gt; formatted string. e.g. &lt;code&gt;5s&lt;/code&gt;, &lt;code&gt;2h&lt;/code&gt;, &lt;code&gt;1m&lt;/code&gt;", which is not what ISO 8601 durations look like. Write &lt;code&gt;PT30S&lt;/code&gt; and it fails. &lt;code&gt;30s&lt;/code&gt; is correct and the doc text is wrong about the name of the format it is describing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The subnet you cannot resize
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;infrastructure_subnet_id&lt;/code&gt; has been an input everywhere above. The networking module is where it gets made, carved out of one address space alongside two other prefixes, each with a different job:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;aca_prefix&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cidrsubnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address_space&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_subnet_newbits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;pe_prefix&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cidrsubnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address_space&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="nx"&gt;apim_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;cidrsubnet&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address_space&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;9&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_virtual_network"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"vnet-${var.workload}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;address_space&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;address_space&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Size is immutable once the environment exists. Changing this prefix is a rebuild of the&lt;/span&gt;
&lt;span class="c1"&gt;# environment and of every app and Dapr component in it.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"snet-aca-infra"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;address_prefixes&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;delegation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"aca-environment"&lt;/span&gt;

    &lt;span class="nx"&gt;service_delegation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Microsoft.App/environments"&lt;/span&gt;
      &lt;span class="nx"&gt;actions&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Microsoft.Network/virtualNetworks/subnets/action"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet"&lt;/span&gt; &lt;span class="s2"&gt;"private_endpoints"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"snet-pe"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_name&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;address_prefixes&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;pe_prefix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;private_endpoint_network_policies&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Disabled"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet"&lt;/span&gt; &lt;span class="s2"&gt;"apim"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"snet-apim"&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;address_prefixes&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apim_prefix&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

  &lt;span class="nx"&gt;delegation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"apim"&lt;/span&gt;

    &lt;span class="nx"&gt;service_delegation&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Microsoft.ApiManagement/service"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# v5 shape. v4 wrote service_endpoints = ["Microsoft.Storage", "Microsoft.EventHub"].&lt;/span&gt;
  &lt;span class="nx"&gt;service_endpoint&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;service&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Microsoft.Storage"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;service_endpoint&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;service&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Microsoft.EventHub"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;aca_subnet_newbits = 7&lt;/code&gt; against a &lt;code&gt;/16&lt;/code&gt; produces a &lt;code&gt;/23&lt;/code&gt;, and that number is the only one in this article you cannot revise later. Learn's rule for a workload profiles environment is that "the minimum subnet size required for virtual network integration is &lt;code&gt;/27&lt;/code&gt;", and a few lines further down on the same page, "you can't modify subnet sizes after you create a Container Apps environment" (&lt;a href="https://learn.microsoft.com/azure/container-apps/custom-virtual-networks#subnet" rel="noopener noreferrer"&gt;custom-virtual-networks#subnet&lt;/a&gt;). An undersized subnet is not a resize. It is a new environment, a new set of apps, new Dapr components, and a cutover.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/27&lt;/code&gt; is legal and it caps hard:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flybhjqjop2z80eo9xxmi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flybhjqjop2z80eo9xxmi.png" alt="Container Apps subnet sizing: available IPs per CIDR prefix and the node ceiling it imposes on Dedicated profiles against the replica ceiling on Consumption" width="730" height="256"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Nine Dedicated nodes is a small production environment on a good day, and a rollout in &lt;code&gt;revision_mode = "Single"&lt;/code&gt; runs the old and new revisions side by side, so the real ceiling during a deploy is roughly half the column. A &lt;code&gt;/23&lt;/code&gt; out of a &lt;code&gt;10.0.0.0/16&lt;/code&gt; costs you address space you were never going to allocate to anything else.&lt;/p&gt;

&lt;p&gt;Do not compute the size yourself from a reserved-IP count, because Microsoft states that count three ways. The body text on &lt;code&gt;custom-virtual-networks#subnet&lt;/code&gt; says Container Apps "automatically reserves 12 IP addresses". The footnote under the sizing table on that same page says 14, "which includes 5 IP addresses that the subnet reserves". The &lt;a href="https://learn.microsoft.com/azure/container-apps/workload-profiles-manage-cli#create-a-container-app-in-a-profile" rel="noopener noreferrer"&gt;workload profiles CLI page&lt;/a&gt; says 11, and concludes that a &lt;code&gt;/27&lt;/code&gt; has 21 available addresses, which contradicts the 18 in the table. Nobody has reconciled these. The sizing table is the source to trust, because it is the only one that resolves to node and replica limits rather than to an IP count, and its arithmetic agrees with itself. Read the replica column, double it for the rollout, and pick the row above that.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/21&lt;/code&gt; figure still circulating comes from the azurerm 4.51 docs and is stale by a factor of 64. The &lt;code&gt;/23&lt;/code&gt; minimum that sits next to it belongs to the legacy Consumption-only environment, and that is also where the delegation rule inverts rather than relaxes: a workload profiles subnet &lt;strong&gt;must&lt;/strong&gt; be delegated to &lt;code&gt;Microsoft.App/environments&lt;/code&gt;, and a Consumption-only subnet "must not be delegated to any services, including &lt;code&gt;Microsoft.App/environments&lt;/code&gt;". Copying a Consumption-era module into a workload profiles environment gets both halves wrong at once. The &lt;code&gt;actions&lt;/code&gt; list under &lt;code&gt;service_delegation&lt;/code&gt; is the one Azure fills in for that delegation anyway; write it or leave it out, you cannot change it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;azurerm_virtual_network&lt;/code&gt; also accepts an inline &lt;code&gt;subnet&lt;/code&gt; block, and a VNet that uses the inline form and standalone &lt;code&gt;azurerm_subnet&lt;/code&gt; resources at the same time fights itself on every plan. Pick one, and pick the standalone resources.&lt;/p&gt;

&lt;h3&gt;
  
  
  The NSG rules everyone pastes are the Consumption rules
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Workload profiles rules, not the Consumption-only set. The Consumption environment needs&lt;/span&gt;
&lt;span class="c1"&gt;# an outbound allow to AzureCloud on 443 and to 1.1.1.1/1.0.0.1 on 53; a workload profiles&lt;/span&gt;
&lt;span class="c1"&gt;# environment reaches its control plane over the same 443 rules the app already needs.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_network_security_group"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"nsg-aca-${var.workload}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;

  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow-apim-to-edge-proxy"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_ranges&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"443"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"31443"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;apim_prefix&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow-lb-health-probe"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;110&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"30000-32767"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"AzureLoadBalancer"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# An NSG is evaluated on both NICs, so the catch-all deny below would otherwise override the&lt;/span&gt;
  &lt;span class="c1"&gt;# default AllowVnetInBound at priority 65000 and break pod to pod traffic inside the subnet.&lt;/span&gt;
  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow-intra-subnet-inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;120&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"deny-other-inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Inbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Deny"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow-entra"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Outbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Tcp"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"443"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"AzureActiveDirectory"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="c1"&gt;# Never deny 168.63.129.16. The environment stops working, and nothing in the portal says why.&lt;/span&gt;
  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"allow-azure-platform-dns"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;150&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Outbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Allow"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"53"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;aca_prefix&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"168.63.129.16"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;security_rule&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"deny-other-outbound"&lt;/span&gt;
    &lt;span class="nx"&gt;priority&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4000&lt;/span&gt;
    &lt;span class="nx"&gt;direction&lt;/span&gt;                  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Outbound"&lt;/span&gt;
    &lt;span class="nx"&gt;access&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Deny"&lt;/span&gt;
    &lt;span class="nx"&gt;protocol&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_port_range&lt;/span&gt;          &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_port_range&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;source_address_prefix&lt;/span&gt;      &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
    &lt;span class="nx"&gt;destination_address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet_network_security_group_association"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;subnet_id&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;network_security_group_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_network_security_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The full module adds four more outbound allows on 443, to &lt;code&gt;MicrosoftContainerRegistry&lt;/code&gt;, &lt;code&gt;AzureFrontDoor.FirstParty&lt;/code&gt;, &lt;code&gt;AzureMonitor&lt;/code&gt; and the private endpoint prefix. What is missing is the interesting part. Most Container Apps NSGs in the wild were copied off the Consumption-only tab of &lt;a href="https://learn.microsoft.com/azure/container-apps/firewall-integration" rel="noopener noreferrer"&gt;firewall-integration&lt;/a&gt;, and on a workload profiles environment those extra rules grant reachability nobody needs:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Folfnrfet82o6mb8mrhxr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Folfnrfet82o6mb8mrhxr.png" alt="NSG rules from the Consumption-only guidance against what a workload profiles environment actually needs, including the inbound gateway subnet ports that only workload profiles require" width="800" height="367"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AzureActiveDirectory&lt;/code&gt; on 443 outbound sits on the workload profiles outbound list with a condition attached: "If you're using a managed identity, it's required" (&lt;a href="https://learn.microsoft.com/azure/container-apps/firewall-integration" rel="noopener noreferrer"&gt;firewall-integration&lt;/a&gt;). In this architecture that condition is never false, because every identity here is a managed identity and every one of them fetches its token over that path. Remove that rule and you do not break the platform; you break every grant the previous section set up, some hours later, when a cached token expires.&lt;/p&gt;

&lt;p&gt;Two more rules are not about ports. Never deny &lt;code&gt;168.63.129.16&lt;/code&gt;: the docs carry an explicit warning and the environment stops working. And the moment a catch-all inbound deny exists, an explicit intra-subnet inbound allow becomes mandatory, because an NSG is evaluated on both the source and the destination NIC and a rule at priority 4000 wins over the default &lt;code&gt;AllowVnetInBound&lt;/code&gt; at 65000. One more shows up only at apply time: service tags work in &lt;code&gt;source_address_prefix&lt;/code&gt; and not in &lt;code&gt;source_address_prefixes&lt;/code&gt;, so the plural form takes your &lt;code&gt;AzureLoadBalancer&lt;/code&gt; string and fails on the API call.&lt;/p&gt;

&lt;p&gt;The sharper point is that on an &lt;strong&gt;external&lt;/strong&gt; workload profiles environment, none of the inbound rules do anything at all. Traffic arrives through a public IP in the environment's managed resource group and reaches the app without ever transiting your subnet, so the NSG sees it only on the way out. &lt;code&gt;internal_only = true&lt;/code&gt; is what turns this file from documentation into enforcement, which is the Terraform-shaped version of the argument &lt;a href="https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik"&gt;Part 6&lt;/a&gt; made about Private Link at the gateway.&lt;/p&gt;

&lt;p&gt;None of those rules apply until the association exists, which is the second dashed edge on the module diagram near the top of this article. The networking module exports &lt;code&gt;nsg_association_id&lt;/code&gt; for callers who would rather have that ordering as a reference than as a hand-written prerequisite; the root module takes the blunter route and lists &lt;code&gt;module.networking&lt;/code&gt; in &lt;code&gt;depends_on&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Private DNS: the zone the private endpoint will not create for you
&lt;/h2&gt;

&lt;p&gt;Four services go behind private endpoints and they need five zones:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;# ACR Premium needs the region-specific data zone as well as the registry zone.&lt;/span&gt;
  &lt;span class="c1"&gt;# Without it the manifest resolves privately and the layer download falls back to the public endpoint.&lt;/span&gt;
  &lt;span class="nx"&gt;private_dns_zone_names&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cosmos&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"privatelink.documents.azure.com"&lt;/span&gt;
    &lt;span class="nx"&gt;servicebus&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"privatelink.servicebus.windows.net"&lt;/span&gt;
    &lt;span class="nx"&gt;keyvault&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"privatelink.vaultcore.azure.net"&lt;/span&gt;
    &lt;span class="nx"&gt;acr&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"privatelink.azurecr.io"&lt;/span&gt;
    &lt;span class="nx"&gt;acr_data&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${var.location}.data.privatelink.azurecr.io"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_dns_zone"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;private_dns_zone_names&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# private_dns_zone_group on the endpoint writes the records. It does not link the zone to the&lt;/span&gt;
&lt;span class="c1"&gt;# VNet, and an unlinked zone resolves to the public IP with no DNS error anywhere.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_dns_zone_virtual_network_link"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_private_dns_zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"link-${each.key}-${var.workload}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;private_dns_zone_id&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_id&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_virtual_network&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;registration_enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_endpoint"&lt;/span&gt; &lt;span class="s2"&gt;"container_registry"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"pe-acr-${var.workload}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;subnet_id&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_subnet&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;private_endpoints&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;

  &lt;span class="nx"&gt;private_service_connection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt;                           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"psc-acr"&lt;/span&gt;
    &lt;span class="nx"&gt;private_connection_resource_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_registry_id&lt;/span&gt;
    &lt;span class="nx"&gt;subresource_names&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"registry"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="nx"&gt;is_manual_connection&lt;/span&gt;           &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;private_dns_zone_group&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"acr"&lt;/span&gt;
    &lt;span class="nx"&gt;private_dns_zone_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
      &lt;span class="nx"&gt;azurerm_private_dns_zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"acr"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="nx"&gt;azurerm_private_dns_zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"acr_data"&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A private endpoint does exactly one DNS job for you, and it is not the one people assume. &lt;code&gt;private_dns_zone_group&lt;/code&gt; writes the A record for the endpoint's private IP into the zones you list. It does not link those zones to a VNet. Skip the link and every lookup falls through to public DNS, which answers with the public IP, and nothing reports a DNS failure anywhere: the application gets a connection refused or a 403 from a firewall, and the first four people who look at it will look at the firewall. The &lt;code&gt;for_each&lt;/code&gt; pairing zones with links is worth more than the typing it saves, because it makes an unlinked zone impossible to create.&lt;/p&gt;

&lt;p&gt;Three details in that file will only ever be checked by the service. &lt;code&gt;subresource_names&lt;/code&gt; is case-sensitive at the API and the casing is not consistent between services: &lt;code&gt;Sql&lt;/code&gt; for Cosmos NoSQL, &lt;code&gt;namespace&lt;/code&gt; for Service Bus, &lt;code&gt;vault&lt;/code&gt; for Key Vault, &lt;code&gt;registry&lt;/code&gt; for the registry. Cosmos in particular has one answer per API, so a Table or Gremlin account needs a different subresource and a different zone than the &lt;code&gt;privatelink.documents.azure.com&lt;/code&gt; above. Second, &lt;code&gt;privatelink.servicebus.windows.net&lt;/code&gt; is shared by Service Bus, Event Hubs, Relay and IoT Hub, so four unrelated services collide in one zone and one &lt;code&gt;for_each&lt;/code&gt; key. Third, ACR Premium needs two zones. The registry zone resolves the manifest; the region-specific &lt;code&gt;{region}.data.privatelink.azurecr.io&lt;/code&gt; zone resolves the data endpoint that serves the layers. Omit the second and a pull starts privately, then stalls or falls back partway through the download, which looks like a network problem and is a missing zone.&lt;/p&gt;

&lt;p&gt;The zone nobody remembers belongs to the environment itself, and it lives in the root module because the environment is not a private endpoint at all:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# A private endpoint gets its records from private_dns_zone_group. The environment is not a&lt;/span&gt;
&lt;span class="c1"&gt;# private endpoint, so its default_domain zone is hand-built: wildcard for the apps, apex for&lt;/span&gt;
&lt;span class="c1"&gt;# the environment itself, both pointing at the internal load balancer address.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_dns_zone"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps_environment"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment_default_domain&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_dns_zone_virtual_network_link"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps_environment"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"link-cae-${local.name_suffix}"&lt;/span&gt;
  &lt;span class="nx"&gt;private_dns_zone_id&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_private_dns_zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps_environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;virtual_network_id&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;networking&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vnet_id&lt;/span&gt;
  &lt;span class="nx"&gt;registration_enabled&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;
  &lt;span class="nx"&gt;resolution_policy&lt;/span&gt;    &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Default"&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_private_dns_a_record"&lt;/span&gt; &lt;span class="s2"&gt;"container_apps_wildcard"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"*"&lt;/span&gt;
  &lt;span class="nx"&gt;private_dns_zone_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_private_dns_zone&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps_environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt;
  &lt;span class="nx"&gt;ttl&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;300&lt;/span&gt;
  &lt;span class="nx"&gt;records&lt;/span&gt;             &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_apps&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment_static_ip&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both halves of that are exported attributes, &lt;code&gt;default_domain&lt;/code&gt; and &lt;code&gt;static_ip_address&lt;/code&gt;, so no data source and no hard-coded domain is involved. The apex record is the same shape with &lt;code&gt;name = "@"&lt;/code&gt;. This zone only belongs on an &lt;strong&gt;internal&lt;/strong&gt; environment: &lt;code&gt;static_ip_address&lt;/code&gt; is the internal load balancer address when &lt;code&gt;internal_load_balancer_enabled&lt;/code&gt; is true and a public IP when it is not, and publishing a public IP into a private zone is a confusing way to achieve nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Coming from azurerm v4
&lt;/h3&gt;

&lt;p&gt;Four v5 changes hit this stack, and the private DNS one is why the diff is large rather than interesting:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxpqbxko89o7yyghfe1kc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxpqbxko89o7yyghfe1kc.png" alt="AzureRM provider v4 to v5 breaking changes: renamed arguments, the service endpoint block syntax switch, the inverted Cosmos DB local auth flag, and where each one bites" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The link and record rows are mechanical: five zones against one VNet means five links, plus every A record resource. The row to slow down on is the Cosmos one, because it is a rename &lt;strong&gt;and&lt;/strong&gt; a polarity flip. Carry the boolean across unchanged and you have written &lt;code&gt;local_authentication_enabled = true&lt;/code&gt;, which turns key authentication back on in the same commit where you believed you turned it off, and the plan diff reads like a rename. The neighbouring services spell the same idea three more ways for good measure: Service Bus uses &lt;code&gt;local_auth_enabled = false&lt;/code&gt; and Key Vault uses &lt;code&gt;rbac_authorization_enabled = true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;None of the &lt;code&gt;container_app&lt;/code&gt; resources themselves carry a breaking change across either major. The whole tree validated on &lt;code&gt;~&amp;gt; 4.51&lt;/code&gt; and on &lt;code&gt;~&amp;gt; 5.6&lt;/code&gt;. Everything that hurt was in the network and the data services around them.&lt;/p&gt;

&lt;h2&gt;
  
  
  The identity chain, and the edge Terraform cannot see
&lt;/h2&gt;

&lt;p&gt;One identity per app, and every grant it needs hanging off it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;# Role GUIDs, not names. A renamed role keeps its ID, and a name costs a role-definitions&lt;/span&gt;
  &lt;span class="c1"&gt;# lookup on every plan.&lt;/span&gt;
  &lt;span class="nx"&gt;role_ids&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;acr_pull&lt;/span&gt;         &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"7f951dda-4ed3-4680-a7ca-43fe172d538d"&lt;/span&gt;
    &lt;span class="nx"&gt;kv_secrets_user&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"4633458b-17de-408a-b874-0445c86b69e6"&lt;/span&gt;
    &lt;span class="nx"&gt;sb_data_sender&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"69a216fc-b8fb-44d8-bc22-1f3c2cd27a39"&lt;/span&gt;
    &lt;span class="nx"&gt;sb_data_receiver&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"4f6d3b9b-027b-4f4c-9142-0e5a2a2247e0"&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nx"&gt;role_definition_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"/subscriptions/${data.azurerm_client_config.current.subscription_id}/providers/Microsoft.Authorization/roleDefinitions"&lt;/span&gt;

  &lt;span class="c1"&gt;# Grants are scoped to the individual queue, never to the namespace.&lt;/span&gt;
  &lt;span class="nx"&gt;app_queue_pairs&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;for&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt; &lt;span class="nx"&gt;in&lt;/span&gt; &lt;span class="nx"&gt;setproduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;tolist&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_ids&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nx"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_queue_ids&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt;
    &lt;span class="s2"&gt;"${pair[0]}.${pair[1]}"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;app_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
      &lt;span class="nx"&gt;queue&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;pair&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_user_assigned_identity"&lt;/span&gt; &lt;span class="s2"&gt;"app"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_ids&lt;/span&gt;

  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"id-${each.value}-${var.environment}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# principal_id is unknown until apply, so Terraform orders the identity ahead of every grant&lt;/span&gt;
&lt;span class="c1"&gt;# below without any help. The edge it cannot see is the one from the container app to this&lt;/span&gt;
&lt;span class="c1"&gt;# grant; see the depends_on on the container-apps module call in the root module.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_role_assignment"&lt;/span&gt; &lt;span class="s2"&gt;"acr_pull"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_ids&lt;/span&gt;

  &lt;span class="nx"&gt;scope&lt;/span&gt;              &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;container_registry_id&lt;/span&gt;
  &lt;span class="nx"&gt;role_definition_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${local.role_definition_prefix}/${local.role_ids.acr_pull}"&lt;/span&gt;
  &lt;span class="nx"&gt;principal_id&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_user_assigned_identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;principal_id&lt;/span&gt;

  &lt;span class="c1"&gt;# Correct for a managed identity and wrong for a user or a group: it suppresses the existence&lt;/span&gt;
  &lt;span class="c1"&gt;# check that fails with PrincipalNotFound while Entra is still replicating the new principal.&lt;/span&gt;
  &lt;span class="nx"&gt;principal_type&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ServicePrincipal"&lt;/span&gt;
  &lt;span class="nx"&gt;skip_service_principal_aad_check&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_role_assignment"&lt;/span&gt; &lt;span class="s2"&gt;"service_bus_sender"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_queue_pairs&lt;/span&gt;

  &lt;span class="nx"&gt;scope&lt;/span&gt;                            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service_bus_queue_ids&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;queue&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="nx"&gt;role_definition_id&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${local.role_definition_prefix}/${local.role_ids.sb_data_sender}"&lt;/span&gt;
  &lt;span class="nx"&gt;principal_id&lt;/span&gt;                     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_user_assigned_identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_id&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;principal_id&lt;/span&gt;
  &lt;span class="nx"&gt;principal_type&lt;/span&gt;                   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ServicePrincipal"&lt;/span&gt;
  &lt;span class="nx"&gt;skip_service_principal_aad_check&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Cosmos data-plane access is not azurerm_role_assignment. A Cosmos DB Built-in Data Contributor&lt;/span&gt;
&lt;span class="c1"&gt;# handed out through the control plane grants nothing at the data plane, and the apply is green.&lt;/span&gt;
&lt;span class="c1"&gt;# 0001 is Data Reader, 0002 is Data Contributor.&lt;/span&gt;
&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_cosmosdb_sql_role_assignment"&lt;/span&gt; &lt;span class="s2"&gt;"data_contributor"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;for_each&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app_ids&lt;/span&gt;

  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cosmosdb_resource_group_name&lt;/span&gt;
  &lt;span class="nx"&gt;account_name&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cosmosdb_account_name&lt;/span&gt;
  &lt;span class="nx"&gt;role_definition_id&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${var.cosmosdb_account_id}/sqlRoleDefinitions/00000000-0000-0000-0000-000000000002"&lt;/span&gt;
  &lt;span class="nx"&gt;principal_id&lt;/span&gt;        &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_user_assigned_identity&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;app&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;each&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;principal_id&lt;/span&gt;
  &lt;span class="nx"&gt;scope&lt;/span&gt;               &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"${var.cosmosdb_account_id}/dbs/${var.cosmosdb_database_name}"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two edges in that file run in opposite directions and only one of them exists. &lt;code&gt;principal_id&lt;/code&gt; is unknown until apply, so Terraform has to create the identity before it can even render the role assignment, and it orders them correctly with no help. The container app in the next module over references the identity and the registry login server, never the grant, so Terraform is equally free to create the app first and let the first revision fail its pull. That is the failed pull from the opening paragraph, and the &lt;code&gt;depends_on&lt;/code&gt; on the module call is the whole of the fix.&lt;/p&gt;

&lt;p&gt;The same grant carries two more failure modes that have nothing to do with ordering. A brand new service principal can return &lt;code&gt;PrincipalNotFound&lt;/code&gt; from the role assignment API while Entra is still replicating it, which &lt;code&gt;skip_service_principal_aad_check = true&lt;/code&gt; suppresses. That argument is correct for every managed identity and wrong for a user or a group, where the check is the only thing standing between a typo and a grant to nothing. And the one nothing in Terraform can fix: managed identity backends cache tokens per resource &lt;a href="https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/managed-identity-best-practice-recommendations#limitation-of-using-managed-identities-for-authorization" rel="noopener noreferrer"&gt;"for around 24 hours"&lt;/a&gt;, and Cosmos data-plane assignments propagate on their own schedule, so a green apply is evidence that a grant exists and not that it works yet. Removing a grant lags the same way, which matters more.&lt;/p&gt;

&lt;p&gt;The GUID map is not premature optimisation: Microsoft's own advice is to use IDs because "even if the role is renamed, the role ID does not change", and &lt;code&gt;role_definition_name&lt;/code&gt; makes the provider list role definitions on every plan. &lt;code&gt;app_queue_pairs&lt;/code&gt; comes from the same instinct. &lt;code&gt;setproduct&lt;/code&gt; over apps and queues produces one grant per app per queue, scoped to &lt;code&gt;azurerm_servicebus_queue.orders.id&lt;/code&gt;. Scoping to the namespace instead is the most common over-grant in this architecture, and it is one shorter &lt;code&gt;scope&lt;/code&gt; argument away.&lt;/p&gt;

&lt;p&gt;The Cosmos resource at the bottom breaks the intuition of anyone who already knows Azure RBAC. &lt;code&gt;azurerm_role_assignment&lt;/code&gt; with a Cosmos DB Built-in Data Contributor role does exist, does apply, and grants nothing at the data plane, because Cosmos keeps its own role system underneath the account. &lt;code&gt;azurerm_cosmosdb_sql_role_assignment&lt;/code&gt; takes a &lt;code&gt;sqlRoleDefinitions/...&lt;/code&gt; path, not a subscription-level role definition ID, and its &lt;code&gt;scope&lt;/code&gt; is a data-plane path like &lt;code&gt;&amp;lt;account&amp;gt;/dbs/orders&lt;/code&gt;. Built-in &lt;code&gt;...0001&lt;/code&gt; is Data Reader and &lt;code&gt;...0002&lt;/code&gt; is Data Contributor. This is what makes &lt;code&gt;local_authentication_enabled = false&lt;/code&gt; on the account survivable: turn keys off without the data-plane assignment and every read returns 403, so the two changes belong in the same commit.&lt;/p&gt;

&lt;h2&gt;
  
  
  State, and the lease nothing expires
&lt;/h2&gt;

&lt;p&gt;One root module, one backend config per environment, one tfvars file per environment, and no workspaces:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;use_oidc&lt;/span&gt;             &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="nx"&gt;use_azuread_auth&lt;/span&gt;     &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="nx"&gt;storage_account_name&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"sttfstateprod01"&lt;/span&gt;
&lt;span class="nx"&gt;container_name&lt;/span&gt;       &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"tfstate"&lt;/span&gt;
&lt;span class="nx"&gt;key&lt;/span&gt;                  &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"container-apps/prod.tfstate"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="nx"&gt;subscription_id&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"00000000-0000-0000-0000-000000000000"&lt;/span&gt;

&lt;span class="nx"&gt;workload&lt;/span&gt;      &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;
&lt;span class="nx"&gt;environment&lt;/span&gt;   &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"prod"&lt;/span&gt;
&lt;span class="nx"&gt;location&lt;/span&gt;      &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"westeurope"&lt;/span&gt;
&lt;span class="nx"&gt;address_space&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"10.70.0.0/16"&lt;/span&gt;

&lt;span class="nx"&gt;cost_center&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"GAZE"&lt;/span&gt;
&lt;span class="nx"&gt;owner&lt;/span&gt;       &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"AZE"&lt;/span&gt;
&lt;span class="nx"&gt;project&lt;/span&gt;     &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"orders"&lt;/span&gt;

&lt;span class="nx"&gt;image_tag&lt;/span&gt;    &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1.4.2"&lt;/span&gt;
&lt;span class="nx"&gt;min_replicas&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nx"&gt;max_replicas&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;30&lt;/span&gt;

&lt;span class="nx"&gt;log_retention_days&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;

&lt;span class="nx"&gt;dedicated_workload_profiles&lt;/span&gt; &lt;span class="err"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;D4&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;profile_type&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"D4"&lt;/span&gt;
    &lt;span class="nx"&gt;minimum_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nx"&gt;maximum_count&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# orders_api_key has no default and is deliberately absent here. Supply it as&lt;/span&gt;
&lt;span class="c1"&gt;# TF_VAR_orders_api_key from the pipeline, not from a file in git.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;infra
terraform init &lt;span class="nt"&gt;-reconfigure&lt;/span&gt; &lt;span class="nt"&gt;-backend-config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;envs/prod.backend.hcl
terraform plan &lt;span class="nt"&gt;-var-file&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;envs/prod.tfvars &lt;span class="nt"&gt;-out&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;tfplan
terraform apply tfplan
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;use_azuread_auth = true&lt;/code&gt; is now a required option rather than an opt-in when you authenticate to the state account with Entra ID, and &lt;code&gt;resource_group_name&lt;/code&gt; moved from required to optional on the backend; it is needed only alongside &lt;code&gt;lookup_blob_endpoint&lt;/code&gt;. The &lt;code&gt;-reconfigure&lt;/code&gt; on &lt;code&gt;init&lt;/code&gt; lets the same working directory point at a different state blob without Terraform offering to migrate the old one.&lt;/p&gt;

&lt;p&gt;Refusing workspaces is a decision with a cost, so here are both halves. HashiCorp's own position is that "CLI workspaces within a working directory use the same backend", which makes them unsuitable for environments that differ in blast radius. The Azure-specific reason is uglier: the azurerm backend builds the workspace blob name by string concatenation, so a &lt;code&gt;staging&lt;/code&gt; workspace on &lt;code&gt;key = "container-apps/prod.tfstate"&lt;/code&gt; writes its state to a blob literally named &lt;code&gt;container-apps/prod.tfstateenv:staging&lt;/code&gt;. What you give up is per-environment configuration divergence. Anything dev needs that prod does not has to become a variable, and a variable that exists only to make dev cheaper is one somebody will eventually set in prod.&lt;/p&gt;

&lt;p&gt;The lock deserves more attention than the docs give it. All the backend documentation says is "supports state locking", and the mechanism is in &lt;a href="https://github.com/hashicorp/terraform/blob/main/internal/backend/remote-state/azure/client.go" rel="noopener noreferrer"&gt;the implementation&lt;/a&gt;: &lt;code&gt;Lock()&lt;/code&gt; acquires a blob lease on the state file with &lt;code&gt;LeaseDuration: -1&lt;/code&gt;, the Terraform lock ID travels as the proposed lease ID in the &lt;code&gt;x-ms-lease-id&lt;/code&gt; header, and the holder is recorded in the blob's &lt;code&gt;terraformlockid&lt;/code&gt; metadata. There is no lock table to provision, which is the pleasant half.&lt;/p&gt;

&lt;p&gt;The unpleasant half is that &lt;code&gt;-1&lt;/code&gt; means infinite, and infinite means nothing expires it. A runner that is hard-killed mid-apply leaves the state locked until a human runs &lt;code&gt;terraform force-unlock &amp;lt;LOCK_ID&amp;gt;&lt;/code&gt; or breaks the lease in the portal. That is a runbook entry, not a piece of folklore, and it is the reason every plan and apply in the next section passes &lt;code&gt;-lock-timeout=5m&lt;/code&gt; and the workflow sets &lt;code&gt;cancel-in-progress: false&lt;/code&gt;. The default reflex of &lt;code&gt;cancel-in-progress: true&lt;/code&gt; is precisely the wrong setting here: it cancels a running apply halfway through and strands the lease it was holding.&lt;/p&gt;

&lt;p&gt;Correct reasoning gets you the wrong answer on one RBAC detail. Storage Blob Data &lt;strong&gt;Reader&lt;/strong&gt; is not enough for &lt;code&gt;terraform plan&lt;/code&gt;, because plan takes the lock and taking the lock writes blob metadata. Grant Contributor scoped to the container, or run read-only plans with &lt;code&gt;-lock=false&lt;/code&gt; and accept that you can read a state file somebody else is halfway through writing.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tags: the provider argument that does not exist
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;cost_center&lt;/code&gt;, &lt;code&gt;owner&lt;/code&gt; and &lt;code&gt;project&lt;/code&gt; are in that tfvars file because the policy in this tenant denies any resource missing &lt;code&gt;cost-center&lt;/code&gt;, &lt;code&gt;owner&lt;/code&gt;, &lt;code&gt;environment&lt;/code&gt; and &lt;code&gt;project&lt;/code&gt;. That is a provider-level problem in every IaC tool that has provider-level tags. azurerm is not one of them:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight hcl"&gt;&lt;code&gt;&lt;span class="c1"&gt;# azurerm has no provider-level default_tags, so the policy-required four go in a locals map and&lt;/span&gt;
&lt;span class="c1"&gt;# get assigned on every resource. merge() where a resource needs extras.&lt;/span&gt;
&lt;span class="nx"&gt;locals&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;required_tags&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s2"&gt;"cost-center"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cost_center&lt;/span&gt;
    &lt;span class="s2"&gt;"owner"&lt;/span&gt;       &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;owner&lt;/span&gt;
    &lt;span class="s2"&gt;"environment"&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;environment&lt;/span&gt;
    &lt;span class="s2"&gt;"project"&lt;/span&gt;     &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;project&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_log_analytics_workspace"&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;name&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"log-${local.name_suffix}"&lt;/span&gt;
  &lt;span class="nx"&gt;location&lt;/span&gt;            &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;location&lt;/span&gt;
  &lt;span class="nx"&gt;resource_group_name&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_resource_group&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;name&lt;/span&gt;
  &lt;span class="nx"&gt;sku&lt;/span&gt;                 &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"PerGB2018"&lt;/span&gt;
  &lt;span class="nx"&gt;retention_in_days&lt;/span&gt;   &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;var&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;log_retention_days&lt;/span&gt;
  &lt;span class="nx"&gt;tags&lt;/span&gt;                &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;local&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;required_tags&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;tags = local.required_tags&lt;/code&gt; on every resource, &lt;code&gt;tags = merge(local.required_tags, { ... })&lt;/code&gt; where one needs extras, and a review that catches the resource where somebody forgot. The tracker will tell you otherwise if you let it: &lt;a href="https://github.com/hashicorp/terraform-provider-azurerm/issues/11682" rel="noopener noreferrer"&gt;issue #11682&lt;/a&gt; asking for &lt;code&gt;default_tags&lt;/code&gt; has 48 reactions and is closed as completed, while &lt;a href="https://github.com/hashicorp/terraform-provider-azurerm/pull/31108" rel="noopener noreferrer"&gt;PR #31108&lt;/a&gt; adding the argument has been open and unmerged since November 2025. A closed-as-completed issue is not a released feature.&lt;/p&gt;

&lt;p&gt;The tooling will not correct you either. Write &lt;code&gt;default_tags { tags = local.required_tags }&lt;/code&gt; into a provider block, run &lt;code&gt;terraform validate&lt;/code&gt;, and you get &lt;code&gt;Success!&lt;/code&gt;, because &lt;code&gt;validate&lt;/code&gt; never decodes the &lt;code&gt;provider&lt;/code&gt; block, and neither does &lt;code&gt;plan&lt;/code&gt; when no resource needs a provider instance: a configuration whose only content was that invented block also returned &lt;code&gt;No changes.&lt;/code&gt; "It validated" is not evidence that an argument exists. &lt;code&gt;terraform providers schema -json&lt;/code&gt; is the answer: the azurerm provider block carries no tag attribute and exactly one nested block, &lt;code&gt;features&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline: plan on the PR, apply behind an environment gate
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Terraform&lt;/span&gt;

&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;pull_request&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TerraformContainerAppsDemo/infra/**"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
  &lt;span class="na"&gt;push&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;branches&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;main&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;
    &lt;span class="na"&gt;paths&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;TerraformContainerAppsDemo/infra/**"&lt;/span&gt;&lt;span class="pi"&gt;]&lt;/span&gt;

&lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;

&lt;span class="na"&gt;concurrency&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform-${{ github.ref }}&lt;/span&gt;
  &lt;span class="c1"&gt;# Never true here. The azurerm backend lock is an infinite blob lease, so a cancelled apply&lt;/span&gt;
  &lt;span class="c1"&gt;# strands the state locked until someone runs terraform force-unlock.&lt;/span&gt;
  &lt;span class="na"&gt;cancel-in-progress&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

&lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;TF_IN_AUTOMATION&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&lt;/span&gt;
  &lt;span class="na"&gt;ARM_USE_OIDC&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&lt;/span&gt;
  &lt;span class="na"&gt;ARM_USE_AZUREAD&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&lt;/span&gt;
  &lt;span class="na"&gt;ARM_CLIENT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.AZURE_CLIENT_ID }}&lt;/span&gt;
  &lt;span class="na"&gt;ARM_TENANT_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.AZURE_TENANT_ID }}&lt;/span&gt;
  &lt;span class="na"&gt;ARM_SUBSCRIPTION_ID&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ vars.AZURE_SUBSCRIPTION_ID }}&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;plan&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Plan (prod)&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
      &lt;span class="na"&gt;pull-requests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
    &lt;span class="na"&gt;defaults&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TerraformContainerAppsDemo/infra&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v5&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;terraform_version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.16.3&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Init&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;init&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform init -input=false -backend-config=envs/prod.backend.hcl&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Validate&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;validate&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform validate -no-color&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Plan&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;plan&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;TF_VAR_orders_api_key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.ORDERS_API_KEY }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform plan -input=false -no-color -lock-timeout=5m -var-file=envs/prod.tfvars -out=tfplan&lt;/span&gt;
        &lt;span class="na"&gt;continue-on-error&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Fail if plan errored&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;steps.plan.outcome == 'failure'&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;exit &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;

      &lt;span class="c1"&gt;# A saved plan carries sensitive values in cleartext and any user with repo read can&lt;/span&gt;
      &lt;span class="c1"&gt;# download an artifact. Keep the retention short.&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Upload plan&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'push'&lt;/span&gt;
        &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/upload-artifact@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tfplan&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TerraformContainerAppsDemo/infra/tfplan&lt;/span&gt;
          &lt;span class="na"&gt;retention-days&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;

  &lt;span class="na"&gt;apply&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Apply (prod)&lt;/span&gt;
    &lt;span class="na"&gt;needs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;plan&lt;/span&gt;
    &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;github.event_name == 'push' &amp;amp;&amp;amp; github.ref == 'refs/heads/main'&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="c1"&gt;# The approval gate is this key and nothing else. Required reviewers, wait timers and&lt;/span&gt;
    &lt;span class="c1"&gt;# deployment branch rules are configured on the environment in repo settings.&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prod&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
    &lt;span class="na"&gt;defaults&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;working-directory&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TerraformContainerAppsDemo/infra&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/checkout@v5&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;hashicorp/setup-terraform@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;terraform_version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;1.16.3&lt;/span&gt;
          &lt;span class="na"&gt;terraform_wrapper&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;uses&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;actions/download-artifact@v4&lt;/span&gt;
        &lt;span class="na"&gt;with&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;tfplan&lt;/span&gt;
          &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;TerraformContainerAppsDemo/infra&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Init&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform init -input=false -backend-config=envs/prod.backend.hcl&lt;/span&gt;

      &lt;span class="c1"&gt;# No -var-file and no -auto-approve: a saved plan takes no further planning options, and&lt;/span&gt;
      &lt;span class="c1"&gt;# passing the file is the approval.&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Apply&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform apply -input=false -lock-timeout=5m tfplan&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The trimmed step is a &lt;code&gt;github-script&lt;/code&gt; block that posts the plan as a PR comment and updates that comment on every push instead of stacking new ones. Four smaller choices in the file get a line each. &lt;code&gt;id-token: write&lt;/code&gt; sits on each job and never at workflow level, because at workflow level every job in the file holds a token exchangeable for Azure credentials, including the ones that only run a linter. &lt;code&gt;azure/login&lt;/code&gt; is absent because the azurerm provider performs the OIDC exchange itself. The apply job passes a saved plan with no &lt;code&gt;-var-file&lt;/code&gt; and no &lt;code&gt;-auto-approve&lt;/code&gt;, since a saved plan accepts no further planning options and handing it over is the approval. And &lt;code&gt;terraform validate&lt;/code&gt; needs no Azure credentials at all, because &lt;code&gt;subscription_id&lt;/code&gt; is required for plan and apply and not for validate.&lt;/p&gt;

&lt;p&gt;Everything that actually breaks in this file breaks on one string. The federated credential matches the &lt;code&gt;sub&lt;/code&gt; claim on the token GitHub mints, and that claim changes shape per trigger:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;repo:OWNER/REPO:pull_request
repo:OWNER/REPO:ref:refs/heads/main
repo:OWNER/REPO:environment:prod
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three subjects, so three federated credentials on the identity. The precedence rule is what makes this a trap rather than an inconvenience: GitHub uses the environment name whenever the job references an environment, &lt;code&gt;pull_request&lt;/code&gt; only if the job references no environment and the trigger was a pull request, and the branch only when neither applies (&lt;a href="https://docs.github.com/en/actions/reference/security/oidc#example-subject-claims" rel="noopener noreferrer"&gt;subject claim examples&lt;/a&gt;). Add &lt;code&gt;environment: prod&lt;/code&gt; to the plan job so it can read a secret and you have silently rewritten that job's own subject, its credential stops matching, and the &lt;code&gt;AADSTS700213&lt;/code&gt;-class error you get back says nothing about environments.&lt;/p&gt;

&lt;p&gt;The segment key is singular &lt;code&gt;ref:&lt;/code&gt;. HashiCorp's own azurerm OIDC guide prints &lt;code&gt;refs:refs/heads/main&lt;/code&gt;; GitHub mints the token, GitHub uses &lt;code&gt;ref:&lt;/code&gt;, and the plural form is a typo that will cost you an afternoon because the failure looks like a trust configuration problem rather than a spelling one.&lt;/p&gt;

&lt;p&gt;Then there is the change that made every older tutorial wrong. "Repositories created after July 15, 2026 now use an immutable default subject format that includes both the owner ID and repository ID" (&lt;a href="https://docs.github.com/en/actions/reference/security/oidc#immutable-subject-claims" rel="noopener noreferrer"&gt;immutable subject claims&lt;/a&gt;), which looks like &lt;code&gt;repo:OWNER@OWNER-ID/REPO@REPO-ID:ref:refs/heads/BRANCH&lt;/code&gt;. Repos created before that date keep the old format until they opt in, and a rename or a transfer after it flips them. The IDs cannot be stripped back out with &lt;code&gt;include_claim_keys&lt;/code&gt;. Copy a subject string out of any pre-2026 blog post, including a good one, and it will not match on a new repository. Read the real &lt;code&gt;sub&lt;/code&gt; off a token, or build the string from the owner and repo IDs the API gives you. There is a ceiling on that string, too: an application or user-assigned identity accepts a maximum of 20 federated identity credentials and wildcards are not supported, so one credential per subject is a budget rather than a pattern.&lt;/p&gt;

&lt;h3&gt;
  
  
  Drift detection that is still believed in week three
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;schedule&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;cron&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;17&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;6&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;*&lt;/span&gt;&lt;span class="nv"&gt; &lt;/span&gt;&lt;span class="s"&gt;1-5"&lt;/span&gt;
  &lt;span class="na"&gt;workflow_dispatch&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;

&lt;span class="na"&gt;jobs&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;drift&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;runs-on&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;ubuntu-latest&lt;/span&gt;
    &lt;span class="c1"&gt;# If the prod environment has required reviewers, this scheduled run sits waiting for&lt;/span&gt;
    &lt;span class="c1"&gt;# approval. Give drift its own read-scoped environment with no reviewers when that happens.&lt;/span&gt;
    &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;prod&lt;/span&gt;
    &lt;span class="na"&gt;permissions&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;contents&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;read&lt;/span&gt;
      &lt;span class="na"&gt;id-token&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
      &lt;span class="na"&gt;issues&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;write&lt;/span&gt;
    &lt;span class="na"&gt;steps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="c1"&gt;# -detailed-exitcode is what makes this possible: 0 no changes, 1 error, 2 changes.&lt;/span&gt;
      &lt;span class="c1"&gt;# Without it a plan with changes and a plan without both exit 0.&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Plan with detailed exit code&lt;/span&gt;
        &lt;span class="na"&gt;id&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;plan&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;TF_VAR_orders_api_key&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.ORDERS_API_KEY }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;terraform plan -input=false -no-color -lock-timeout=5m -detailed-exitcode -var-file=envs/prod.tfvars&lt;/span&gt;
        &lt;span class="na"&gt;continue-on-error&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;

      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Fail the job on a real error&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;steps.plan.outputs.exitcode == '1'&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;exit &lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt;

      &lt;span class="c1"&gt;# A detector that only opens issues trains everyone to ignore it within two weeks.&lt;/span&gt;
      &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Close the drift issue when clean&lt;/span&gt;
        &lt;span class="na"&gt;if&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;steps.plan.outputs.exitcode == '0'&lt;/span&gt;
        &lt;span class="na"&gt;env&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;GH_TOKEN&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;${{ secrets.GITHUB_TOKEN }}&lt;/span&gt;
        &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
          &lt;span class="s"&gt;gh issue list --state open --label drift --json number --jq '.[].number' \&lt;/span&gt;
            &lt;span class="s"&gt;| xargs -r -I{} gh issue close {} --comment "Plan is clean again."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The checkout, setup and init steps are the same three as the plan job, and the step that opens or comments on the issue on exit code 2 is in the companion repo. &lt;code&gt;continue-on-error: true&lt;/code&gt; on the plan step is not optional: exit code 2 is a success for our purposes and a failure as far as Actions is concerned, so without it the step fails, every conditional after it is skipped, and you get a red run that tells you nothing about whether prod drifted.&lt;/p&gt;

&lt;p&gt;The step most drift workflows are missing is the last one. Opening an issue when the plan is dirty is the easy half; closing it when the plan comes back clean keeps anyone reading the issues in week three. A detector that only ever adds to a pile teaches the team to filter the label, and after that it is a scheduled job that costs money and detects nothing.&lt;/p&gt;

&lt;p&gt;Whether this ever runs comes down to scheduling rules the docs bury. Scheduled workflows only ever run from the default branch, so you cannot test a schedule change on a branch and &lt;code&gt;workflow_dispatch&lt;/code&gt; is how you try it. GitHub delays scheduled runs during high load at the top of the hour, hence &lt;code&gt;17&lt;/code&gt; rather than &lt;code&gt;0&lt;/code&gt;. And a public repository has its scheduled workflows disabled after 60 days without activity, which lands exactly when drift has had time to accumulate and nobody is watching. The &lt;code&gt;environment: prod&lt;/code&gt; on this job exists to match the third federated credential, and it brings the approval gate with it: if that environment has required reviewers, the scheduled run sits waiting for a human who is not expecting to approve anything. Give drift a read-scoped environment of its own with its own credential.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;A grant before a pull. An NSG before an environment. A zone link before a lookup. A data-plane role before a read. None of those four are things your configuration has any reason to reference, which is why &lt;code&gt;depends_on&lt;/code&gt; and a handful of &lt;code&gt;precondition&lt;/code&gt; blocks are where you write them down, and why every silent failure in this article is the same failure.&lt;/p&gt;

&lt;p&gt;The full tree is in the &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/TerraformContainerAppsDemo" rel="noopener noreferrer"&gt;companion repo&lt;/a&gt;, including the two workflow files and the steps trimmed out of the samples above. It validates and &lt;code&gt;fmt&lt;/code&gt;s clean on Terraform 1.16.3 with azurerm 5.6.0, and it deploys nothing on its own.&lt;/p&gt;

&lt;p&gt;One question, and it splits teams cleanly: does your Terraform run &lt;code&gt;plan&lt;/code&gt; on every pull request, or only after the merge?&lt;/p&gt;

</description>
      <category>azure</category>
      <category>terraform</category>
      <category>infrastructureascode</category>
      <category>containerapps</category>
    </item>
    <item>
      <title>Azure Front Door, API Management and Container Apps: What Each Hop Trusts</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 18 Sep 2026 09:29:39 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik</link>
      <guid>https://dev.to/martin_oehlert/azure-front-door-api-management-and-container-apps-what-each-hop-trusts-38ik</guid>
      <description>&lt;p&gt;You can put Front Door, API Management and an internal Container Apps environment in front of &lt;code&gt;orders-api&lt;/code&gt; and still ship an app that takes a token from any workload in your tenant. Container Apps authentication checks that API Management's &lt;strong&gt;managed identity&lt;/strong&gt; token came from your tenant, and checks nothing else, so a workload with any identity calls the app directly and names whichever end user it likes. Entra closes that with one setting. The four hops in front of the app each run on a different answer to the same question, and only two of those answers are a credential.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj4lfk2o3r93o5pjmka1i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fj4lfk2o3r93o5pjmka1i.png" alt="Network topology: Front Door Premium, API Management Standard v2 with a private endpoint and VNet integration, an internal Container Apps environment, and the four hops between them" width="800" height="482"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Front Door takes TLS, the WAF and a per-client rate limit off the gateway's hands, which leaves API Management deciding who may call and Container Apps running the code. The scenario is the order API from &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1"&gt;Part 5&lt;/a&gt;, with the Function App gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The shape you land on, and the tiers it forces
&lt;/h2&gt;

&lt;p&gt;Each tier below is the cheapest one with a feature the topology cannot do without.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Front Door Premium.&lt;/strong&gt; On Standard, "only custom rules are supported": the managed Default Rule Set and Bot Manager are &lt;a href="https://learn.microsoft.com/azure/web-application-firewall/afds/afds-overview" rel="noopener noreferrer"&gt;Premium&lt;/a&gt;, and so are &lt;a href="https://learn.microsoft.com/azure/frontdoor/origin-security" rel="noopener noreferrer"&gt;Private Link origins&lt;/a&gt;. Either reason alone settles it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;API Management Standard v2.&lt;/strong&gt; The gateway has to accept Front Door's traffic privately and send its own traffic into the VNet that holds the Container Apps environment. Those are separate networking features, and the &lt;a href="https://learn.microsoft.com/azure/api-management/virtual-network-concepts" rel="noopener noreferrer"&gt;tier table&lt;/a&gt; decides which instances get both:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flls2v00zgxbhy7eag5je.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Flls2v00zgxbhy7eag5je.png" alt="API Management networking models by tier: classic VNet injection, Premium v2 injection, v2 VNet integration, and inbound private endpoints" width="800" height="259"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Two constraints choose for you, and both bite late. Classic Premium looks like the enterprise answer and is the tier that blocks you: "In the classic API Management tiers, private endpoints aren't supported in instances injected in an internal or external virtual network." For the v2 tiers Microsoft's &lt;a href="https://learn.microsoft.com/azure/api-management/private-endpoint" rel="noopener noreferrer"&gt;private endpoint guide&lt;/a&gt; says to "combine inbound private endpoints to Standard v2 instances with outbound virtual network integration to provide end-to-end network isolation", which leaves Standard v2 as the lowest tier that does both.&lt;/p&gt;

&lt;p&gt;The other is an ordering rule, and it breaks pipelines. Integration on its own leaves the gateway and developer portal endpoints &lt;a href="https://learn.microsoft.com/azure/api-management/integrate-vnet-outbound" rel="noopener noreferrer"&gt;publicly reachable&lt;/a&gt;, so you switch public network access off once the private endpoint exists. You can only do that &lt;a href="https://learn.microsoft.com/azure/api-management/private-endpoint#optionally-disable-public-network-access" rel="noopener noreferrer"&gt;on an instance that already exists&lt;/a&gt;, never in the deployment that creates it, which means the gateway is public for as long as it takes you to run the second deployment. Give it an integration subnet of its own: at least /27, delegated to &lt;code&gt;Microsoft.Web/serverFarms&lt;/code&gt;, with a network security group attached.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Container Apps: a workload profiles environment, internal, in your own VNet.&lt;/strong&gt; You pick accessibility once, when you create the environment, and an internal one has &lt;a href="https://learn.microsoft.com/azure/container-apps/ingress-overview#external-and-internal-ingress" rel="noopener noreferrer"&gt;no public endpoint&lt;/a&gt;. The subnet is fixed at creation too, and you &lt;a href="https://learn.microsoft.com/azure/container-apps/custom-virtual-networks" rel="noopener noreferrer"&gt;cannot resize it afterwards&lt;/a&gt;: /27 minimum, delegated to &lt;code&gt;Microsoft.App/environments&lt;/code&gt;. Size it for the most revisions you expect to keep active at once. Single revision mode briefly doubles address use during a revision change, and &lt;code&gt;orders-api&lt;/code&gt; runs in multiple revision mode, where every active revision keeps its own &lt;code&gt;minReplicas&lt;/code&gt; running on the same subnet (one address per 10 replicas on the Consumption profile, one per node on a dedicated one).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Service Bus Premium.&lt;/strong&gt; Service Bus private endpoints are &lt;a href="https://learn.microsoft.com/azure/service-bus-messaging/private-link-service" rel="noopener noreferrer"&gt;a Premium feature&lt;/a&gt;, and the data hop at the end of this article runs over them.&lt;/p&gt;

&lt;h2&gt;
  
  
  Front Door: what the edge actually does for you
&lt;/h2&gt;

&lt;h3&gt;
  
  
  WAF on a JSON API
&lt;/h3&gt;

&lt;p&gt;The WAF policy is a separate resource from the profile, and a security policy attaches it to the custom domain:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource wafPolicy 'Microsoft.Network/FrontDoorWebApplicationFirewallPolicies@2025-03-01' = {
  name: 'wafOrdersApi'
  location: 'global'
  sku: { name: 'Premium_AzureFrontDoor' }   // defaults to Classic_AzureFrontDoor when omitted
  properties: {
    policySettings: {
      enabledState: 'Enabled'
      mode: 'Detection'
    }
    managedRules: {
      managedRuleSets: [
        {
          ruleSetType: 'Microsoft_DefaultRuleSet'
          ruleSetVersion: '2.2'
          ruleSetAction: 'Block'
        }
      ]
    }
    customRules: {
      rules: [
        {
          name: 'ApiPerClientRateLimit'
          priority: 10
          enabledState: 'Enabled'
          ruleType: 'RateLimitRule'
          rateLimitDurationInMinutes: 5
          rateLimitThreshold: 3000
          matchConditions: [
            {
              matchVariable: 'RequestUri'
              operator: 'Contains'
              matchValue: [ '/api/' ]
            }
          ]
          action: 'Block'
        }
      ]
    }
  }
}

resource wafAttachment 'Microsoft.Cdn/profiles/securityPolicies@2025-06-01' = {
  parent: frontDoorProfile
  name: 'waf-api-contoso'
  properties: {
    parameters: {
      type: 'WebApplicationFirewall'
      wafPolicy: { id: wafPolicy.id }
      associations: [
        {
          domains: [ { id: apiCustomDomain.id } ]
          patternsToMatch: [ '/*' ]
        }
      ]
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start in &lt;code&gt;mode: 'Detection'&lt;/code&gt; on purpose. DRS 2.x uses &lt;a href="https://learn.microsoft.com/azure/web-application-firewall/afds/waf-front-door-drs" rel="noopener noreferrer"&gt;&lt;strong&gt;anomaly scoring&lt;/strong&gt;&lt;/a&gt;: a request is acted on once its score reaches 5, which one Critical match does on its own, and in Detection mode that action is only a log entry. Microsoft's rollout guidance is detection, then tuning, then prevention, and "the whole process might take several weeks." Do the tuning in Bicep or the CLI: changing the rule set version in the portal "resets all previous customizations".&lt;/p&gt;

&lt;p&gt;Expect &lt;code&gt;Authorization&lt;/code&gt; to be your first &lt;a href="https://learn.microsoft.com/azure/web-application-firewall/afds/waf-front-door-exclusion" rel="noopener noreferrer"&gt;exclusion&lt;/a&gt;, because Entra access tokens in a request header "can contain special characters that trigger a false positive detection". The WAF also &lt;a href="https://learn.microsoft.com/azure/web-application-firewall/afds/waf-faq" rel="noopener noreferrer"&gt;"doesn't support content-encoding"&lt;/a&gt;, so a client that gzips its POST body gets no meaningful body inspection.&lt;/p&gt;

&lt;p&gt;The rate limit rule is narrower than its property names suggest. It counts requests &lt;a href="https://learn.microsoft.com/azure/web-application-firewall/afds/waf-front-door-rate-limit" rel="noopener noreferrer"&gt;"from each socket IP address"&lt;/a&gt; over a fixed window of one or five minutes, and once a client crosses the threshold, "all traffic matching that rate limiting rule is blocked for the remainder of the fixed window." The &lt;code&gt;action&lt;/code&gt; in the rule above is one of only two a rate limit rule accepts, Log or Block. Counters live on individual Front Door servers, so low thresholds leak: below about 200 requests a minute "you might see some requests above the threshold get through". The five-minute window with a larger threshold is the more accurate shape, and you take the number itself from a week of Detection logs.&lt;/p&gt;

&lt;p&gt;Layer 3, 4 and 7 &lt;a href="https://learn.microsoft.com/azure/frontdoor/front-door-ddos" rel="noopener noreferrer"&gt;DDoS protection&lt;/a&gt; arrives with the profile whether you write a WAF policy or not.&lt;/p&gt;

&lt;h3&gt;
  
  
  One origin, and it is the gateway
&lt;/h3&gt;

&lt;p&gt;The origin is API Management: Front Door cannot see apps behind an internal environment, and the per-path routing it did during the migration now happens in the gateway. If you leave API Management out, the Private Link origin is the environment itself, and Part 5 covered why &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1#going-private-takes-the-whole-environment"&gt;that takes every app in it private at once&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource apimOriginGroup 'Microsoft.Cdn/profiles/originGroups@2025-06-01' = {
  parent: frontDoorProfile
  name: 'apim-gateway'
  properties: {
    loadBalancingSettings: {
      sampleSize: 4
      successfulSamplesRequired: 3
    }
    healthProbeSettings: {
      probePath: '/status-0123456789abcdef'
      probeRequestType: 'GET'
      probeProtocol: 'Https'
      probeIntervalInSeconds: 30
    }
  }
}

resource apimOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2025-06-01' = {
  parent: apimOriginGroup
  name: 'apim-primary'
  properties: {
    hostName: '${apim.name}.azure-api.net'
    originHostHeader: '${apim.name}.azure-api.net'
    httpsPort: 443
    priority: 1
    weight: 1000
    enforceCertificateNameCheck: true
    sharedPrivateLinkResource: {
      privateLink: { id: apim.id }
      groupId: 'Gateway'
      privateLinkLocation: apim.location
      requestMessage: 'Front Door Premium to the orders gateway'
    }
  }
}

resource apiEndpoint 'Microsoft.Cdn/profiles/afdEndpoints@2025-06-01' = {
  parent: frontDoorProfile
  name: 'orders-api'
  location: 'global'
  properties: { enabledState: 'Enabled' }
}

resource apiRoute 'Microsoft.Cdn/profiles/afdEndpoints/routes@2025-06-01' = {
  parent: apiEndpoint
  name: 'api'
  dependsOn: [ apimOrigin ]
  properties: {
    customDomains: [ { id: apiCustomDomain.id } ]
    originGroup: { id: apimOriginGroup.id }
    patternsToMatch: [ '/api/*' ]
    supportedProtocols: [ 'Https' ]
    forwardingProtocol: 'HttpsOnly'
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Deploying this does not connect anything yet. Front Door creates a private endpoint that shows up as a pending connection on the API Management instance, and traffic flows only after someone &lt;a href="https://learn.microsoft.com/azure/frontdoor/standard-premium/how-to-enable-private-link-apim" rel="noopener noreferrer"&gt;approves it&lt;/a&gt; with &lt;code&gt;az network private-endpoint-connection approve&lt;/code&gt;. Put that step in the pipeline, or the deployment succeeds and serves nothing. A Private Link origin can't share an origin group with public origins, and it has a ceiling worth writing down before you size anything: "each Front Door regional cluster has a limit of 7200 RPS (requests per second) per Front Door profile", and requests past it come back &lt;a href="https://learn.microsoft.com/azure/frontdoor/private-link#frequently-asked-questions" rel="noopener noreferrer"&gt;429&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The route has no &lt;code&gt;cacheConfiguration&lt;/code&gt;, and leaving it out is how you &lt;a href="https://learn.microsoft.com/azure/templates/microsoft.cdn/profiles/afdendpoints/routes" rel="noopener noreferrer"&gt;disable caching&lt;/a&gt; for an API. The managed certificate on &lt;code&gt;apiCustomDomain&lt;/code&gt; has a condition of its own: it renews by itself only if the domain's CNAME &lt;a href="https://learn.microsoft.com/azure/frontdoor/domain" rel="noopener noreferrer"&gt;"points directly to a Front Door endpoint"&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  The probe tests the gateway
&lt;/h3&gt;

&lt;p&gt;You are configuring this probe for a day that has not arrived yet. With one gateway region there is one origin, and a &lt;a href="https://learn.microsoft.com/azure/frontdoor/best-practices#best-practices-for-health-probes" rel="noopener noreferrer"&gt;single-origin group&lt;/a&gt; routes to it whatever the probe reports. The probe starts deciding anything on the day you add a second region, which is also the day you would least like to discover you pointed it at the wrong path.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/status-0123456789abcdef&lt;/code&gt; is the path Microsoft's &lt;a href="https://learn.microsoft.com/azure/api-management/front-door-api-management#configure-azure-front-door" rel="noopener noreferrer"&gt;Front Door and API Management guide&lt;/a&gt; configures. It is &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-gateways-overview#gateway-health-check-endpoint" rel="noopener noreferrer"&gt;built into every managed gateway&lt;/a&gt; outside the Consumption tier and answers 200 when the gateway is up, which is all a probe choosing between gateways needs to know. On a Private Link origin, health probes &lt;a href="https://learn.microsoft.com/azure/frontdoor/private-link#frequently-asked-questions" rel="noopener noreferrer"&gt;take the same network path as traffic&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;An app route would fail as a probe target. The gateway rejects a probe that carries no subscription key or token, and the &lt;code&gt;/health&lt;/code&gt; endpoint from &lt;a href="https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3"&gt;Part 4&lt;/a&gt; is mapped in Development only. When every origin fails, Front Door &lt;a href="https://learn.microsoft.com/azure/frontdoor/health-probes" rel="noopener noreferrer"&gt;"considers all origins unhealthy and routes traffic in a round robin distribution across all of them"&lt;/a&gt;: the probe fails open. App health is decided one layer down anyway, by readiness probes on the container apps and by a circuit breaker on the API Management backend.&lt;/p&gt;

&lt;h2&gt;
  
  
  API Management: the only layer that knows the caller
&lt;/h2&gt;

&lt;p&gt;Front Door knows a socket address and Container Apps knows a token issuer. Only API Management knows which person or partner is calling and on which product, so most of this architecture's configuration lives in its policies.&lt;/p&gt;

&lt;h3&gt;
  
  
  A backend per app, reached through the VNet
&lt;/h3&gt;

&lt;p&gt;There is no backend for "the Container Apps environment". An environment has no single URL: each app has its own FQDN and the environment's proxy routes on the host header. API Management gets one backend entity per app, and the VNet gets a private DNS zone that resolves those names to the environment's internal address:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;param acaDefaultDomain string   // az containerapp env show --query properties.defaultDomain
param acaStaticIp string        // az containerapp env show --query properties.staticIp

resource ordersBackend 'Microsoft.ApiManagement/service/backends@2024-05-01' = {
  parent: apim
  name: 'orders-api'
  properties: {
    url: 'https://orders-api.${acaDefaultDomain}'
    protocol: 'http'
  }
}

resource acaZone 'Microsoft.Network/privateDnsZones@2024-06-01' = {
  name: acaDefaultDomain
  location: 'global'
}

resource acaRecords 'Microsoft.Network/privateDnsZones/A@2024-06-01' = [for recordName in [ '*', '@' ]: {
  parent: acaZone
  name: recordName
  properties: {
    ttl: 3600
    aRecords: [ { ipv4Address: acaStaticIp } ]
  }
}]

resource acaZoneLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2024-06-01' = {
  parent: acaZone
  name: 'vnet-orders'
  location: 'global'
  properties: {
    registrationEnabled: false
    virtualNetwork: { id: vnet.id }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The zone is &lt;a href="https://learn.microsoft.com/azure/container-apps/private-endpoints-with-dns" rel="noopener noreferrer"&gt;named after the environment's default domain&lt;/a&gt;, and it has to be linked to the VNet that API Management integrates with, or the gateway resolves the public name and gets nowhere. Leave the host header alone: &lt;a href="https://learn.microsoft.com/azure/architecture/best-practices/host-name-preservation" rel="noopener noreferrer"&gt;"by default, API Management overrides the host name that's sent to the back end"&lt;/a&gt; with the host of the URL it calls, which is the app FQDN the environment proxy routes on. Reference it from policy with &lt;code&gt;backend-id&lt;/code&gt; rather than &lt;code&gt;base-url&lt;/code&gt;, because Part 5 covered &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1#what-you-do-when-it-goes-wrong"&gt;the trap&lt;/a&gt; in mixing the two across scopes.&lt;/p&gt;

&lt;p&gt;The failure that survives all of this is a 404. Aspire &lt;a href="https://aspire.dev/deployment/azure/container-apps/" rel="noopener noreferrer"&gt;maps an internal endpoint to internal-only ingress&lt;/a&gt;, so &lt;code&gt;azd infra gen&lt;/code&gt; writes &lt;code&gt;ingress.external: false&lt;/code&gt; for every project the AppHost doesn't mark with &lt;code&gt;WithExternalHttpEndpoints()&lt;/code&gt;, and on an internal environment that setting hides the app from the rest of the VNet as well: &lt;a href="https://learn.microsoft.com/azure/container-apps/connect-apps" rel="noopener noreferrer"&gt;the DNS name resolves and the TLS handshake succeeds, but the proxy rejects the request&lt;/a&gt; with a 404. It reads as a routing bug and is a visibility setting. Add &lt;code&gt;WithExternalHttpEndpoints()&lt;/code&gt; to &lt;code&gt;orders-api&lt;/code&gt; in the AppHost; on an internal environment, external ingress still keeps the app off the internet.&lt;/p&gt;

&lt;h3&gt;
  
  
  One inbound policy, in the order it has to run
&lt;/h3&gt;

&lt;p&gt;The policy on the orders API does the rest of this section's work, and the order of the elements is load-bearing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;check-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"X-Azure-FDID"&lt;/span&gt; &lt;span class="na"&gt;failed-check-httpcode=&lt;/span&gt;&lt;span class="s"&gt;"403"&lt;/span&gt;
                  &lt;span class="na"&gt;failed-check-error-message=&lt;/span&gt;&lt;span class="s"&gt;"Invalid request."&lt;/span&gt; &lt;span class="na"&gt;ignore-case=&lt;/span&gt;&lt;span class="s"&gt;"false"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;{{FrontDoorId}}&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/check-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;validate-azure-ad-token&lt;/span&gt; &lt;span class="na"&gt;tenant-id=&lt;/span&gt;&lt;span class="s"&gt;"{{TenantId}}"&lt;/span&gt; &lt;span class="na"&gt;output-token-variable-name=&lt;/span&gt;&lt;span class="s"&gt;"caller"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;audiences&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;audience&amp;gt;&lt;/span&gt;{{OrdersPublicAudience}}&lt;span class="nt"&gt;&amp;lt;/audience&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/audiences&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/validate-azure-ad-token&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;rate-limit-by-key&lt;/span&gt; &lt;span class="na"&gt;calls=&lt;/span&gt;&lt;span class="s"&gt;"120"&lt;/span&gt; &lt;span class="na"&gt;renewal-period=&lt;/span&gt;&lt;span class="s"&gt;"60"&lt;/span&gt;
                       &lt;span class="na"&gt;counter-key=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;orders-"&lt;/span&gt; &lt;span class="err"&gt;+&lt;/span&gt; &lt;span class="err"&gt;((Jwt)context.Variables["caller"]).Subject)"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"X-End-User-Id"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(((Jwt)context.Variables["caller"]).Claims.GetValueOrDefault("oid", ""))&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-api"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"Ocp-Apim-Subscription-Key"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"delete"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;authentication-managed-identity&lt;/span&gt; &lt;span class="na"&gt;resource=&lt;/span&gt;&lt;span class="s"&gt;"{{OrdersApiAppId}}"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;on-error&amp;gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/on-error&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;check-header&lt;/code&gt; goes first&lt;/strong&gt;, so nothing downstream spends a token validation on a request that did not come through your profile. Front Door adds &lt;code&gt;X-Azure-FDID&lt;/code&gt; to every request it forwards, and anyone with portal access can read the value, so it proves only that a request passed through your profile. That still matters, because Front Door's address ranges are shared: &lt;a href="https://learn.microsoft.com/azure/frontdoor/origin-security" rel="noopener noreferrer"&gt;"IP address filtering alone isn't sufficient ... because other Azure customers use the same IP addresses"&lt;/a&gt;, and someone else's profile pointed at your gateway passes an IP filter and fails this check. Keep it once Private Link is in place, as the backstop for the day public network access is switched back on. &lt;a href="https://learn.microsoft.com/azure/api-management/check-header-policy" rel="noopener noreferrer"&gt;&lt;code&gt;ignore-case&lt;/code&gt; is required&lt;/a&gt; on this policy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;validate-azure-ad-token&lt;/code&gt; is the reason the Front Door hop uses Private Link.&lt;/strong&gt; Front Door can authenticate to an origin with a managed identity, but it &lt;a href="https://learn.microsoft.com/azure/frontdoor/origin-authentication-with-managed-identities" rel="noopener noreferrer"&gt;"overwrites an existing &lt;code&gt;Authorization&lt;/code&gt; header with its origin authentication token"&lt;/a&gt;, so the caller's token would never reach this line unless a Front Door rule copied it into a different header first. The feature is still &lt;a href="https://learn.microsoft.com/azure/frontdoor/secure-front-door#identity-and-access-management" rel="noopener noreferrer"&gt;in preview&lt;/a&gt;: its &lt;code&gt;authentication&lt;/code&gt; block exists only in a preview API version of the origin group, which also adds a &lt;code&gt;tokenDestinationHeader&lt;/code&gt; that can move the token out of &lt;code&gt;Authorization&lt;/code&gt;. Neither helps here, because the feature "isn't currently supported for origins with Private Link enabled". &lt;code&gt;output-token-variable-name&lt;/code&gt; keeps the validated token as a &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-policy-expressions" rel="noopener noreferrer"&gt;&lt;code&gt;Jwt&lt;/code&gt; object&lt;/a&gt; for the elements after it.&lt;/p&gt;

&lt;p&gt;Microsoft's &lt;a href="https://learn.microsoft.com/azure/api-management/rate-limit-by-key-policy" rel="noopener noreferrer"&gt;example for &lt;code&gt;rate-limit-by-key&lt;/code&gt;&lt;/a&gt; keys on &lt;code&gt;context.Request.IpAddress&lt;/code&gt;, which is the wrong key here. Behind Front Door, the connection API Management sees comes from Front Door, so an IP key throttles Front Door itself. The policy above keys on the validated subject instead, and the per-client-IP limit stays where it already works, in the WAF. Counters are tracked per gateway ("It doesn't aggregate call data across the entire instance") and shared by every scope that uses the same key, hence the &lt;code&gt;orders-&lt;/code&gt; prefix. v2 tiers count with a token bucket where classic tiers use a sliding window, and Microsoft warns that inconsistent limits on a shared key there "can cause unpredictable behavior", so give every policy that shares a key the same numbers.&lt;/p&gt;

&lt;p&gt;The last element, &lt;code&gt;authentication-managed-identity&lt;/code&gt;, is the reason the two &lt;code&gt;set-header&lt;/code&gt; elements above it are there at all. It requests a token for the &lt;code&gt;orders-api&lt;/code&gt; app registration and writes it into &lt;code&gt;Authorization&lt;/code&gt;, over the top of the caller's own token, so the end user's identity reaches &lt;code&gt;orders-api&lt;/code&gt; only if you copy it out first: here as the &lt;code&gt;oid&lt;/code&gt; claim in &lt;code&gt;X-End-User-Id&lt;/code&gt;, with &lt;code&gt;exists-action="override"&lt;/code&gt; so that a client sending its own &lt;code&gt;X-End-User-Id&lt;/code&gt; gets it replaced rather than trusted. The subscription key goes in the same pass, because by default it is &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" rel="noopener noreferrer"&gt;"passed to the backend and might be exposed in backend monitoring logs"&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The gateway then &lt;a href="https://learn.microsoft.com/azure/api-management/authentication-managed-identity-policy" rel="noopener noreferrer"&gt;caches that token until it expires&lt;/a&gt;, and the element "doesn't validate which backend the token is sent to". Anyone who can write an API policy can point this element at a resource of their choosing and collect the gateway identity's token, so treat policy-edit rights as token rights.&lt;/p&gt;

&lt;h3&gt;
  
  
  Subscription keys, per product
&lt;/h3&gt;

&lt;p&gt;A partner's key is issued against a product that requires a subscription, and the API it contains is the one the policy above is attached to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource ordersHttpApi 'Microsoft.ApiManagement/service/apis@2024-05-01' = {
  parent: apim
  name: 'orders'
  properties: {
    displayName: 'Orders'
    path: 'api/orders'
    protocols: [ 'https' ]
    subscriptionRequired: true
  }
}

resource partnerProduct 'Microsoft.ApiManagement/service/products@2024-05-01' = {
  parent: apim
  name: 'orders-partners'
  properties: {
    displayName: 'Orders for partners'
    subscriptionRequired: true
    state: 'published'
  }
}

resource partnerProductOrders 'Microsoft.ApiManagement/service/products/apis@2024-05-01' = {
  parent: partnerProduct
  name: ordersHttpApi.name
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A subscription key tells you which product a caller bought, and it is a shared secret with no lifecycle: API Management &lt;a href="https://learn.microsoft.com/azure/api-management/api-management-subscriptions" rel="noopener noreferrer"&gt;"doesn't provide built-in features to manage the lifecycle of subscription keys, such as setting expiration dates or automatically rotating keys"&lt;/a&gt;. That is why the policy validates a token as well, and because &lt;code&gt;tenant-id&lt;/code&gt; pins the issuer to your tenant, a partner needs a token your tenant issues: from an app registration you create for them, or from their multitenant app once it is consented into your tenant.&lt;/p&gt;

&lt;p&gt;The same page describes the configuration that quietly disables every key you have issued. "If the key isn't valid but a product exists that includes the API without requiring a subscription (an &lt;strong&gt;open product&lt;/strong&gt;), API Management ignores the key and handles the request as an API request without a subscription key." One open product left over from a demo turns a revoked partner key into anonymous access. Scope is the other trap: requests made with an API-scoped, all-APIs or built-in all-access subscription skip product-scope policies entirely. Keep the checks in the policy above at API scope, and use product scope for what legitimately differs per product, such as &lt;code&gt;rate-limit&lt;/code&gt; and &lt;code&gt;quota&lt;/code&gt;, which only apply when a subscription key is used.&lt;/p&gt;

&lt;h3&gt;
  
  
  Managed identity to Container Apps, and who else gets a token
&lt;/h3&gt;

&lt;p&gt;Every check so far runs in the gateway, which holds up until a caller skips it.&lt;/p&gt;

&lt;p&gt;Container Apps authentication, the &lt;strong&gt;Easy Auth&lt;/strong&gt; sidecar, validates the token that the last policy element attaches, and on its own it accepts far more than the gateway. Microsoft's page for &lt;a href="https://learn.microsoft.com/azure/container-apps/authentication-entra" rel="noopener noreferrer"&gt;this exact flow&lt;/a&gt; says it "allows &lt;em&gt;any&lt;/em&gt; client application in your Microsoft Entra tenant to request an access token and authenticate to the target app." Any workload in your tenant with a managed identity could call &lt;code&gt;orders-api&lt;/code&gt; directly, set &lt;code&gt;X-End-User-Id&lt;/code&gt; to any user's object ID, and look like API Management vouching for that user.&lt;/p&gt;

&lt;p&gt;That is worth a second read, because it inverts the usual reading of this diagram. The hop that gets pointed at when someone calls this architecture secure is the hop where nothing about the caller is checked beyond which tenant it lives in.&lt;/p&gt;

&lt;p&gt;Close it in Entra. Define an &lt;strong&gt;app role&lt;/strong&gt;, assign it to the gateway's identity, and set &lt;strong&gt;assignment required&lt;/strong&gt; on the &lt;code&gt;orders-api&lt;/code&gt; service principal. The client credentials documentation says that setting &lt;a href="https://learn.microsoft.com/entra/identity-platform/v2-oauth2-client-creds-grant-flow#get-direct-authorization" rel="noopener noreferrer"&gt;"will block users and applications without assigned roles from being able to get a token for this application"&lt;/a&gt;, so a workload without the role never gets as far as the sidecar:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az ad app update &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--set&lt;/span&gt; api.requestedAccessTokenVersion&lt;span class="o"&gt;=&lt;/span&gt;2
az ad app update &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--app-roles&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="s1"&gt;'[{"allowedMemberTypes":["Application"],"value":"Orders.Gateway","displayName":"Orders gateway","description":"API Management calls orders-api","isEnabled":true}]'&lt;/span&gt;
&lt;span class="nv"&gt;GATEWAY_ROLE_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;az ad app show &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s2"&gt;"appRoles[?value=='Orders.Gateway'].id"&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; tsv&lt;span class="si"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# Role assignments and the assignment requirement live on the service principal, which may not exist yet.&lt;/span&gt;
&lt;span class="nv"&gt;ORDERS_SP_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;az ad sp show &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; tsv 2&amp;gt;/dev/null &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="o"&gt;||&lt;/span&gt; az ad sp create &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="nb"&gt;id&lt;/span&gt; &lt;span class="nt"&gt;-o&lt;/span&gt; tsv&lt;span class="si"&gt;)&lt;/span&gt;
az ad sp update &lt;span class="nt"&gt;--id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_SP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--set&lt;/span&gt; &lt;span class="nv"&gt;appRoleAssignmentRequired&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;

&lt;span class="c"&gt;# The Azure CLI has no command for assigning an app role to a managed identity.&lt;/span&gt;
&lt;span class="nv"&gt;APIM_PRINCIPAL_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;az resource show &lt;span class="nt"&gt;--ids&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$APIM_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="nt"&gt;--query&lt;/span&gt; identity.principalId &lt;span class="nt"&gt;-o&lt;/span&gt; tsv&lt;span class="si"&gt;)&lt;/span&gt;
az rest &lt;span class="nt"&gt;-m&lt;/span&gt; POST &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-u&lt;/span&gt; &lt;span class="s2"&gt;"https://graph.microsoft.com/v1.0/servicePrincipals/&lt;/span&gt;&lt;span class="nv"&gt;$APIM_PRINCIPAL_ID&lt;/span&gt;&lt;span class="s2"&gt;/appRoleAssignments"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-b&lt;/span&gt; &lt;span class="s2"&gt;"{&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;principalId&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$APIM_PRINCIPAL_ID&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;resourceId&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_SP_ID&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;,&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;appRoleId&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="nv"&gt;$GATEWAY_ROLE_ID&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;}"&lt;/span&gt;

az containerapp auth microsoft update &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; rg-orders &lt;span class="nt"&gt;--name&lt;/span&gt; orders-api &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--client-id&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ORDERS_API_APP_ID&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--issuer&lt;/span&gt; &lt;span class="s2"&gt;"https://login.microsoftonline.com/&lt;/span&gt;&lt;span class="nv"&gt;$TENANT_ID&lt;/span&gt;&lt;span class="s2"&gt;/v2.0"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--yes&lt;/span&gt;
az containerapp auth update &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; rg-orders &lt;span class="nt"&gt;--name&lt;/span&gt; orders-api &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--enabled&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt; &lt;span class="nt"&gt;--unauthenticated-client-action&lt;/span&gt; Return401
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first command exists because of the issuer line. The token version API Management receives is chosen by the &lt;code&gt;orders-api&lt;/code&gt; registration: a &lt;code&gt;requestedAccessTokenVersion&lt;/code&gt; of &lt;a href="https://learn.microsoft.com/entra/identity-platform/access-tokens#token-formats" rel="noopener noreferrer"&gt;&lt;code&gt;null&lt;/code&gt; or &lt;code&gt;1&lt;/code&gt; results in v1.0 tokens&lt;/a&gt;, and the manifest reference is explicit that &lt;a href="https://learn.microsoft.com/entra/identity-platform/reference-app-manifest#requestedaccesstokenversion-attribute" rel="noopener noreferrer"&gt;null is where a registration starts&lt;/a&gt;, since "if the value is null, this parameter defaults to 1, which corresponds to the v1.0 endpoint". A v1.0 token's issuer is &lt;code&gt;https://sts.windows.net/&amp;lt;tenant&amp;gt;/&lt;/code&gt;, which never matches the &lt;code&gt;/v2.0&lt;/code&gt; URL Microsoft tells you to configure. Set the registration to 2 and the two match by construction.&lt;/p&gt;

&lt;p&gt;Assignment required decides who gets a token. Any role on the registration satisfies it, and Easy Auth "doesn't perform the validation steps" for roles, so a role check in code is the second line, for the day someone gives another identity a different role on the same registration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;System.Text.Json&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;GatewayCaller&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;PrincipalClaim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Typ&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Val&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;ClientPrincipal&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;RoleTyp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PrincipalClaim&lt;/span&gt;&lt;span class="p"&gt;[]?&lt;/span&gt; &lt;span class="n"&gt;Claims&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;readonly&lt;/span&gt; &lt;span class="n"&gt;JsonSerializerOptions&lt;/span&gt; &lt;span class="n"&gt;Json&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;PropertyNamingPolicy&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;JsonNamingPolicy&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SnakeCaseLower&lt;/span&gt; &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="nf"&gt;HasRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HttpRequest&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"X-MS-CLIENT-PRINCIPAL"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrEmpty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;JsonSerializer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Deserialize&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;ClientPrincipal&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="n"&gt;Convert&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromBase64String&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;Json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="k"&gt;not&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;Claims&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="n"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;RoleTyp&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;roleType&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;claims&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Any&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Typ&lt;/span&gt; &lt;span class="k"&gt;is&lt;/span&gt; &lt;span class="s"&gt;"roles"&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Typ&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;roleType&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Val&lt;/span&gt; &lt;span class="p"&gt;==&lt;/span&gt; &lt;span class="n"&gt;role&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapGroup&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"/api/orders"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddEndpointFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;next&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
        &lt;span class="n"&gt;GatewayCaller&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;HasRole&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;HttpContext&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"Orders.Gateway"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;next&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Results&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;StatusCode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;StatusCodes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Status403Forbidden&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The identity headers come from the sidecar, and &lt;a href="https://learn.microsoft.com/azure/container-apps/authentication" rel="noopener noreferrer"&gt;"external requests aren't allowed to set these headers"&lt;/a&gt;. The Base64 &lt;code&gt;X-MS-CLIENT-PRINCIPAL&lt;/code&gt; header and its &lt;code&gt;role_typ&lt;/code&gt; field are &lt;a href="https://learn.microsoft.com/azure/app-service/configure-authentication-user-identities" rel="noopener noreferrer"&gt;documented for App Service's Easy Auth&lt;/a&gt;, whose claims "undergo a default claims-mapping process", which is why the filter accepts &lt;code&gt;roles&lt;/code&gt; or whatever &lt;code&gt;role_typ&lt;/code&gt; names. Role changes also arrive late. Managed identity back ends &lt;a href="https://learn.microsoft.com/entra/identity/managed-identities-azure-resources/managed-identity-best-practice-recommendations#limitation-of-using-managed-identities-for-authorization" rel="noopener noreferrer"&gt;cache tokens per resource "for around 24 hours"&lt;/a&gt;, and API Management caches its own until expiry, so a token issued before the assignment can keep arriving without the &lt;code&gt;roles&lt;/code&gt; claim, and the filter answers 403 until it ages out.&lt;/p&gt;

&lt;h2&gt;
  
  
  Container Apps: the layer that decides who gets in and how many answer
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Which ingress settings let the gateway in
&lt;/h3&gt;

&lt;p&gt;Whether API Management can reach &lt;code&gt;orders-api&lt;/code&gt; at all depends on the environment's accessibility, fixed when the environment is created, and on the app's &lt;code&gt;external&lt;/code&gt; flag, which &lt;a href="https://learn.microsoft.com/azure/container-apps/ingress-how-to" rel="noopener noreferrer"&gt;you can change on any deploy&lt;/a&gt; without creating a revision.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkr40kgvwgax8i6xhreqr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fkr40kgvwgax8i6xhreqr.png" alt="Container Apps ingress: environment accessibility against the app's external flag. An internal environment with external: false answers the rest of the VNet with a 404" width="800" height="134"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The bottom-right cell is the Aspire 404 from the backend section, and the bottom-left cell is where &lt;code&gt;orders-api&lt;/code&gt; belongs. &lt;code&gt;inventory-api&lt;/code&gt; sits outside the table, because it has no ingress at all. Other Dapr-enabled apps &lt;a href="https://learn.microsoft.com/azure/container-apps/connect-apps#dapr-service-invocation" rel="noopener noreferrer"&gt;still invoke it through Dapr service invocation&lt;/a&gt;, which is the only way anything in this design calls it.&lt;/p&gt;

&lt;p&gt;This is &lt;code&gt;orders-api&lt;/code&gt; as the rest of the section configures it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;param blueSuffix string
param greenSuffix string = ''
param greenWeight int = 0
param apimIntegrationSubnetPrefix string

var latestSuffix = !empty(greenSuffix) ? greenSuffix : blueSuffix

resource ordersApp 'Microsoft.App/containerApps@2026-01-01' = {
  name: 'orders-api'
  location: location
  identity: { type: 'SystemAssigned' }
  properties: {
    environmentId: acaEnvironment.id
    configuration: {
      activeRevisionsMode: 'Multiple'
      ingress: {
        external: true
        targetPort: 8080
        transport: 'auto'
        ipSecurityRestrictions: [
          {
            name: 'apim-outbound'
            ipAddressRange: apimIntegrationSubnetPrefix
            action: 'Allow'
          }
        ]
        traffic: !empty(blueSuffix) &amp;amp;&amp;amp; !empty(greenSuffix) ? [
          { revisionName: 'orders-api--${blueSuffix}', label: 'blue', weight: 100 - greenWeight }
          { revisionName: 'orders-api--${greenSuffix}', label: 'green', weight: greenWeight }
        ] : [
          { revisionName: 'orders-api--${blueSuffix}', label: 'blue', weight: 100 }
        ]
      }
      dapr: { enabled: true, appId: 'orders-api', appPort: 8080 }
    }
    template: {
      revisionSuffix: latestSuffix
      containers: [
        { name: 'orders-api', image: 'acrorders.azurecr.io/orders-api:${latestSuffix}' }
      ]
      scale: {
        minReplicas: 1
        maxReplicas: 20
        rules: [
          { name: 'http-rate', http: { metadata: { concurrentRequests: '40' } } }
        ]
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The only caller with ingress access is API Management, leaving from its integration subnet, so the allow rule is that subnet's prefix; Front Door's addresses never reach this app. Rules take &lt;a href="https://learn.microsoft.com/azure/container-apps/ip-restrictions" rel="noopener noreferrer"&gt;CIDR ranges only, and all of one type&lt;/a&gt; ("You can't combine allow rules and deny rules"), and they cannot read a header, so the &lt;code&gt;X-Azure-FDID&lt;/code&gt; check stays in the gateway. If a browser client ever appears, CORS goes in API Management's &lt;code&gt;cors&lt;/code&gt; policy as the first inbound element, because during a preflight &lt;a href="https://learn.microsoft.com/azure/api-management/cors-policy" rel="noopener noreferrer"&gt;"only the &lt;code&gt;cors&lt;/code&gt; policy is evaluated on the &lt;code&gt;OPTIONS&lt;/code&gt; request"&lt;/a&gt; and the request never reaches the app.&lt;/p&gt;

&lt;h3&gt;
  
  
  The HTTP rule counts a rate, not concurrency
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;concurrentRequests: '40'&lt;/code&gt; reads as "add a replica when 40 requests are in flight". It means something else. &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app#http" rel="noopener noreferrer"&gt;"Every 15 seconds, the number of concurrent requests is calculated as the number of requests in the past 15 seconds divided by 15"&lt;/a&gt;: requests per second, averaged over a 15-second window, and Microsoft's own example describes its setting as "100 concurrent requests per second". The replica count then follows &lt;code&gt;desiredReplicas = ceil(currentMetricValue / targetMetricValue)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Request duration appears nowhere in that formula, so one number can be wrong in both directions. Take the rule above on paper. An order lookup answering in 25 ms at 400 requests per second holds about 10 requests in flight across the whole app, and the rule asks for ceil(400 / 40) = 10 replicas, each doing one thing at a time. A report export taking 4 seconds at 5 requests per second holds 20 requests open and gets ceil(5 / 40) = 1 replica. The first overspends, the second queues, and the replica chart for both looks like autoscaling working.&lt;/p&gt;

&lt;p&gt;Set the value from throughput. Load one replica until latency starts to climb, note the request rate it sustained, and set &lt;code&gt;concurrentRequests&lt;/code&gt; below that. If an app serves both shapes of request, the rule can be right for one of them only, which is an argument for moving the slow endpoint into its own app. &lt;code&gt;maxReplicas&lt;/code&gt; is the cost ceiling either way: the &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app" rel="noopener noreferrer"&gt;scale limits table&lt;/a&gt; puts its default at 10 with 1,000 configurable, and replicas arrive in a &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app#scale-behavior" rel="noopener noreferrer"&gt;scale up step&lt;/a&gt; of "1, 4, 8, 16, 32, ... up to configured maximum replicas".&lt;/p&gt;

&lt;p&gt;&lt;code&gt;minReplicas: 1&lt;/code&gt; matters more here than it did during the migration. Nothing sends &lt;code&gt;orders-api&lt;/code&gt; traffic on a schedule any more, because Front Door's probe stops at the gateway's status path, so at zero replicas the first call after a quiet spell waits for a replica to start while API Management holds the request open. &lt;code&gt;scale.cooldownPeriod&lt;/code&gt; does not soften that: &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app#custom" rel="noopener noreferrer"&gt;"The cool down period only takes effect when scaling in from the final replica to 0."&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Queue depth for the app nobody calls over HTTP
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;inventory-api&lt;/code&gt; scales on the backlog of the &lt;code&gt;orders&lt;/code&gt; topic instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource inventoryApp 'Microsoft.App/containerApps@2026-01-01' = {
  name: 'inventory-api'
  location: location
  identity: { type: 'SystemAssigned' }
  properties: {
    environmentId: acaEnvironment.id
    configuration: {
      activeRevisionsMode: 'Single'
      dapr: { enabled: true, appId: 'inventory-api', appPort: 8080 }
    }
    template: {
      containers: [
        { name: 'inventory-api', image: 'acrorders.azurecr.io/inventory-api:${releaseSuffix}' }
      ]
      scale: {
        minReplicas: 1
        maxReplicas: 10
        rules: [
          {
            name: 'orders-backlog'
            custom: {
              type: 'azure-servicebus'
              identity: 'system'
              metadata: {
                namespace: serviceBusNamespaceName
                topicName: 'orders'
                subscriptionName: 'inventory-api'
                messageCount: '30'
              }
            }
          }
        ]
      }
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no &lt;code&gt;ingress&lt;/code&gt; block, and &lt;code&gt;activeRevisionsMode: 'Single'&lt;/code&gt; is deliberate: the scale rules page asks for single revision mode &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app" rel="noopener noreferrer"&gt;whenever a scale rule is not an HTTP one&lt;/a&gt;, which is one reason the canary lives on &lt;code&gt;orders-api&lt;/code&gt;. &lt;code&gt;messageCount&lt;/code&gt; is a target per replica, so &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-keda-scaling" rel="noopener noreferrer"&gt;150 waiting messages ask for five replicas&lt;/a&gt;, and &lt;code&gt;subscriptionName&lt;/code&gt; has to name the subscription the Dapr component drains, the &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1#consumerid-is-the-subscription-name-and-it-defaults-to-your-app-id"&gt;pairing Part 5 covered&lt;/a&gt;. Keep &lt;code&gt;namespace&lt;/code&gt; even though that Microsoft sample leaves it out: KEDA's Service Bus scaler &lt;a href="https://keda.sh/docs/latest/scalers/azure-service-bus/" rel="noopener noreferrer"&gt;requires it&lt;/a&gt; when it authenticates with an identity, and no Container Apps page says the platform fills it in.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;identity: 'system'&lt;/code&gt; &lt;a href="https://learn.microsoft.com/azure/container-apps/managed-identity#scale-rules" rel="noopener noreferrer"&gt;authenticates the rule&lt;/a&gt; with the app's own identity. Container Apps documents neither the Service Bus role that identity needs nor whether the scaler reaches a namespace with public access disabled. The nearest answers are both too generous: the AKS guide for KEDA &lt;a href="https://learn.microsoft.com/azure/aks/keda-workload-identity" rel="noopener noreferrer"&gt;assigns Azure Service Bus Data Owner&lt;/a&gt;, and KEDA's own reference wants a Manage policy for a connection string, either of them more than a consumer should hold. That is why &lt;code&gt;minReplicas&lt;/code&gt; is 1: a replica that exists keeps draining the subscription whether or not the scaler can read it, and it is also awake for Dapr invocations from &lt;code&gt;orders-api&lt;/code&gt;, which don't pass through ingress and so can't wake an app from zero.&lt;/p&gt;

&lt;h3&gt;
  
  
  Revisions: the rollout Front Door no longer does
&lt;/h3&gt;

&lt;p&gt;In Part 5, Front Door origin weights moved traffic between two runtimes. With one origin and one gateway, the rollout axis is the app's revisions, two layers below anything Front Door can see.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;traffic&lt;/code&gt; block follows &lt;a href="https://learn.microsoft.com/azure/container-apps/blue-green-deployment?pivots=bicep" rel="noopener noreferrer"&gt;Microsoft's blue-green template&lt;/a&gt;. The first deploy sets only &lt;code&gt;blueSuffix&lt;/code&gt;, and the single entry sends everything to the one revision that deploy creates. The next deploy sets &lt;code&gt;greenSuffix&lt;/code&gt;, creates the green revision and keeps it at &lt;code&gt;greenWeight: 0&lt;/code&gt;. &lt;strong&gt;Weights&lt;/strong&gt; split the requests that arrive on the app's own FQDN, which is the URL API Management's backend calls, so a deploy with &lt;code&gt;greenWeight: 10&lt;/code&gt; is a canary for every caller of the API with no gateway change. &lt;strong&gt;Labels&lt;/strong&gt; give a revision its own address, &lt;code&gt;orders-api---green.&amp;lt;default domain&amp;gt;&lt;/code&gt;, and a &lt;a href="https://learn.microsoft.com/azure/container-apps/revisions" rel="noopener noreferrer"&gt;label keeps its URL when you move it to another revision&lt;/a&gt;. The zone's &lt;code&gt;*&lt;/code&gt; record already resolves that name, but the smoke test still has to come from an address &lt;code&gt;ipSecurityRestrictions&lt;/code&gt; allows: add a test operation in API Management that targets the label address, or add your build agents' subnet to the rule for the duration of the rollout.&lt;/p&gt;

&lt;p&gt;Promotion follows the template too: &lt;code&gt;az containerapp ingress traffic set --label-weight blue=0 green=100&lt;/code&gt;, then a deploy with &lt;code&gt;greenWeight: 100&lt;/code&gt; so the next template run doesn't put the old split back. Rollback is the same with the numbers reversed. Neither creates a revision, because ingress changes &lt;a href="https://learn.microsoft.com/azure/container-apps/ingress-how-to" rel="noopener noreferrer"&gt;apply to every revision at once&lt;/a&gt;. Keeping both revisions active has a price: &lt;code&gt;minReplicas&lt;/code&gt; counts &lt;a href="https://learn.microsoft.com/azure/container-apps/scale-app" rel="noopener noreferrer"&gt;per revision&lt;/a&gt;, so each one holds its own warm replica, and sticky sessions are &lt;a href="https://learn.microsoft.com/azure/container-apps/sticky-sessions" rel="noopener noreferrer"&gt;single revision mode only&lt;/a&gt;, which Part 5 &lt;a href="https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1#caching-and-affinity-change-what-a-cutover-means"&gt;ran into&lt;/a&gt; from the Front Door side.&lt;/p&gt;

&lt;h2&gt;
  
  
  The trust chain, hop by hop
&lt;/h2&gt;

&lt;p&gt;Here are the four hops from the introduction again, with what the receiving side of each one actually relies on:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8mpwbi4769z2ed6x2e84.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F8mpwbi4769z2ed6x2e84.png" alt="The trust chain hop by hop: what each receiver trusts, whether managed identity is involved, and what you have to add" width="800" height="347"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You settled the first two in the gateway section. From Front Door to API Management, trust rests on a network path and an identifier, and neither of those is a credential, which is why &lt;code&gt;check-header&lt;/code&gt; stays in the policy. From API Management to &lt;code&gt;orders-api&lt;/code&gt;, the assignment requirement decides which identities can get a token at all, and your role check confirms that the one which arrived carries the gateway's role.&lt;/p&gt;

&lt;h3&gt;
  
  
  Sidecar to app: the token you no longer set
&lt;/h3&gt;

&lt;p&gt;Container Apps generates &lt;code&gt;APP_API_TOKEN&lt;/code&gt; for you. The platform &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-authentication-token" rel="noopener noreferrer"&gt;injects it into every Dapr-enabled app&lt;/a&gt;, "unique per each app and app revision", and the &lt;a href="https://learn.microsoft.com/azure/container-apps/enable-dapr" rel="noopener noreferrer"&gt;supported &lt;code&gt;dapr&lt;/code&gt; settings&lt;/a&gt; have no field for it or for &lt;code&gt;DAPR_API_TOKEN&lt;/code&gt;. Part 3's &lt;a href="https://dev.to/martin_oehlert/building-your-first-dapr-web-api-service-3p2g#the-token-nobody-checks"&gt;endpoint filter&lt;/a&gt; still does the checking, and its fail-open branch never runs in Azure: the variable is always set when Dapr is enabled. The token "can also change at any time", so never copy it into Key Vault or another app's settings.&lt;/p&gt;

&lt;p&gt;Placement matters with two filters in play. The token filter goes on routes the sidecar calls: &lt;code&gt;inventory-api&lt;/code&gt;'s invoked methods and its pub/sub handler. It never goes on the &lt;code&gt;orders-api&lt;/code&gt; routes API Management calls, because those requests carry no &lt;code&gt;dapr-api-token&lt;/code&gt; and every one of them would get a 401. The &lt;code&gt;GatewayCaller&lt;/code&gt; role check is the mirror image and belongs only on those gateway routes.&lt;/p&gt;

&lt;p&gt;The token proves that a call came through &lt;code&gt;inventory-api&lt;/code&gt;'s own sidecar. It does not say which app sent it. The sidecars &lt;a href="https://learn.microsoft.com/azure/container-apps/connect-apps#dapr-service-invocation" rel="noopener noreferrer"&gt;secure that call with mutual TLS on their own&lt;/a&gt;, but the Dapr access control policies that would restrict which app IDs may invoke &lt;code&gt;inventory-api&lt;/code&gt; live in the Configuration spec, which &lt;a href="https://dev.to/martin_oehlert/introduction-to-dapr-for-azure-developers-1l9h#what-azure-container-apps-gives-you-and-what-it-takes-away"&gt;Container Apps does not support&lt;/a&gt;. Any Dapr-enabled app in the environment can call it, so on this hop the boundary is who is allowed to deploy into the environment.&lt;/p&gt;

&lt;h3&gt;
  
  
  App to data, and the network under all four hops
&lt;/h3&gt;

&lt;p&gt;On the last hop managed identity carries the trust with no secret anywhere, and what you add is plumbing. Both apps reach Service Bus and Cosmos DB with their own identities and data-plane role assignments, wired as in &lt;a href="https://dev.to/martin_oehlert/introduction-to-dapr-for-azure-developers-1l9h#the-auth-chain-that-hides-a-misconfiguration"&gt;Part 2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The VNet in the diagram carries four subnets with one owner each: API Management's inbound private endpoint, its /27 integration subnet, the environment's /27, and &lt;code&gt;snet-pe&lt;/code&gt; for the data services. With public network access disabled on both services, each app resolves them through &lt;a href="https://learn.microsoft.com/azure/private-link/private-endpoint-dns" rel="noopener noreferrer"&gt;private DNS zones&lt;/a&gt;, &lt;code&gt;privatelink.servicebus.windows.net&lt;/code&gt; and &lt;code&gt;privatelink.documents.azure.com&lt;/code&gt;, linked to the same VNet as the environment's own zone. Miss a link and the name &lt;a href="https://learn.microsoft.com/azure/service-bus-messaging/private-link-service#troubleshoot-private-endpoint-connectivity" rel="noopener noreferrer"&gt;resolves to a public IP instead of the private one&lt;/a&gt;, so the failure shows up as a refused or timed-out connection from the app, with no DNS error anywhere.&lt;/p&gt;

&lt;h3&gt;
  
  
  Verify on first deploy
&lt;/h3&gt;

&lt;p&gt;Each item below rests on documentation that describes the pieces separately and never shows them working together, so check it once in your own subscription:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The Front Door origin reports healthy&lt;/strong&gt; once the private endpoint connection is approved.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A managed identity without the app role is refused a token&lt;/strong&gt; for &lt;code&gt;orders-api&lt;/code&gt;. The assignment requirement is documented for applications in general, never for a managed identity.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One decoded &lt;code&gt;X-MS-CLIENT-PRINCIPAL&lt;/code&gt;&lt;/strong&gt; from a real gateway call tells you the claim type the role arrives under.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A call to &lt;code&gt;orders-api&lt;/code&gt; from a VM in another subnet is refused.&lt;/strong&gt; That is the ingress proxy comparing the source address you expect it to compare.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The &lt;code&gt;inventory-api&lt;/code&gt; replica count follows a test backlog&lt;/strong&gt; with public network access disabled on the namespace, which proves the scaler reaches Service Bus with the role you granted.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This architecture gets sold on one line: each layer authenticates to the next with managed identity. On the data hop that line is true. On the hop from API Management to &lt;code&gt;orders-api&lt;/code&gt; it is true only after Entra refuses tokens to identities without the app role, and false every minute before that. The other two hops never claimed it in the first place. Front Door to API Management runs on a network path and an identifier, and sidecar to app runs on a token the platform generates for you.&lt;/p&gt;

&lt;p&gt;It is still a sound design, as long as the checks carrying the trust that managed identity does not carry are actually deployed. The expensive mistake is dropping the header check or the assignment requirement because "it's managed identity". The other price is on the invoice: no public origin means a Premium Front Door profile, a v2 gateway and a Premium namespace, all billed before the first container starts, so price them for your region before the design review rather than after it.&lt;/p&gt;

&lt;p&gt;Part 7 puts this stack into Terraform, where the steps this article ran by hand (the private endpoint approval, the app role, the assignment requirement) have to become code or be forgotten in the next environment.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Have you set &lt;strong&gt;assignment required&lt;/strong&gt; on your API's service principal, or are you relying on the role check in &lt;strong&gt;app code&lt;/strong&gt;?&lt;/p&gt;
&lt;/blockquote&gt;

</description>
      <category>azure</category>
      <category>containerapps</category>
      <category>architecture</category>
      <category>security</category>
    </item>
    <item>
      <title>Azure Functions to Container Apps, One Endpoint at a Time</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 11 Sep 2026 06:06:01 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1</link>
      <guid>https://dev.to/martin_oehlert/azure-functions-to-container-apps-one-endpoint-at-a-time-2e1</guid>
      <description>&lt;p&gt;You have &lt;code&gt;/api/orders/*&lt;/code&gt; running on a Dapr-enabled Container App in staging and &lt;code&gt;/api/reports/*&lt;/code&gt; nowhere near ready, and Azure Front Door will move production traffic for you either way. The two ways are different objects and you cannot get one from the other: a &lt;strong&gt;route&lt;/strong&gt; maps a set of path patterns to exactly one &lt;strong&gt;origin group&lt;/strong&gt;, while a &lt;strong&gt;weight&lt;/strong&gt; splits traffic between origins &lt;em&gt;inside&lt;/em&gt; a single origin group. Take the route and the cutover happens one path at a time, reverting by deleting a pattern. Take the weight and both runtimes have to serve every path on that route, and the ratio you typed does nothing at all until you change a load balancing setting almost nobody mentions. The four phases below are the order those two levers go in, and what each one costs you when it goes wrong.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftggmjyckko6kwplz7j2j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftggmjyckko6kwplz7j2j.png" alt="The four phases and what moves in each" width="712" height="948"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 1: deploy alongside and route nothing
&lt;/h2&gt;

&lt;p&gt;The running scenario for the rest of this article: an order API on &lt;code&gt;api.contoso.com&lt;/code&gt;, fronted by a Front Door Standard profile, with a single route whose patterns are &lt;code&gt;['/*']&lt;/code&gt; pointing at a Function App origin. Everything is on that one route today. &lt;code&gt;/api/orders/*&lt;/code&gt; moves to the Container App first, &lt;code&gt;/api/reports/*&lt;/code&gt; moves last.&lt;/p&gt;

&lt;p&gt;Phase 1 adds two things and changes nothing else. The Container App gets deployed and registered in the Front Door profile as an origin in its own origin group. No route points at that group yet, so it serves zero production requests, and the only claim phase 1 makes is that Front Door can reach it and gets a 200 back from a probe.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;/*&lt;/code&gt; route stays exactly where it is, for the whole migration. It is the &lt;strong&gt;catch-all&lt;/strong&gt;: the fallback for every endpoint you have not moved yet, and the thing that catches a path back when you revert one. Front Door has no implicit default, and a request matching no route errors out with one of two status codes depending on which doc you read, so do not build anything that inspects the code.&lt;/p&gt;

&lt;p&gt;Everything here is Front Door Standard/Premium, resource type &lt;code&gt;Microsoft.Cdn/profiles&lt;/code&gt;. Front Door classic (&lt;code&gt;Microsoft.Network/frontDoors&lt;/code&gt;) &lt;a href="https://learn.microsoft.com/azure/frontdoor/tier-migration" rel="noopener noreferrer"&gt;retires on 2027-03-31&lt;/a&gt;: no new profiles, no new domain onboarding, no new managed certificates. If your existing profile is classic, the migration in front of you is a different one from this article's.&lt;/p&gt;

&lt;p&gt;The ordering decision worth making now is which path goes last, and &lt;code&gt;/api/reports/*&lt;/code&gt; is last here for a reason that is not "reports matter less". Front Door's &lt;a href="https://learn.microsoft.com/azure/frontdoor/how-to-configure-origin#origin-response-timeout" rel="noopener noreferrer"&gt;origin response timeout&lt;/a&gt; is 16 to 240 seconds, and "this timeout value is applied to all endpoints in the Azure Front Door profile". A long-running report path cannot be given a longer timeout than the order path next to it. Whichever endpoint has the widest latency spread sets the number for the whole profile, so you move it when you have the most information.&lt;/p&gt;

&lt;h3&gt;
  
  
  The probe is the first thing that breaks
&lt;/h3&gt;

&lt;p&gt;Front Door's health probe has a rule that reads as a detail and behaves as an outage: &lt;a href="https://learn.microsoft.com/azure/frontdoor/health-probes" rel="noopener noreferrer"&gt;only 200 OK counts as healthy&lt;/a&gt;. Not 204, not 301. Put a Function App whose &lt;code&gt;/healthz&lt;/code&gt; returns 204, which plenty do on purpose, in an origin group next to a container that returns 200, and you have manufactured an outage in the component you added to prevent one.&lt;/p&gt;

&lt;p&gt;The second rule contradicts the first place you would look: the probe path is case sensitive, while route path patterns are case insensitive, to the point that Front Door rejects &lt;code&gt;/FOO&lt;/code&gt; and &lt;code&gt;/foo&lt;/code&gt; as duplicates in the same field.&lt;/p&gt;

&lt;p&gt;The Container Apps side is quieter and worse. With ingress enabled and no probes defined, Container Apps &lt;a href="https://learn.microsoft.com/azure/container-apps/health-probes#default-configuration" rel="noopener noreferrer"&gt;adds defaults&lt;/a&gt; that are TCP checks against the ingress target port, and a TCP probe passes as long as something is bound to it. A process that is listening and broken, whose database connection died on startup or whose configuration failed to bind, passes every default probe it gets: false green, at the exact moment you are looking for evidence that the new runtime works.&lt;/p&gt;

&lt;p&gt;On top of startup, readiness and liveness, a Dapr-enabled app adds a fourth opinion: the sidecar's &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-overview" rel="noopener noreferrer"&gt;own app health probe&lt;/a&gt; (&lt;code&gt;dapr.appHealth&lt;/code&gt;, with its own path, interval, timeout and threshold), which decides whether the sidecar considers your app up. That is a separate question from whether the platform considers the replica up, and from whether Front Door considers the origin healthy.&lt;/p&gt;

&lt;p&gt;Collapse it onto one answer: one HTTP health endpoint returning exactly 200, the same path with the same casing on both origins, and explicit probes replacing the TCP defaults so the container's readiness reflects the check Front Door is making:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;probes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Readiness&lt;/span&gt;
    &lt;span class="na"&gt;httpGet&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;path&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;/healthz&lt;/span&gt;      &lt;span class="c1"&gt;# same string, same casing, as the Front Door probePath&lt;/span&gt;
      &lt;span class="na"&gt;port&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8080&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then have the Function App serve &lt;code&gt;/healthz&lt;/code&gt; at 200 too, before you point a single probe at it, and check which verb you are probing with while you are there. New profiles default to &lt;code&gt;HEAD&lt;/code&gt;, which is the right choice for load, and a &lt;code&gt;MapGet&lt;/code&gt; answers it with 405 while an &lt;code&gt;[HttpTrigger(..., "get")]&lt;/code&gt; answers it with 404. Either add the verb on both origins or set &lt;code&gt;probeRequestType: 'GET'&lt;/code&gt;, because the rule at the top of this aside does not care why the response was not a 200.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 2: send the new endpoints and nothing else
&lt;/h2&gt;

&lt;p&gt;Phase 2 is the first config that carries traffic, and it is two resources: an origin group for the orders path, and a route pointing at it. Everything else in the profile is untouched.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;resource ordersOriginGroup 'Microsoft.Cdn/profiles/originGroups@2021-06-01' = {
  name: 'orders-origin-group'
  parent: frontDoorProfile
  properties: {
    loadBalancingSettings: {
      sampleSize: 4
      successfulSamplesRequired: 3
      // Load-bearing, and it does nothing in phase 2. Leave it at the default 0 and the
      // weights you set in phase 3 are ignored entirely. See "Your 90/10 split is a
      // 100/0 split" below.
      additionalLatencyInMilliseconds: 500
    }
    healthProbeSettings: {
      probePath: '/healthz'          // case sensitive, unlike patternsToMatch
      probeRequestType: 'HEAD'
      probeProtocol: 'Https'
      probeIntervalInSeconds: 30     // set it; the documented default varies by source
    }
  }
}

resource ordersRoute 'Microsoft.Cdn/profiles/afdEndpoints/routes@2021-06-01' = {
  name: 'orders-route'
  parent: frontDoorEndpoint
  dependsOn: [ ordersOrigin ]   // the origin group must not be empty when the route is created
  properties: {
    originGroup: { id: ordersOriginGroup.id }
    supportedProtocols: [ 'Https' ]
    // Both patterns, deliberately. The wildcard rules do not settle whether
    // '/api/orders/*' also matches a bare '/api/orders', and POST /api/orders is the
    // create-order call. Listing both is correct either way and costs nothing.
    patternsToMatch: [ '/api/orders', '/api/orders/*' ]
    forwardingProtocol: 'HttpsOnly'
    linkToDefaultDomain: 'Enabled'
    httpsRedirect: 'Enabled'
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;/*&lt;/code&gt; route from phase 1 is still deployed and still points at the Function App, and nothing about this new route mentions it. That omission is why the strangler fig shape works in Front Door: there is no priority field on a route and declaration order is irrelevant. Front Door "always matches to the most-specific request by evaluating the left-hand side properties: protocol, domain, and path, in that order", with the frontend host matched exactly and the path matched against exact patterns first, wildcard patterns second. &lt;code&gt;/api/orders/12345&lt;/code&gt; hits &lt;code&gt;orders-route&lt;/code&gt; and &lt;code&gt;/api/reports/monthly&lt;/code&gt; falls through to the catch-all, and you did not order anything to make that happen.&lt;/p&gt;

&lt;p&gt;The wildcard syntax has three rules and they are all about the end of the string: &lt;code&gt;*&lt;/code&gt; is valid only as the last character, with nothing after it, preceded by &lt;code&gt;/&lt;/code&gt;. A pattern with no wildcard is an exact match, and so is a pattern ending in &lt;code&gt;/&lt;/code&gt;, which is the one that catches people:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0u0lsulj3k69xknr3gs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc0u0lsulj3k69xknr3gs.png" alt="How Front Door matches a request against route patterns, most specific first" width="800" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The CLI equivalent, if your Front Door is not in Bicep yet:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az afd route create &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--resource-group&lt;/span&gt; rg-orders &lt;span class="nt"&gt;--profile-name&lt;/span&gt; afd-orders &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--endpoint-name&lt;/span&gt; orders-endpoint &lt;span class="nt"&gt;--route-name&lt;/span&gt; orders-route &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--origin-group&lt;/span&gt; orders-origin-group &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--patterns-to-match&lt;/span&gt; &lt;span class="s2"&gt;"[/api/orders,/api/orders/*]"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--supported-protocols&lt;/span&gt; &lt;span class="s2"&gt;"[Https]"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--forwarding-protocol&lt;/span&gt; HttpsOnly &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--https-redirect&lt;/span&gt; Enabled &lt;span class="nt"&gt;--link-to-default-domain&lt;/span&gt; Enabled
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no &lt;code&gt;--cache-configuration&lt;/code&gt; flag on that command, and its absence is the setting: omitting it leaves caching off for the route. A migrating order API wants it off badly enough that phase 3 spends an aside on what happens if you forget.&lt;/p&gt;

&lt;p&gt;Doing this one path at a time has a ceiling, and it is far away: a Standard profile allows 100 routes and 100 origin groups (Premium doubles both), 100 path patterns per route, and a composite limit of 5000 routes per profile counted as domains multiplied by paths. An API with thirty endpoints is not close to any of those.&lt;/p&gt;

&lt;h3&gt;
  
  
  A route is a switch, not a dial
&lt;/h3&gt;

&lt;p&gt;Read the route above as a percentage control and you will misread the whole migration. A route maps its patterns to exactly one origin group and 100% of matching requests go there. There is no weight, ratio or percentage anywhere in a route's properties, and no partial state between "the Function App serves &lt;code&gt;/api/orders&lt;/code&gt;" and "the Container App serves it".&lt;/p&gt;

&lt;p&gt;The percentage lever lives one level down: &lt;strong&gt;origin weights&lt;/strong&gt;, integers from 1 to 1000, on the origins inside a single origin group. That is a different object with different behaviour, and the two do not compose the way most migration write-ups imply. You cannot put 10% of &lt;code&gt;/api/orders/*&lt;/code&gt; on the Container App by editing a route, because what the route selects is the group, not the origin. Which leaves a design fork that decides the rest of your migration:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Two origin groups plus two routes.&lt;/strong&gt; Per-path cutover, no percentage available. You revert by removing a pattern from &lt;code&gt;patternsToMatch&lt;/code&gt;, and the catch-all route re-catches the path. Blast radius is one path pattern.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;One origin group plus two origins.&lt;/strong&gt; Percentage rollout by weight, reverted by disabling the new origin. The cost is that both origins are eligible for every path on that route, so the Function App and the Container App each have to serve the whole pattern set.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Phase 2 is the first shape, deliberately: a path you have never sent a request to is the cheapest thing in the world to move, and the revert is one line of config. Phase 3 is the second shape, where the weights come out and turn out not to work at their defaults.&lt;/p&gt;

&lt;h3&gt;
  
  
  The host header decides which app answers
&lt;/h3&gt;

&lt;p&gt;Both origins need one property that has no obvious symptom when it is missing, because Front Door is documented to fill it in for you: "If you use Azure Resource Manager templates or another method without explicitly setting this field, Front Door sends the incoming host name as the value for the host header." Omit &lt;code&gt;originHostHeader&lt;/code&gt; in Bicep and the Container App receives &lt;code&gt;Host: api.contoso.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;That breaks on both sides, and harder on the new one. App Service and Functions want the host header to match the backend domain unless the custom domain is bound to the app. Container Apps goes further: the environment's ingress proxy routes traffic to the correct app, revision and replica &lt;em&gt;based on host headers&lt;/em&gt;, so a wrong header is not a mismatched certificate, it is the environment being unable to work out which of your apps you meant. Set it explicitly on each origin, and keep both lines next to each other so the asymmetry is obvious in review:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;originHostHeader: 'orders-api.orangeplant-77e5875b.westeurope.azurecontainerapps.io'  // Container App
originHostHeader: 'orders-func.azurewebsites.net'                                     // Function App
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same property decides which app answers a probe, so an unset host header can turn phase 1's green probe into a phase 2 outage without either config changing in between.&lt;/p&gt;

&lt;h2&gt;
  
  
  Both runtimes on one Service Bus topic
&lt;/h2&gt;

&lt;p&gt;Phase 2 moved an HTTP path. The order topic is the first Azure resource both runtimes hold at once, and it is where a migration stops being a routing exercise. Three files decide whether that goes well, and the same string appears in all three.&lt;/p&gt;

&lt;p&gt;The Dapr component on the Container App:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="c1"&gt;# components/orders-pubsub.yaml&lt;/span&gt;
&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dapr.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Component&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;orders-pubsub&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;pubsub.azure.servicebus.topics&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
  &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;namespaceName&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;sb-orders.servicebus.windows.net"&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;azureClientId&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;&amp;lt;user-assigned-identity-client-id&amp;gt;"&lt;/span&gt;
    &lt;span class="c1"&gt;# The line that decides whether this is a cutover or a duplicate.&lt;/span&gt;
    &lt;span class="c1"&gt;# consumerID is the Service Bus SUBSCRIPTION NAME, not a label.&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;consumerID&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;orders-fn"&lt;/span&gt;
    &lt;span class="c1"&gt;# The Function App's bicep already created the topic and the subscription.&lt;/span&gt;
    &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;disableEntityManagement&lt;/span&gt;
      &lt;span class="na"&gt;value&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;true"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Function App, unchanged, still deployed, still consuming:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;ServiceBusTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"orders-fn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ServiceBus"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the scale rule on the Container App, which is the file people forget is part of the same decision:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;scale: {
  minReplicas: 0
  maxReplicas: 10
  rules: [ { name: 'orders-topic', custom: {
    type: 'azure-servicebus'
    identity: 'system'
    metadata: {
      topicName: 'orders'
      subscriptionName: 'orders-fn'   // the same literal as consumerID above
      messageCount: '30'
    }
  } } ]
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;orders-fn&lt;/code&gt; three times, in three different formats, validated by nothing.&lt;/p&gt;

&lt;p&gt;That shared string buys you the second row of a two-row decision, and that decision is the whole coexistence story. A &lt;strong&gt;subscription&lt;/strong&gt; on a Service Bus topic "resembles a virtual queue that receives copies of the messages that are sent to the topic", and every subscription gets &lt;a href="https://learn.microsoft.com/azure/service-bus-messaging/service-bus-queues-topics-subscriptions#topics-and-subscriptions" rel="noopener noreferrer"&gt;its own copy&lt;/a&gt; of every published message. The number of subscriptions is the number of times each order gets processed.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5lnkepjmna9dx46mhf4i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F5lnkepjmna9dx46mhf4i.png" alt="Two Service Bus topic topologies: separate subscriptions process every order twice, one shared subscription makes the runtimes competing consumers" width="800" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The second row is a supported configuration rather than a hack. Subscriptions "support the same patterns described earlier in this section regarding queues: competing consumer, temporal decoupling, load leveling, and load balancing." Dapr already does it to itself: replicas sharing an &lt;code&gt;app-id&lt;/code&gt; get each message delivered to &lt;a href="https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/" rel="noopener noreferrer"&gt;"only one instance of that application"&lt;/a&gt;, so adding the Function widens an existing race rather than starting a new one. Which runtime wins any given race is not something you get to know, so do not write a handler whose correctness depends on which side processed order 41.&lt;/p&gt;

&lt;p&gt;One default changes load rather than behaviour, so nothing will page you about it. Dapr's &lt;code&gt;maxConcurrentHandlers&lt;/code&gt; defaults to &lt;code&gt;0&lt;/code&gt;, meaning unlimited; the Functions host's &lt;code&gt;maxConcurrentCalls&lt;/code&gt; defaults to &lt;code&gt;16&lt;/code&gt;. Point both runtimes at the same downstream database and the new side applies materially more concurrent pressure than the side it replaces, on a number nobody typed.&lt;/p&gt;

&lt;p&gt;Sessions are the one mismatch here that fails loudly, at component init. Session properties belong to the &lt;strong&gt;subscription metadata&lt;/strong&gt; rather than the component metadata (&lt;code&gt;requireSessions&lt;/code&gt;, default &lt;code&gt;false&lt;/code&gt;; &lt;code&gt;maxConcurrentSessions&lt;/code&gt;, default 8), and the Functions equivalent is &lt;code&gt;IsSessionsEnabled&lt;/code&gt;. Point a default Dapr subscriber at a session-enabled subscription the Function has been draining for two years and the component source returns &lt;code&gt;subscription %s already exists but session requirement doesn't match&lt;/code&gt;, with nothing in the portal mentioning sessions. If you enable sessions on the Dapr side, check the concurrency number too: 8 against the Functions host's 2000 is a drop of two and a half orders of magnitude.&lt;/p&gt;

&lt;h3&gt;
  
  
  consumerID is the subscription name, and it defaults to your app ID
&lt;/h3&gt;

&lt;p&gt;The Dapr reference page describes &lt;code&gt;consumerID&lt;/code&gt; as a grouping label. Verbatim: "Consumer ID (consumer tag) organizes one or more consumers into a group. Consumers with the same consumer ID work as one virtual consumer ... If the &lt;code&gt;consumerID&lt;/code&gt; is not provided, the Dapr runtime set it to the Dapr application ID (&lt;code&gt;appID&lt;/code&gt;) value."&lt;/p&gt;

&lt;p&gt;Read that as a label and you will leave it unset. The component source says what the page does not, which is that the value is a name of a real Azure entity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// pubsub/azure/servicebus/topics/servicebus.go&lt;/span&gt;
&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rErr&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetClient&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NewReceiverForSubscription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ConsumerID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;client&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;EnsureSubscription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;subscribeCtx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;metadata&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ConsumerID&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;req&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;ConsumerID&lt;/code&gt; goes straight into &lt;code&gt;NewReceiverForSubscription&lt;/code&gt; and &lt;code&gt;EnsureSubscription&lt;/code&gt; as the subscription argument. The consumer ID &lt;strong&gt;is&lt;/strong&gt; the Service Bus subscription name. That mapping comes from &lt;a href="https://github.com/dapr/components-contrib/blob/main/pubsub/azure/servicebus/topics/servicebus.go" rel="noopener noreferrer"&gt;components-contrib&lt;/a&gt;, not from the reference page, so cite the source if you have to defend it in review.&lt;/p&gt;

&lt;p&gt;Follow the default through the migration and you get a specific outcome. Deploy the Container App with app ID &lt;code&gt;orders-api&lt;/code&gt; and no &lt;code&gt;consumerID&lt;/code&gt;, and Dapr creates a Service Bus subscription literally named &lt;code&gt;orders-api&lt;/code&gt; and consumes from it. Nothing about &lt;code&gt;orders-fn&lt;/code&gt; changes. The Function keeps working perfectly. You are now in the first row of that table: every order processed twice, by two runtimes, with no error raised anywhere, and the only visible symptom is downstream. Duplicate confirmation emails, doubled inventory decrements, two rows where you expected one.&lt;/p&gt;

&lt;p&gt;The second half of the pairing is the scale rule. &lt;code&gt;subscriptionName&lt;/code&gt; in the KEDA &lt;code&gt;azure-servicebus&lt;/code&gt; rule is the entity KEDA polls to decide how many replicas you need. &lt;code&gt;consumerID&lt;/code&gt; is the entity Dapr drains. Both are naming the same kind of thing, so if the two strings differ, KEDA is measuring a backlog that the app it is scaling will never touch. The failure is quiet in the direction that matters: with &lt;code&gt;minReplicas: 0&lt;/code&gt;, KEDA watches a subscription that stays empty, keeps the app at zero replicas, and the subscription that is actually filling up has no consumer at all. Nothing validates the pair, in either resource.&lt;/p&gt;

&lt;p&gt;Entity management is the third thing the component does that a migration does not want it doing. &lt;code&gt;disableEntityManagement&lt;/code&gt; defaults to &lt;code&gt;"false"&lt;/code&gt;, meaning create-if-missing. The source shows what "automatically" costs: the component builds a second, administrative client, and &lt;code&gt;EnsureSubscription&lt;/code&gt; calls &lt;code&gt;EnsureTopic&lt;/code&gt; and then &lt;code&gt;GetSubscription&lt;/code&gt; before deciding whether to create anything. A failed &lt;code&gt;GetSubscription&lt;/code&gt; is an error rather than a shrug:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="n"&gt;res&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;adminClient&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;GetSubscription&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;topic&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="no"&gt;nil&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="no"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;fmt&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Errorf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"could not get subscription %s: %w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;subscription&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;err&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;GetSubscription&lt;/code&gt; is a management-plane call. A Container App whose managed identity holds only &lt;code&gt;Azure Service Bus Data Receiver&lt;/code&gt; has no path to the management plane, so on that reading subscription setup fails at init while the identity holds every right it needs to actually receive messages. The permission that looks correct on a least-privilege review is the one that stops the sidecar from starting. That chain is read off the source rather than watched, so treat the exact failure text as unconfirmed until you have the sidecar log in front of you.&lt;/p&gt;

&lt;p&gt;One related waste of time. Four fields in the component reference (&lt;code&gt;lockDurationInSec&lt;/code&gt;, &lt;code&gt;maxDeliveryCount&lt;/code&gt;, &lt;code&gt;defaultMessageTimeToLiveInSec&lt;/code&gt;, &lt;code&gt;autoDeleteOnIdleInSec&lt;/code&gt;) each carry the qualifier "Used during subscription creation only", and the source confirms there is no update path. In a migration you are always pointing at a subscription that already exists, so all four are inert: setting &lt;code&gt;maxDeliveryCount&lt;/code&gt; in your component YAML changes nothing about how many times a message is delivered. Set it on the Service Bus entity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What to do instead&lt;/strong&gt;, and it is the file at the top of this section. Set &lt;code&gt;consumerID&lt;/code&gt; explicitly to the Function's existing subscription name. Set &lt;code&gt;disableEntityManagement: "true"&lt;/code&gt;. Pre-create the topic and the subscription in the Function App's existing bicep, which already owns them. Make the KEDA &lt;code&gt;subscriptionName&lt;/code&gt; the same literal, and if your infrastructure is in Bicep, make it the same variable so the compiler enforces what neither service does. Then grep for that string before you deploy: it should appear in the component, the trigger attribute, and the scale rule, and nowhere else.&lt;/p&gt;

&lt;h3&gt;
  
  
  The envelope goes one way cleanly and one way silently
&lt;/h3&gt;

&lt;p&gt;Dapr "uses the CloudEvents 1.0 specification as its message format" and wraps outgoing messages &lt;a href="https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-cloudevents/" rel="noopener noreferrer"&gt;automatically&lt;/a&gt;. Publish an order from the Container App and this is what lands on the topic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"topic"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"pubsubname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"orders-pubsub"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"orderId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"order-123"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"customerId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"cust-42"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nl"&gt;"total"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mf"&gt;89.50&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"5929aaac-a5e2-4ca1-859c-edfe73f11565"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"specversion"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"1.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"datacontenttype"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"application/json; charset=utf-8"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"orders-api"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"com.dapr.event.sent"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"time"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2026-09-11T06:23:21Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"traceid"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"traceparent"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"00-113ad9c4e42b27583ae98ba698d54255-e3743e35ff56f219-01"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"tracestate"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your order is in there, one level down, under &lt;code&gt;data&lt;/code&gt;. Going the other way costs nothing: the Function publishes a bare order body with the SDK, and "the subscribing Dapr process still wraps these raw messages in a CloudEvent before delivering them to the subscribing application", so the handler receives an envelope whose &lt;code&gt;data&lt;/code&gt; is the body the Function sent. The direction that breaks is the one you will deploy second, where the Function's existing trigger binds to &lt;code&gt;Order&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;ServiceBusTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"orders-fn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ServiceBus"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;Order&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// order.OrderId    is null&lt;/span&gt;
    &lt;span class="c1"&gt;// order.CustomerId is null&lt;/span&gt;
    &lt;span class="c1"&gt;// order.Total      is 0&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Processing order {OrderId}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CompletedTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The binding deserializes the message body, and the body is now the envelope. &lt;code&gt;topic&lt;/code&gt; and &lt;code&gt;specversion&lt;/code&gt; are not properties of &lt;code&gt;Order&lt;/code&gt;, and &lt;code&gt;OrderId&lt;/code&gt; is not a property of a CloudEvent, so every field lands on its default, with no exception thrown, because the JSON is valid and the type is populated with nothing. The message completes, the delivery count never increments, nothing dead-letters, and &lt;code&gt;DeadletteredMessages&lt;/code&gt; stays flat while every order silently evaporates.&lt;/p&gt;

&lt;p&gt;There is a documented switch that makes the problem go away, and it costs more than it looks. Setting &lt;code&gt;rawPayload: "true"&lt;/code&gt; on publish stops Dapr wrapping the message, but the same page states that disabling CloudEvents &lt;a href="https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-raw/" rel="noopener noreferrer"&gt;"disables support for tracing, event deduplication per messageId, content-type metadata, and any other features built using the CloudEvent schema"&lt;/a&gt;, and the subscribe side is then "always base64 encoded with content type &lt;code&gt;application/octet-stream&lt;/code&gt;". Trading tracing away is a bad deal in a migration whose whole argument is that a single trace spans both sides of it.&lt;/p&gt;

&lt;p&gt;So teach the Function about the envelope rather than teaching Dapr to stop producing it. The shim is a record and one property access:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;sealed&lt;/span&gt; &lt;span class="k"&gt;record&lt;/span&gt; &lt;span class="nc"&gt;CloudEvent&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;JsonPropertyName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"data"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt; &lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;JsonPropertyName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"id"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;JsonPropertyName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;property&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;JsonPropertyName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"traceparent"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="n"&gt;TraceParent&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;Function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;nameof&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;))]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt; &lt;span class="nf"&gt;ProcessOrder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;ServiceBusTrigger&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"orders"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"orders-fn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Connection&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"ServiceBus"&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="n"&gt;CloudEvent&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Order&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Data&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;LogInformation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Processing order {OrderId} from event {EventId}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;message&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;Task&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;CompletedTask&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That keeps tracing, keeps &lt;code&gt;messageId&lt;/code&gt; deduplication, and hands the Function the &lt;code&gt;traceparent&lt;/code&gt; it needs to join the Container App's trace. It also survives the Function App being turned off in phase 4. Reach for &lt;code&gt;rawPayload&lt;/code&gt; only when the Function App is genuinely untouchable, and write down what you gave up.&lt;/p&gt;

&lt;h2&gt;
  
  
  How many requests one call actually makes
&lt;/h2&gt;

&lt;p&gt;Phase 3 is about to put production traffic on the new runtime, so this is the last comfortable moment to count what one request there actually costs. The same &lt;code&gt;orders-api&lt;/code&gt; that now shares that subscription also asks &lt;code&gt;inventory-api&lt;/code&gt; whether an order can be filled, and the call site is one call:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;var&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;PostAsJsonAsync&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"/stock/check"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nf"&gt;StockCheckRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;OrderId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;order&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Lines&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="n"&gt;cancellationToken&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;inventory&lt;/code&gt; is an &lt;code&gt;HttpClient&lt;/code&gt; built by &lt;code&gt;DaprClient.CreateInvokeHttpClient("inventory-api")&lt;/code&gt; with &lt;code&gt;AddStandardResilienceHandler()&lt;/code&gt; on it, which is what the templates put there. That client, the &lt;code&gt;/stock/check&lt;/code&gt; endpoint it calls and the service defaults wrapping both are in &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/DaprAspireDemo" rel="noopener noreferrer"&gt;DaprAspireDemo in azure-functions-samples&lt;/a&gt;, the same projects Part 4 built. Count the HTTP requests &lt;code&gt;inventory-api&lt;/code&gt; receives for that one call while it is having a bad minute:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Layer 1  AddStandardResilienceHandler   1 initial + 3 retries = 4 attempts
Layer 2  Dapr service invocation        1 initial + 3 retries = 4 attempts, per layer-1 attempt
                                                                ------------
         delivered to inventory-api                 4 x 4    =   16

Layer 0  Service Bus redelivery, MaxDeliveryCount 10
         before one message dead-letters           10 x 16   =  160
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Layer 1&lt;/strong&gt; is &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;. &lt;code&gt;AddStandardResilienceHandler()&lt;/code&gt; chains five strategies from outermost to innermost: a rate limiter, a 30 second total timeout, a retry strategy with max retries 3 and exponential backoff with jitter on a 2 second base delay, a circuit breaker, and a 10 second per-attempt timeout. It retries on HTTP 500 and above, 408 and 429, and by default it retries every HTTP method &lt;a href="https://learn.microsoft.com/dotnet/core/resilience/http-resilience" rel="noopener noreferrer"&gt;including POST&lt;/a&gt;. Three retries means four attempts leave your process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer 2&lt;/strong&gt; is the sidecar those four attempts pass through. Dapr's built-in service-invocation retries use a 1 second backoff interval with a threshold of 3, so each attempt becomes four sidecar-to-sidecar requests, on a number nobody wrote down in your repository. The version repeated in write-ups goes one further and is wrong: attach your own Dapr retry policy and you would expect 4 x 4 x 4 = 64, but "a user defined retry policy replaces default retries. Targets rely solely on the applied policy." The number stays 16.&lt;/p&gt;

&lt;p&gt;What makes sixteen a migration number rather than a Dapr number is the message underneath it. &lt;code&gt;orders-api&lt;/code&gt; is woken up by a message on the &lt;code&gt;orders-fn&lt;/code&gt; subscription the Function App still reads, and throwing out of the handler abandons that message for redelivery up to &lt;code&gt;MaxDeliveryCount&lt;/code&gt;, which defaults to 10 and replays the whole fan-out each time. That last multiplication is arithmetic on documented defaults rather than a number anyone publishes, so read it as the shape of the problem. &lt;code&gt;MaxDeliveryCount&lt;/code&gt; belongs to the subscription rather than the consumer. That is why the component field of the same name was inert back in the topic section, and why the count only bites during coexistence: every delivery the Container App burns on a failure is one the Function App does not get. Two runtimes, one budget, sized when only one existed.&lt;/p&gt;

&lt;p&gt;The timing interaction is worse than the multiplication, and it is what turns a slow dependency into an outage. Take &lt;code&gt;inventory-api&lt;/code&gt; degraded to 3 seconds per request, not down, just slow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sidecar budget for ONE layer-1 attempt   4 x 3 s + 3 backoffs x 1 s  = 15 s
layer-1 per-attempt timeout                                          = 10 s
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The outer timeout is shorter than the inner retry budget. Polly cancels every attempt at 10 seconds, waits its backoff, and starts a fresh one, so the sidecar's sequence never runs to the end, and the 30 second total timeout leaves room for roughly three of those attempts. The caller pushes seven or eight real requests into an already-degraded dependency and returns a timeout, having succeeded zero times. The defaults in that chain are documented; the interaction between them is reasoning, not a measured run. The rule: &lt;strong&gt;the outermost timeout must exceed the innermost retry budget&lt;/strong&gt;, or the inner layer never finishes and the outer layer only adds load. Either raise the attempt timeout above &lt;code&gt;(maxRetries + 1) * expected_latency + total_backoff&lt;/code&gt;, or take a layer out.&lt;/p&gt;

&lt;p&gt;The instinct at this point is to port the Function App's retry configuration across. Functions runtime retry policies (&lt;code&gt;[FixedDelayRetry]&lt;/code&gt;, &lt;code&gt;[ExponentialBackoffRetry]&lt;/code&gt;) support four trigger types: Cosmos DB, Event Hubs, Kafka and Timer. &lt;strong&gt;Service Bus is not one of them&lt;/strong&gt;, so a Service Bus trigger's retry behaviour has always come from the broker's delivery count, and &lt;code&gt;clientRetryOptions&lt;/code&gt; in &lt;code&gt;host.json&lt;/code&gt; looks like the answer and is not: those settings "only apply to interactions with the Service Bus service. They don't affect retries of &lt;a href="https://learn.microsoft.com/azure/azure-functions/functions-bindings-error-pages#retries" rel="noopener noreferrer"&gt;function executions&lt;/a&gt;." Where a policy does carry across, on a Timer or Event Hubs trigger you move later, the retry count "is stored in the memory of the instance", so "the maximum retry count is a best effort". Either way a like-for-like port is a category error: "we retry ten times" meant one thing when a broker counted the deliveries, and on a chained in-process pipeline sitting on a sidecar it means 10 x 16.&lt;/p&gt;

&lt;p&gt;The one lever you own everywhere, including on Container Apps, is layer 1:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;httpClientBuilder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddStandardResilienceHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Retry&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;DisableForUnsafeHttpMethods&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;   &lt;span class="c1"&gt;// POST, PATCH, PUT, DELETE, CONNECT&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;DisableFor(params HttpMethod[])&lt;/code&gt; is the targeted form if you want to keep retrying one unsafe method you know is idempotent. The Dapr layer below retries a POST regardless of what you think about idempotency, and the app layer is the only place the multiplication can be stopped.&lt;/p&gt;

&lt;h3&gt;
  
  
  resiliency.yaml is the right answer and it does not reach your deployment
&lt;/h3&gt;

&lt;p&gt;Dapr has a proper answer, and it is one resource. &lt;code&gt;policies&lt;/code&gt; names the strategies, &lt;code&gt;targets&lt;/code&gt; binds them to an app, a component or an actor type, and both blocks are required:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dapr.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Resiliency&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;orders-resiliency&lt;/span&gt;
&lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;scopes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="s"&gt;orders-api&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;policies&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;timeouts&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;inventoryTimeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;5s&lt;/span&gt;
    &lt;span class="na"&gt;retries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;inventoryRetry&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;policy&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;exponential&lt;/span&gt;
        &lt;span class="na"&gt;maxInterval&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;10s&lt;/span&gt;
        &lt;span class="na"&gt;maxRetries&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;
        &lt;span class="na"&gt;matching&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
          &lt;span class="na"&gt;httpStatusCodes&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="s"&gt;429,500-599"&lt;/span&gt;
    &lt;span class="na"&gt;circuitBreakers&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;inventoryBreaker&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;maxRequests&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;
        &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;30s&lt;/span&gt;
        &lt;span class="na"&gt;trip&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;consecutiveFailures &amp;gt; &lt;/span&gt;&lt;span class="m"&gt;5&lt;/span&gt;
  &lt;span class="na"&gt;targets&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
    &lt;span class="na"&gt;apps&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
      &lt;span class="na"&gt;inventory-api&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
        &lt;span class="na"&gt;timeout&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;inventoryTimeout&lt;/span&gt;
        &lt;span class="na"&gt;retry&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;inventoryRetry&lt;/span&gt;
        &lt;span class="na"&gt;circuitBreaker&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;inventoryBreaker&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two caveats before you copy it. The &lt;code&gt;apiVersion&lt;/code&gt; is &lt;code&gt;dapr.io/v1alpha1&lt;/code&gt; and the resource is not on Dapr's &lt;a href="https://docs.dapr.io/operations/support/alpha-beta-apis/" rel="noopener noreferrer"&gt;alpha/beta API maturity page&lt;/a&gt;, so do not plan around it as a stable surface. And "currently, resiliency policies are not supported for service invocation via &lt;a href="https://docs.dapr.io/operations/resiliency/resiliency-overview/" rel="noopener noreferrer"&gt;gRPC&lt;/a&gt;", which, since sidecar-to-sidecar traffic is gRPC whatever the caller speaks, means your app must call its sidecar over HTTP rather than that the wire must be HTTP end to end.&lt;/p&gt;

&lt;p&gt;The larger caveat is that on Azure Container Apps the block above does not apply: the Dapr &lt;code&gt;Resiliency&lt;/code&gt; resource is not exposed there. ACA has two unrelated preview features instead, &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-component-resiliency" rel="noopener noreferrer"&gt;Dapr component resiliency&lt;/a&gt;, which covers &lt;code&gt;outbound&lt;/code&gt; and &lt;code&gt;inbound&lt;/code&gt; hops and has no &lt;code&gt;targets.apps&lt;/code&gt; concept, and &lt;a href="https://learn.microsoft.com/azure/container-apps/service-discovery-resiliency" rel="noopener noreferrer"&gt;service discovery resiliency&lt;/a&gt;, whose documentation states that "you can't apply resiliency policies to requests made by using the Dapr Service Invocation API".&lt;/p&gt;

&lt;p&gt;That closure makes the much-repeated claim "Dapr's built-in retries cannot be disabled" true in a narrower way than it is usually written. The global override is genuinely capped: overrides "are not applied to specific targets", and "you cannot override with lesser values than the provided default value, or completely remove default &lt;a href="https://docs.dapr.io/operations/resiliency/policies/retries/override-default-retries/" rel="noopener noreferrer"&gt;retries&lt;/a&gt;", so &lt;code&gt;maxRetries: 0&lt;/code&gt; under &lt;code&gt;DaprBuiltInServiceRetries&lt;/code&gt; does nothing. A per-target policy replaces the built-in rather than lowering it, and &lt;code&gt;maxRetries: 0&lt;/code&gt; there does take, which a maintainer thread (&lt;a href="https://github.com/dapr/dapr/issues/9625" rel="noopener noreferrer"&gt;dapr/dapr#9625&lt;/a&gt;) documents as the supported workaround. On ACA that per-target route is the one thing you cannot reach: resiliency "is not enabled for Dapr service invocation. And for components it is only enabled if you explicitly create a component resiliency policy" (&lt;a href="https://github.com/microsoft/azure-container-apps/issues/585" rel="noopener noreferrer"&gt;microsoft/azure-container-apps#585&lt;/a&gt;, February 2024).&lt;/p&gt;

&lt;p&gt;So pick one layer to own retries and neuter the others. On Container Apps the choice is made for you: layer 2 is not yours, so layer 1 is where the policy lives.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Own layer 1 deliberately.&lt;/strong&gt; &lt;code&gt;AddStandardResilienceHandler&lt;/code&gt; is per-&lt;code&gt;HttpClient&lt;/code&gt;, so leave it off the client that goes through the sidecar and keep it on the clients that call external HTTP APIs directly. If you keep it on the sidecar client, apply &lt;code&gt;DisableForUnsafeHttpMethods()&lt;/code&gt; and raise &lt;code&gt;AttemptTimeout&lt;/code&gt; above the sidecar's budget so an attempt can complete.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Configure the layer ACA does give you.&lt;/strong&gt; Component resiliency covers the sidecar-to-component and sidecar-to-app hops that pub/sub and state run over:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;   az containerapp &lt;span class="nb"&gt;env &lt;/span&gt;dapr-component resiliency create &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--name&lt;/span&gt; orders-pubsub-resiliency &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--dapr-component-name&lt;/span&gt; orders-pubsub &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--environment&lt;/span&gt; aca-env &lt;span class="nt"&gt;--resource-group&lt;/span&gt; rg-orders &lt;span class="se"&gt;\&lt;/span&gt;
     &lt;span class="nt"&gt;--out-http-retries&lt;/span&gt; 2 &lt;span class="nt"&gt;--out-http-delay&lt;/span&gt; 500 &lt;span class="nt"&gt;--out-http-interval&lt;/span&gt; 5000
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The CLI defaults if you leave those out are 3 retries, a 1000 ms delay and a 10000 ms interval, and &lt;code&gt;responseTimeoutInSeconds&lt;/code&gt; "includes all retries". Applying a policy requires restarting your Dapr applications, so it is a deployment step, not a hot config change.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Turn the message-level multiplier down while both runtimes share a subscription.&lt;/strong&gt; Judgement rather than documentation: &lt;code&gt;MaxDeliveryCount&lt;/code&gt; at 10 was sized for a single consumer whose only retry mechanism was redelivery, and with a pipeline and a sidecar underneath it, a lower count dead-letters faster and costs the shared dependency less.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Write the number down for one endpoint before you cut it over. Sixteen is fine if you decided on sixteen.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 3: one endpoint at a time
&lt;/h2&gt;

&lt;p&gt;Everything still sitting on the &lt;code&gt;/*&lt;/code&gt; route has live clients on it, so phase 3 is a loop rather than a deploy. One path leaves the catch-all per iteration, and every point inside the iteration has to be somewhere you would be willing to stop.&lt;/p&gt;

&lt;p&gt;The two levers stack rather than blend: the route decides which origin group serves a path, and the weights inside that group decide which runtime serves a request. So one path moves in two motions, carved out of the catch-all onto its own route pointing at a group that holds &lt;strong&gt;both&lt;/strong&gt; origins, then reweighted. &lt;code&gt;/api/customers/*&lt;/code&gt; is the one moving here; &lt;code&gt;/api/reports/*&lt;/code&gt; is still last.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Step 1. One origin group for the path, holding both runtimes.
// customersOriginGroup is name: 'customers-origin-group', and its
// loadBalancingSettings and healthProbeSettings are the same block as
// orders-origin-group in phase 2, additionalLatencyInMilliseconds: 500 included.
// That line is the whole reason the weights below do anything: see the aside.

resource customersFunctionOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = {
  name: 'customers-functions'
  parent: customersOriginGroup
  properties: {
    hostName: 'orders-func.azurewebsites.net'
    originHostHeader: 'orders-func.azurewebsites.net'
    httpsPort: 443
    priority: 1          // both origins share a priority, deliberately
    weight: 75
    enabledState: 'Enabled'
  }
}

resource customersContainerOrigin 'Microsoft.Cdn/profiles/originGroups/origins@2021-06-01' = {
  name: 'customers-containerapp'
  parent: customersOriginGroup
  properties: {
    hostName: 'orders-api.orangeplant-77e5875b.westeurope.azurecontainerapps.io'
    originHostHeader: 'orders-api.orangeplant-77e5875b.westeurope.azurecontainerapps.io'
    httpsPort: 443
    priority: 1
    weight: 25
    enabledState: 'Disabled'   // deploy dark; step 3 is the only step that moves traffic
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The route is the phase 2 shape with different values: &lt;code&gt;patternsToMatch: [ '/api/customers', '/api/customers/*' ]&lt;/code&gt;, pointing at &lt;code&gt;customersOriginGroup&lt;/code&gt;. That is the whole configuration, and the order you apply it in is what makes it reversible:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Deploy the group with the new origin disabled.&lt;/strong&gt; The Function App is the only enabled member, so the group behaves exactly like the catch-all did.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Deploy the route.&lt;/strong&gt; The path is carved out of &lt;code&gt;/*&lt;/code&gt; and 100% of it still lands on the Function App. Nothing a client can observe changes, which is why it is worth deploying on its own and leaving alone for a day.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enable the Container App origin&lt;/strong&gt;, at the low ratio you already deployed. First contact between new-runtime code and a production request on this path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shift weight and watch.&lt;/strong&gt; Raise the Container App, lower the Function App, repeat.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Revert by disabling the origin, not by undoing the deployment.&lt;/strong&gt; "If any issues arise with the new origin, disable it to route all traffic back to the old origin", and "when an origin is disabled, both routing and health probes to the origin are also disabled".&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;That is &lt;a href="https://learn.microsoft.com/azure/frontdoor/blue-green-deployment" rel="noopener noreferrer"&gt;Microsoft's own blue/green procedure&lt;/a&gt; with a migration in the middle of it, and Microsoft lists the use case by name under weighted routing: "Application migration to Azure: ... Adjust weights to prefer new origins ... then disable and remove less preferred origins."&lt;/p&gt;

&lt;p&gt;Reversibility is worth costing before you need it, because the five levers are not equally cheap:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyhnv5j93coqadzr2cz2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyhnv5j93coqadzr2cz2.png" alt="Five reversibility levers, what each one reverts by, and the blast radius of pulling it" width="800" height="296"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Every row is config only: no redeploy, no pipeline, and any of them can be done by whoever is holding the pager. What none of them is, is a keystroke with an immediate effect. The first four are control-plane changes to Front Door, and a control-plane change reaches the points of presence on Front Door's schedule rather than yours. The last row is the exception, and it exists only if API Management is already in the path. Measure the delay in your own profile, and write the runbook with a window in it rather than a promise.&lt;/p&gt;

&lt;p&gt;Which path goes next is judgement rather than documentation. Move the paths that are neither cacheable nor session-affine first, because both change behaviour when the origin behind a path changes, and neither is something you want to debug on the same afternoon as a runtime change. That is a second reason &lt;code&gt;/api/reports/*&lt;/code&gt; goes last, on top of the profile-wide timeout argument from phase 1.&lt;/p&gt;

&lt;p&gt;One more weighting mechanism shows up in this phase, and it is not on this axis at all. Container Apps splits traffic between &lt;strong&gt;revisions&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az containerapp ingress traffic &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="nt"&gt;-n&lt;/span&gt; orders-api &lt;span class="nt"&gt;-g&lt;/span&gt; rg-orders &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--revision-weight&lt;/span&gt; orders-api--knowngood&lt;span class="o"&gt;=&lt;/span&gt;80 orders-api--newrevision&lt;span class="o"&gt;=&lt;/span&gt;20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Weights there must total 100, it needs multiple revision mode, and every name in that command is a revision of &lt;code&gt;orders-api&lt;/code&gt;: no argument accepts a Function App. Front Door weights answer "old runtime or new runtime"; revision weights answer "old version or new version of the service that already moved". The trick worth stealing early is a label on a revision carrying weight 0, a stable URL that takes no production traffic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Your 90/10 split is a 100/0 split
&lt;/h3&gt;

&lt;p&gt;Set 75 and 25 on the two origins above, deploy, and watch every single request land on one of them. Nothing fails. The portal shows the weights you typed, on the origins you set them on, in the group the route points at, and the traffic ignores all of it.&lt;/p&gt;

&lt;p&gt;Weights are the last of four filters, and the third one has already discarded an origin by the time weighting runs. Front Door picks an origin in this order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Available.&lt;/strong&gt; Enabled origins that are passing their health probe.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Priority.&lt;/strong&gt; Only origins at the best priority value survive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Latency.&lt;/strong&gt; Only origins within the latency sensitivity range of the fastest one survive.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Weight.&lt;/strong&gt; Round robin across whatever is left, in your ratio.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Stage 3 reads &lt;code&gt;additionalLatencyInMilliseconds&lt;/code&gt; on the origin group, and it defaults to 0. Verbatim, from the &lt;a href="https://learn.microsoft.com/azure/frontdoor/routing-methods" rel="noopener noreferrer"&gt;routing methods page&lt;/a&gt;: "By default, the latency sensitivity property is set to 0 ms. With this setting, requests are always forwarded to the fastest available origins. Weights on the origins only take effect if two origins have the same network latency." Two origins having the same measured network latency is the condition, and a Function App and a Container App do not meet it, ever. Whichever one measures faster from a given point of presence is the only origin still standing after stage 3, and stage 4 round-robins across a set of one. Your 90/10 deploys as 100/0.&lt;/p&gt;

&lt;p&gt;The same pipeline has a second way to do this to you, one stage earlier. If the Function App origin is priority 1 and the Container App origin is priority 2, the Container App gets nothing at all while the Function App is healthy, whatever the weights say. Both origins have to carry the same priority value, which is why the Bicep above sets &lt;code&gt;priority: 1&lt;/code&gt; on both and says so in a comment.&lt;/p&gt;

&lt;p&gt;And the honest caveat for anyone running an internal API at a handful of requests per second: "For customers with very low RPS, due to the distributed nature of Azure Front Door points of presence (POPs) and machines, Azure Front Door can't guarantee that the weights you configure are strictly followed and the load balancing might appear skewed." A clean 90/10 is not something to promise a change board.&lt;/p&gt;

&lt;p&gt;The fix is one property on the origin group, and it is the &lt;a href="https://learn.microsoft.com/azure/frontdoor/blue-green-deployment" rel="noopener noreferrer"&gt;blue/green guide's value&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// before: the default. 90/10 deploys as 100/0.
loadBalancingSettings: {
  sampleSize: 4
  successfulSamplesRequired: 3
  additionalLatencyInMilliseconds: 0
}

// after: both origins stay eligible at stage 3, and 90/10 means 90/10.
loadBalancingSettings: {
  sampleSize: 4
  successfulSamplesRequired: 3
  additionalLatencyInMilliseconds: 500
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Confirming it took effect is two checks, not one, because the property being deployed and the split being live are different claims. Read the value back off the deployed resource:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az afd origin-group show &lt;span class="nt"&gt;-g&lt;/span&gt; rg-orders &lt;span class="nt"&gt;--profile-name&lt;/span&gt; afd-orders &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--origin-group-name&lt;/span&gt; customers-origin-group &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--query&lt;/span&gt; loadBalancingSettings.additionalLatencyInMilliseconds
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then count requests at the two origins over a window and compare the ratio to the one you configured, rather than assuming it. Both apps log their own hostname, and Front Door's probes announce themselves with the &lt;code&gt;Edge Health Probe&lt;/code&gt; user agent, so exclude those before you count or a low-traffic path will look busier on both sides than it is. Expect the ratio to be roughly right rather than exactly right, and treat "roughly 75/25" as the property working and "everything on one origin" as it not working.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching and affinity change what a cutover means
&lt;/h3&gt;

&lt;p&gt;A path you cut over on Tuesday is still answering from the Function App on Friday, and every piece of routing config is correct.&lt;/p&gt;

&lt;p&gt;Only GET requests are cacheable, so &lt;code&gt;POST /api/orders&lt;/code&gt; was never at risk and &lt;code&gt;GET /api/customers/{id}&lt;/code&gt; is, from the moment anyone enables caching on the route. The part that outlives the cutover is what Front Door does when your origin is quiet about it: if the response carries no &lt;code&gt;Cache-Control&lt;/code&gt;, Front Door invents a TTL &lt;a href="https://learn.microsoft.com/azure/frontdoor/front-door-caching" rel="noopener noreferrer"&gt;"between one and three days"&lt;/a&gt; at random. A migration-era endpoint that forgot its cache headers can serve the old runtime's response for days after the origin behind it changed, and none of the five reversibility levers touches it: they all move traffic, not what is already cached.&lt;/p&gt;

&lt;p&gt;Caching also rewrites the request the origin sees: &lt;code&gt;Content-Length&lt;/code&gt;, &lt;code&gt;Transfer-Encoding&lt;/code&gt;, &lt;code&gt;Accept&lt;/code&gt;, &lt;code&gt;Accept-Charset&lt;/code&gt;, &lt;code&gt;Accept-Language&lt;/code&gt; and &lt;code&gt;Vary&lt;/code&gt; are not forwarded, so an API that content-negotiates behaves differently on the same code. And &lt;code&gt;Set-Cookie&lt;/code&gt; is stripped from cacheable responses, which is how caching breaks session affinity without either feature being touched: Front Door's own affinity is not established at all if the origin sends a cacheable response.&lt;/p&gt;

&lt;p&gt;Affinity has a harder constraint underneath it, a dead end rather than a trap. Container Apps sticky sessions (&lt;code&gt;ingress.stickySessions.affinity: "sticky"&lt;/code&gt;) are &lt;a href="https://learn.microsoft.com/azure/container-apps/sticky-sessions" rel="noopener noreferrer"&gt;supported in single revision mode only&lt;/a&gt;, which is exactly what revision traffic splitting cannot run in, so the smoke-test lever from earlier in this phase is not available on an affine path.&lt;/p&gt;

&lt;p&gt;So: leave caching off for &lt;code&gt;/api/*&lt;/code&gt; for the whole migration, which is what omitting &lt;code&gt;--cache-configuration&lt;/code&gt; already did in phase 2, and prove it rather than believe it. Curl a migrated GET and read the &lt;code&gt;X-Cache&lt;/code&gt; header: &lt;code&gt;CONFIG_NOCACHE&lt;/code&gt; is caching being off, &lt;code&gt;TCP_HIT&lt;/code&gt; is a response you are no longer choosing the origin for. Move session-affine paths by path rather than by weight, because a weighted origin group is free to send the second request of a session to the other runtime, and if a path needs sticky sessions, pick between affinity and revision splitting before the cutover window starts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Going private takes the whole environment
&lt;/h3&gt;

&lt;p&gt;The two origin types stop being interchangeable at network lockdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl3m4f035yfszq8avxeiv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fl3m4f035yfszq8avxeiv.png" alt="Private Link and origin lockdown compared across a Function App origin and a Container App origin, where the private endpoint scopes to the whole environment" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The load-bearing row is the target sub-resource. The Container Apps private endpoint attaches to &lt;code&gt;managedEnvironments&lt;/code&gt;, so enabling it takes the entire environment private, every app in it, not the one path you migrated last week: you plan the environment, not the app, and you plan it before the first cutover. The row underneath costs you a pattern you probably already have on the Function App, since the &lt;code&gt;AzureFrontDoor.Backend&lt;/code&gt; service tag paired with an &lt;code&gt;x-azure-fdid&lt;/code&gt; header match has no Container Apps ingress equivalent. Origin lockdown on the new runtime is either Private Link or an &lt;code&gt;X-Azure-FDID&lt;/code&gt; check in your own middleware.&lt;/p&gt;

&lt;h2&gt;
  
  
  What you do when it goes wrong
&lt;/h2&gt;

&lt;p&gt;Two hours after &lt;code&gt;/api/orders/*&lt;/code&gt; starts serving from the Container App, the 5xx rate on it triples. You have two questions and only one of them has a good answer: how fast you can put the traffic back, and what putting it back leaves behind. The second one is the expensive one.&lt;/p&gt;

&lt;p&gt;The fast answer depends on which surface owns the routing. With only Front Door in front of the two runtimes, the levers are the ones phase 3 costed. If API Management sits between Front Door and your backends, which is the steady-state shape Part 6 builds, the fastest lever in the migration is a policy edit, because it takes effect at the gateway rather than at the edge:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;policies&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;inbound&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@(context.Request.Url.Path.StartsWith("&lt;/span&gt;&lt;span class="err"&gt;/api/orders"))"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;choose&amp;gt;&lt;/span&gt;
          &lt;span class="c"&gt;&amp;lt;!-- {{orders-backend}} is a named value: "containerapp" or "functions".
               One edit in the portal or one az apim nv update, no redeploy. --&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;when&lt;/span&gt; &lt;span class="na"&gt;condition=&lt;/span&gt;&lt;span class="s"&gt;"@("&lt;/span&gt;&lt;span class="err"&gt;{{orders-backend}}"&lt;/span&gt; &lt;span class="err"&gt;==&lt;/span&gt; &lt;span class="err"&gt;"containerapp")"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-containerapp"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;otherwise&amp;gt;&lt;/span&gt;
            &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-functions"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
          &lt;span class="nt"&gt;&amp;lt;/otherwise&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/when&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;otherwise&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;set-backend-service&lt;/span&gt; &lt;span class="na"&gt;backend-id=&lt;/span&gt;&lt;span class="s"&gt;"orders-functions"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;/otherwise&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/choose&amp;gt;&lt;/span&gt;
    &lt;span class="c"&gt;&amp;lt;!-- Type is Single or Pool. This is how you prove from logs which runtime
         served request X, rather than inferring it from response latency. --&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;set-header&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"X-Backend-Type"&lt;/span&gt; &lt;span class="na"&gt;exists-action=&lt;/span&gt;&lt;span class="s"&gt;"override"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="nt"&gt;&amp;lt;value&amp;gt;&lt;/span&gt;@(context.Backend?.Type ?? "n/a")&lt;span class="nt"&gt;&amp;lt;/value&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/set-header&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/inbound&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;backend&amp;gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/backend&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;outbound&amp;gt;&amp;lt;base&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/outbound&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/policies&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;context.Backend&lt;/code&gt; exposes &lt;code&gt;Id&lt;/code&gt;, &lt;code&gt;Type&lt;/code&gt; and &lt;code&gt;AzureRegion&lt;/code&gt;, so the &lt;code&gt;X-Backend-Type&lt;/code&gt; header turns "which runtime served this request" from a guess into a field you can group by. During a mixed week that header is the difference between an incident review and an argument.&lt;/p&gt;

&lt;p&gt;There is one way to get that wrong that you will not enjoy at 3am. &lt;code&gt;set-backend-service&lt;/code&gt; takes either &lt;code&gt;base-url&lt;/code&gt; or &lt;code&gt;backend-id&lt;/code&gt;, and the two do not mix across scopes: if a base policy sets the backend with &lt;code&gt;backend-id&lt;/code&gt;, "it can only be overridden with a policy using the &lt;code&gt;backend-id&lt;/code&gt; attribute, not the &lt;code&gt;base-url&lt;/code&gt; attribute." Pick &lt;code&gt;backend-id&lt;/code&gt; everywhere, including the rollback branch.&lt;/p&gt;

&lt;p&gt;And the backend pool is the one place in this migration where a Function App and a Container App can be given real percentages against each other: up to 30 backends with round-robin, weighted or priority-based balancing and per-backend circuit breakers, with no latency-sensitivity setting standing between the weights you typed and the traffic you get. The docs are honest that "because of the distributed nature of the API Management architecture, backend load balancing is approximate", which is a much smaller caveat than the one phase 3 ran into.&lt;/p&gt;

&lt;h3&gt;
  
  
  The runbook is mostly about the writes
&lt;/h3&gt;

&lt;p&gt;Write this before the cutover, one per migrated endpoint, and keep it to six lines:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Route revert.&lt;/strong&gt; The named value edit above, or &lt;code&gt;az afd route update --route-name orders-route --enabled-state Disabled&lt;/code&gt;, with the resource group already filled in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Consumer re-enable.&lt;/strong&gt; The app setting that disabled the Function's &lt;code&gt;orders-fn&lt;/code&gt; trigger (phase 4 names it), and the value to put it back to.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stores the new path wrote to&lt;/strong&gt;, by name: the Dapr state store component, its container, and anything the handler touched directly.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The reconciliation query for each.&lt;/strong&gt; Counts and checksums on both sides rather than a row-by-row diff, written out, tested, and dated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dead-letter disposition.&lt;/strong&gt; Drain, dead-letter or accept, decided now rather than during the incident.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The delivery-count assumption.&lt;/strong&gt; What you believe &lt;code&gt;MaxDeliveryCount&lt;/code&gt; is on &lt;code&gt;orders-fn&lt;/code&gt;, so the person reverting knows what budget they are inheriting.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Lines 1 and 2 take minutes to write. Lines 3 to 5 are why the document exists, because reverting a route is a control-plane change and a control-plane change has no opinion about data. Three things the new path did while it was live survive the revert intact.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;State it committed.&lt;/strong&gt; The write through the sidecar succeeded, and flipping the named value does not un-write it. Dapr does not store your object as your object: it stores an envelope, your document nested under a &lt;code&gt;value&lt;/code&gt; property and the application ID prefixed onto the key. So the old Function path, still reading that container with the Cosmos SDK, finds documents under IDs it never wrote, in a shape it does not deserialize. Do not point both runtimes at one state store during the migration; give each its own and keep them in step through the topic.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Messages it published.&lt;/strong&gt; An order event the Container App put on the &lt;code&gt;orders&lt;/code&gt; topic is in the broker. The HTTP revert does not recall it, and the subscriber will process it minutes after you believe the new path is off. This is the line teams skip, and the one that produces the second incident an hour after the first closed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delivery attempts it burned.&lt;/strong&gt; If the Container App consumed a message from &lt;code&gt;orders-fn&lt;/code&gt; and failed, the count is already incremented broker-side, and "the delivery count is increased when a message is received in PeekLock mode and didn't complete the message before the message lock expired." Re-enable the Function consumer and it inherits a partially spent budget on messages it has never seen. The counter does not reset because you changed your mind.&lt;/p&gt;

&lt;p&gt;Re-enabling is not the mirror image of disabling either. It puts a cold app back on a subscription that accumulated backlog for the duration of the failed experiment, with no way to ask whether it came back healthy, which is the next problem.&lt;/p&gt;

&lt;h3&gt;
  
  
  The health signal is not symmetric
&lt;/h3&gt;

&lt;p&gt;You will want a dashboard with the old runtime on the left and the new one on the right. The left column does not exist.&lt;/p&gt;

&lt;p&gt;App Service Health check is the feature you would use, and for the app most likely to be strangled it is not available: "Health check isn't an option for the Flex Consumption and Consumption plans." Where it does exist, it needs an anonymous HTTP trigger answering on the configured path with a 200, which a queue-triggered Function App does not have, and even then a failure only surfaces once ten consecutive one-minute pings cross the load-balancing threshold.&lt;/p&gt;

&lt;p&gt;The Container App side is the opposite problem: startup, readiness and liveness probes plus the sidecar's own &lt;code&gt;dapr.appHealth&lt;/code&gt;, the four-opinion pile-up from phase 1, with readiness at its default failure threshold of 48 on a 5-second period giving a signal roughly four minutes wide. Four health opinions and a four-minute signal on one side, against nothing and a ten-minute signal on the other.&lt;/p&gt;

&lt;p&gt;Front Door does not close that gap, and for the shape phase 2 built it is documented not to: "If you have only a single origin, Azure Front Door always routes traffic to that origin even if its health probe reports an unhealthy status." Microsoft's guidance is to disable probes when a group has one origin, so every probe in &lt;code&gt;orders-origin-group&lt;/code&gt; is telemetry rather than protection. Probes are not free either: volume is per point of presence, so a freshly cut-over Container App running &lt;code&gt;minReplicas: 0&lt;/code&gt; is kept warm, and billed, by probe traffic alone.&lt;/p&gt;

&lt;p&gt;So build for one side. The rollback trigger is the new runtime's error rate and readiness state, grouped by the &lt;code&gt;X-Backend-Type&lt;/code&gt; header, plus the reconciliation queries from line 4 of the runbook. Do not wait for a comparison that the old runtime cannot participate in.&lt;/p&gt;

&lt;h3&gt;
  
  
  There is no feature flag in API Management
&lt;/h3&gt;

&lt;p&gt;The policy above says &lt;code&gt;{{orders-backend}}&lt;/code&gt; rather than anything that looks like a feature flag, and that is not a stylistic choice. API Management has no feature-flag primitive. What it has is a &lt;strong&gt;named value&lt;/strong&gt; (plain, secret, or a Key Vault reference) read as &lt;code&gt;{{name}}&lt;/code&gt; inside a &lt;code&gt;choose&lt;/code&gt;, and a backend pool with per-backend weights. Everything written as "check the feature flag in your APIM policy" is one of those two with a nicer noun on it.&lt;/p&gt;

&lt;p&gt;If the flag genuinely has to live in Azure App Configuration, price the gateway version before you build it. A bare &lt;code&gt;send-request&lt;/code&gt; per inbound request is a full HTTP round trip in the inbound pipeline before the backend has been chosen, with a &lt;code&gt;timeout&lt;/code&gt; that defaults to &lt;strong&gt;60 seconds&lt;/strong&gt;. Caching the lookup is the only workable shape, and the cache is its own project: &lt;code&gt;cache-store-value&lt;/code&gt; is asynchronous, so every expiry lets a burst through to App Configuration at once; the built-in cache is volatile and per-region, so a flag flip lands region by region; it does not exist at all in the Consumption tier; and &lt;code&gt;cache-lookup-value&lt;/code&gt; "is not supported inside a policy fragment", which closes the obvious refactor.&lt;/p&gt;

&lt;p&gt;Then the number that decides the design. In-app, &lt;code&gt;Microsoft.FeatureManagement&lt;/code&gt; with &lt;code&gt;UseFeatureFlags()&lt;/code&gt; refreshes App Configuration feature flags on a &lt;strong&gt;30-second default interval&lt;/strong&gt;, with no cache to design, no tier requirement and no regional skew.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What to do instead:&lt;/strong&gt; use the named value from the first policy for the routing switch, because it is one edit that applies at the gateway, with no cache in front of it. Reach for the App Configuration lookup only when the rollback genuinely has to beat 30 seconds, and be able to say why it does. One security sentence, because migrations hand out policy-edit rights broadly: anyone holding &lt;code&gt;Microsoft.ApiManagement/service/apis/policies/write&lt;/code&gt; can use &lt;code&gt;authentication-managed-identity&lt;/code&gt; to authenticate as the service identity and take the token with them.&lt;/p&gt;

&lt;h3&gt;
  
  
  The cross-runtime trace is two settings away from existing
&lt;/h3&gt;

&lt;p&gt;The part everyone worries about works. Dapr uses W3C trace context on service invocation and pub/sub: "When a request arrives without a trace ID, Dapr creates a new one. Otherwise, it passes the trace ID along the call chain", and "Dapr always propagates trace spans to an application." The &lt;code&gt;traceparent&lt;/code&gt; in the CloudEvent envelope earlier is that contract, in a message. Dapr's docs then warn that you must carry the context from your app's inbound request onto its outbound calls yourself, with no SDK helpers for it. Do not repeat that warning unchanged to a .NET audience: &lt;code&gt;System.Diagnostics.Activity&lt;/code&gt; plus the &lt;code&gt;HttpClient&lt;/code&gt; diagnostics handler already injects &lt;code&gt;traceparent&lt;/code&gt; from the ambient activity, and W3C TraceContext has been the default ID format since .NET 5.&lt;/p&gt;

&lt;p&gt;What actually breaks, in both directions, breaks by omission. Open Application Insights during a mixed week with nothing configured and the Function App contributes no host telemetry, because the isolated worker emits OpenTelemetry only when &lt;code&gt;host.json&lt;/code&gt; says so, while the sidecar hop between the runtimes is missing because Dapr's documented default sample rate is &lt;strong&gt;0.0001&lt;/strong&gt;, one span in ten thousand. Two islands of application-level logging, with a hole where the interesting hop was.&lt;/p&gt;

&lt;p&gt;The obvious fix is closed on Container Apps. Sampling lives at &lt;code&gt;spec.tracing.samplingRate&lt;/code&gt; in a Dapr &lt;code&gt;Configuration&lt;/code&gt; resource, and the first entry in ACA's list of unsupported Dapr capabilities is "Dapr Configuration spec: Any capabilities that require use of the Dapr configuration spec." Neither doc set says whether ACA's managed sidecar keeps the 0.0001 default or sets its own rate once export is enabled, so turn export on and count spans rather than trusting a number from anywhere, including this article.&lt;/p&gt;

&lt;p&gt;Two settings, one per runtime. On the Function App:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2.0"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"telemetryMode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"OpenTelemetry"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;with &lt;code&gt;APPLICATIONINSIGHTS_CONNECTION_STRING&lt;/code&gt; set alongside it. On the Container Apps environment, the property that replaces the sampling knob you cannot reach:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;properties: {
  daprAIConnectionString: appInsights.properties.ConnectionString
  openTelemetryConfiguration: {
    tracesConfiguration: {
      includeDapr: true                 // exports the sidecar's own spans
      destinations: [ 'appInsights' ]
    }
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After both, one request that enters through the Function App and continues into &lt;code&gt;orders-api&lt;/code&gt; is one &lt;code&gt;operation_Id&lt;/code&gt;, because the W3C to Application Insights mapping is fixed: &lt;code&gt;trace-id&lt;/code&gt; becomes &lt;code&gt;operation_Id&lt;/code&gt; and the span's &lt;code&gt;parent-id&lt;/code&gt; becomes the &lt;code&gt;id&lt;/code&gt; of the request or dependency. The Application Map draws both runtimes and the sidecar hop between them.&lt;/p&gt;

&lt;p&gt;Set &lt;code&gt;telemetryMode&lt;/code&gt; on the Function App, set &lt;code&gt;includeDapr&lt;/code&gt; on the environment, and point both runtimes at the &lt;strong&gt;same&lt;/strong&gt; Application Insights resource. That last one is not a detail. Two workspaces give you a trace that is technically continuous and practically invisible, because Transaction Diagnostics and the Application Map join on data they can both see. A migration whose main argument is that one trace spans both runtimes should be able to show the trace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Phase 4: turning the Function App off
&lt;/h2&gt;

&lt;p&gt;Phase 4 has no new code in it, and the only question it asks is how you know it is safe to stop. &lt;strong&gt;One endpoint is done&lt;/strong&gt; when nothing routes to its Function implementation and nothing triggers it, which is what the end of each pass through phase 3 looks like. &lt;strong&gt;The app is done&lt;/strong&gt; when the last endpoint is done, and that is not the same as the app being gone. Disable, do not delete.&lt;/p&gt;

&lt;p&gt;The route goes first, because it is the only thing here that reverses without touching state. For every path you already moved, the Front Door work finished in phase 3; what is left is the &lt;code&gt;/*&lt;/code&gt; catch-all, still pointing at the Function App origin and still catching everything nobody has looked at in six weeks. Do it in two moves. Set &lt;code&gt;enabledState: 'Disabled'&lt;/code&gt; on the Function App origin, which stops routing and probes together and leaves the route there to re-enable. Then, only after a full business cycle passes without anyone noticing, remove the &lt;code&gt;/*&lt;/code&gt; route. That second move changes what an unrecognised path does, from quietly served by the old runtime to erroring at the edge, which is both the point of it and the reason it goes last.&lt;/p&gt;

&lt;p&gt;The consumer goes next, one function at a time. The message-triggered half of the app has nothing to do with Front Door and has its own switch, &lt;a href="https://learn.microsoft.com/azure/azure-functions/disable-function" rel="noopener noreferrer"&gt;an app setting named after the function&lt;/a&gt;: "You can disable a function in place by creating an app setting in the format &lt;code&gt;AzureWebJobs.&amp;lt;FUNCTION_NAME&amp;gt;.Disabled&lt;/code&gt; set to &lt;code&gt;true&lt;/code&gt;." One function stops and the rest of the app keeps serving.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;az functionapp config appsettings &lt;span class="nb"&gt;set&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--name&lt;/span&gt; orders-func &lt;span class="nt"&gt;--resource-group&lt;/span&gt; rg-orders &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;--settings&lt;/span&gt; AzureWebJobs.ProcessOrder.Disabled&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two caveats travel with that command. The setting is &lt;strong&gt;not honoured for Functions running on Container Apps&lt;/strong&gt;, so if you already moved the Function App into a container this lever does not exist for you. And "changing application settings causes your function app to restart by default across all hosting plans", so disabling one function restarts every other function in the app. Schedule it as a restart, not as a config tweak. Then wait longer than feels reasonable: the grace period for draining in-flight invocations "can extend up to 10 minutes for Consumption plan apps and up to 60 minutes for Flex Consumption and Premium plan apps". Budget an hour on Premium, and check that the Service Bus extension is &lt;a href="https://learn.microsoft.com/azure/azure-functions/event-driven-scaling#scale-in-behaviors" rel="noopener noreferrer"&gt;version 4.2.0 or later&lt;/a&gt; before you rely on the drain rather than after.&lt;/p&gt;

&lt;p&gt;The app itself you stop and keep. Stop it if you want the compute line gone, and leave the code deployed, because reverting this step is &lt;code&gt;AzureWebJobs.ProcessOrder.Disabled&lt;/code&gt; back to &lt;code&gt;false&lt;/code&gt;: the shortest rollback anywhere in this migration, though not a free one, since it costs the same restart and puts a cold Function App back onto whatever backlog built up. Delete the app and that rollback becomes a redeploy from a repository whose pipeline you disabled two weeks ago, at the exact moment you are least interested in fixing a build. Keep it deployed and disabled for one full retention window, long enough that a bug report about an order processed on the old path can still be answered by the app that processed it. The &lt;code&gt;CloudEvent&amp;lt;T&amp;gt;&lt;/code&gt; shim from the topic section stays in that code for the same reason: the Container App goes on publishing envelopes whether or not anything is subscribed.&lt;/p&gt;

&lt;p&gt;One deletion needs planning, and it does not look like it belongs to the Function App at all. The topic and the &lt;code&gt;orders-fn&lt;/code&gt; subscription were pre-created in the Function App's bicep, and the Container App now consumes from them, so deleting that resource group takes away the subscription the migrated app is reading from. Move those two resources into the template that owns the new runtime before you delete anything on the old side, and treat the move as its own change with its own rollback, because a Service Bus subscription that gets deleted and recreated does not bring its messages with it.&lt;/p&gt;

&lt;h3&gt;
  
  
  ActiveMessageCount zero does not mean the old consumer is gone
&lt;/h3&gt;

&lt;p&gt;Disabling the consumer ends in "wait, then confirm", and "confirm" is the step people replace with a metric. The metric they reach for cannot answer the question, twice over.&lt;/p&gt;

&lt;p&gt;The first reason is shape. The Azure Monitor &lt;code&gt;ActiveMessages&lt;/code&gt; metric carries the dimension &lt;code&gt;EntityName&lt;/code&gt; and nothing else, and on a topic the topic-level figure is not a backlog at all: "the active message count on the topic itself is 0, as those messages have been successfully forwarded to the subscription." Per-subscription backlog is &lt;a href="https://learn.microsoft.com/azure/service-bus-messaging/message-counters" rel="noopener noreferrer"&gt;not available from Azure Monitor metrics&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The second survives getting the number right. An active message count counts messages nobody is currently holding, and a message received in &lt;code&gt;PeekLock&lt;/code&gt; and not yet completed is not active, so &lt;code&gt;orders-fn&lt;/code&gt; can read zero while a Function instance is halfway through the last three orders it will ever process. Zero proves the subscription is empty right now, and says nothing about whether anything is still attached to it.&lt;/p&gt;

&lt;p&gt;Take three signals instead, in increasing order of how much they prove:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Function invocation count&lt;/strong&gt; in Application Insights. Necessary, not sufficient: zero invocations is also what a broken trigger looks like, so it tells you when to keep waiting, not when to proceed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Per-subscription &lt;code&gt;CountDetails&lt;/code&gt;, from the administration API rather than from metrics.&lt;/strong&gt; &lt;code&gt;Get-AzServiceBusSubscription ... | Select CountDetails&lt;/code&gt; returns &lt;code&gt;ActiveMessageCount&lt;/code&gt;, &lt;code&gt;DeadLetterMessageCount&lt;/code&gt;, &lt;code&gt;ScheduledMessageCount&lt;/code&gt; and the two transfer counts; in .NET, &lt;code&gt;SubscriptionRuntimeProperties&lt;/code&gt;. Poll it gently, because "the acquisition of the message counters is an expensive operation inside the message broker, and executing it frequently directly and adversely impacts the entity performance".&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;ActiveConnections&lt;/code&gt; on the namespace or entity.&lt;/strong&gt; The receiver's AMQP link disappearing is the closest thing to proof that the old consumer let go. It will not drop to zero, because the Container App holds links of its own, so write down the count while both consumers are attached, or the drop you are waiting for has nothing to be a drop from.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;By path. The route is the lever you reach for first, and the reason is what the revert costs: taking &lt;code&gt;/api/orders/*&lt;/code&gt; back off the Container App means deleting one string from &lt;code&gt;patternsToMatch&lt;/code&gt; and letting the catch-all catch it again, with a blast radius of exactly one path pattern and no arithmetic to get wrong at three in the morning. Weights are the second lever rather than the competing one. They belong inside a single origin group, and they mean nothing until &lt;code&gt;additionalLatencyInMilliseconds&lt;/code&gt; stops handing every request to whichever origin measured fastest. Use them when one path is too large to move in a single piece, and not to avoid making the per-path decision.&lt;/p&gt;

&lt;p&gt;None of that is the hard part. The hard part is that almost nothing in this migration fails loudly: a weight that is ignored, a second subscription that appears under your app ID because you left a field blank, a message that deserializes into an object with every field at its default and nothing thrown. Nothing raises and nothing pages, and all of it looks like working software right up until a customer counts their confirmation emails. Most of the work in the four phases is not moving traffic. It is making those failures audible while you are still watching for them.&lt;/p&gt;

&lt;p&gt;Part 6 takes the same three components (Front Door, API Management, Container Apps) and asks what they look like when they are not a transition: the steady-state architecture, sized and secured for the shape you land on rather than the one you pass through.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>dotnet</category>
      <category>cloudnative</category>
      <category>architecture</category>
    </item>
    <item>
      <title>.NET Aspire: Orchestrating Cloud-Native Apps</title>
      <dc:creator>Martin Oehlert</dc:creator>
      <pubDate>Fri, 04 Sep 2026 05:48:18 +0000</pubDate>
      <link>https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3</link>
      <guid>https://dev.to/martin_oehlert/net-aspire-orchestrating-cloud-native-apps-15f3</guid>
      <description>&lt;p&gt;Part 3 started two services and two sidecars from a Dapr multi-app run file, one &lt;code&gt;dapr run&lt;/code&gt; per app, and that file never leaves your laptop. Aspire replaces it with a C# program that also never leaves your laptop: aspire.dev states that "The AppHost isn't a production runtime. It's a development-time orchestration tool that simplifies the process of running and debugging your application locally." Both artifacts are deleted at the deployment boundary. So the question is what the C# one does in the hours before that boundary that the run file does not. The four projects that answer it are in &lt;a href="https://github.com/MO2k4/azure-functions-samples/tree/main/DaprAspireDemo" rel="noopener noreferrer"&gt;DaprAspireDemo in azure-functions-samples&lt;/a&gt;: an AppHost, a ServiceDefaults library, and the two services, building clean at 0 warnings and 0 errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the AppHost actually owns
&lt;/h2&gt;

&lt;p&gt;The local loop is still one command, and that command is the only line of the developer workflow that changed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dapr run &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="nb"&gt;.&lt;/span&gt;    &lt;span class="c"&gt;# Part 3: one run file, one dapr run per app&lt;/span&gt;
aspire run       &lt;span class="c"&gt;# Part 4: one C# program, the same four processes&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second one came back with four resources in the dashboard, all &lt;code&gt;Running&lt;/code&gt;. Two are the services, listed against their &lt;code&gt;.csproj&lt;/code&gt;. The other two are &lt;code&gt;order-service-dapr-cli&lt;/code&gt; and &lt;code&gt;inventory-service-dapr-cli&lt;/code&gt;, executable resources whose Source column holds the entire &lt;code&gt;dapr run&lt;/code&gt; command line the integration assembled: the app ID, the app port, the three sidecar ports, the app channel address, the app protocol, and whichever components flag it chose to pass. That column is the best debugging surface in this whole setup. "Which component folder did this sidecar actually load" becomes one row in a browser instead of a log grep, and the in-memory state store further down is nothing but an exercise in reading it.&lt;/p&gt;

&lt;p&gt;The run file had no equivalent. &lt;code&gt;dapr run -f .&lt;/code&gt; gives you four processes interleaving their stdout into one terminal and a &lt;code&gt;dapr stop -f .&lt;/code&gt; to take the set back down. Under the AppHost each sidecar is a resource in its own right: its own console log pane, its own recorded start time, its own Stop and Restart actions, and its own OTLP stream arriving in the same dashboard as the app it sits beside. The sidecar stops being something you remember to start and becomes something you can point at.&lt;/p&gt;

&lt;p&gt;Startup order is the second thing the AppHost owns, and it is where people arriving from Docker Compose lose an afternoon. Two methods look interchangeable and are not. &lt;code&gt;WithReference(x)&lt;/code&gt; is wiring: it injects the configuration a consumer needs in order to find &lt;code&gt;x&lt;/code&gt;, and the documentation is explicit that it says nothing whatsoever about who starts first. &lt;code&gt;WaitFor(x)&lt;/code&gt; is ordering: it holds a resource back until &lt;code&gt;x&lt;/code&gt; is running and its registered health checks report healthy. Read &lt;code&gt;WithReference&lt;/code&gt; as compose's &lt;code&gt;depends_on&lt;/code&gt; and you have written down a dependency the runtime will not honour, which surfaces as a startup race rather than as an error message. &lt;a href="https://aspire.dev/app-host/migrate-from-docker-compose/" rel="noopener noreferrer"&gt;aspire.dev's own compose migration guide&lt;/a&gt; names this as the top gotcha for people coming from compose, and it earns the title.&lt;/p&gt;

&lt;p&gt;One piece of housekeeping before any of this reproduces on your machine. Ask a box set up today which Aspire version it is on and you get three answers: one from the CLI, one from the installed project templates, and one from the packages that actually resolve at build time. &lt;code&gt;aspire update&lt;/code&gt; reconciles them. Everything below is pinned to &lt;code&gt;Aspire.AppHost.Sdk&lt;/code&gt; 13.5.3 and &lt;code&gt;CommunityToolkit.Aspire.Hosting.Dapr&lt;/code&gt; 13.0.0, and version-qualifying your own transcripts is worth the ten seconds when a stack moves this fast.&lt;/p&gt;

&lt;h3&gt;
  
  
  It is not docker-compose, and it does not replace it
&lt;/h3&gt;

&lt;p&gt;The reflex on first reading an &lt;code&gt;AppHost.cs&lt;/code&gt; is that this is a compose file with C# syntax, and half of that reflex is correct. The compose file that exists purely to stand up Postgres, Redis, RabbitMQ or Azurite and then run your services does go away: &lt;code&gt;AddPostgres&lt;/code&gt; plus &lt;code&gt;AddProject&lt;/code&gt; covers it, and adds service discovery, health-gated startup and the dashboard on top. The part that goes away with it is the workaround where you containerise a .NET service you have no intention of shipping in a container, just so compose can see it. &lt;code&gt;AddProject&lt;/code&gt; runs it as a host process, so breakpoints and the ordinary build loop keep working.&lt;/p&gt;

&lt;p&gt;The other half of the reflex is wrong in a way that matters, because a compose file is a deployment artifact and the AppHost is not. Aspire does not delete your compose file. It writes one: publishing to a Docker Compose environment emits &lt;code&gt;docker-compose.yaml&lt;/code&gt;, a &lt;code&gt;.env&lt;/code&gt;, per-environment &lt;code&gt;.env&lt;/code&gt; files, and a &lt;code&gt;Dockerfile&lt;/code&gt; per resource, and &lt;code&gt;aspire deploy&lt;/code&gt; then runs &lt;code&gt;docker compose up -d --remove-orphans&lt;/code&gt; over the result. The C# is the model; the YAML is the output.&lt;/p&gt;

&lt;p&gt;Three gaps matter before you delete anything, and all three come from that same migration guide rather than from community complaints. &lt;code&gt;deploy.resources.limits.memory&lt;/code&gt; and &lt;code&gt;cpus&lt;/code&gt; are documented as "Not supported", so you cannot reproduce a memory-starved container locally the way compose lets you. Restart policies exist at publish time only. And network isolation has no direct equivalent at all: Microsoft's own wording is that "If your Docker Compose setup relies on network isolation (for example, preventing a frontend service from directly accessing the database), Aspire doesn't provide a direct equivalent." That last one is the one to read twice if your compose file uses a private network as a dev-time security boundary, because the boundary does not survive the move and nothing tells you it is gone.&lt;/p&gt;

&lt;h2&gt;
  
  
  One file that starts everything
&lt;/h2&gt;

&lt;p&gt;The AppHost is a console application whose whole job is to describe the other four resources. Its project file comes first, because the shape of it changed on the 13.x line and the version most tutorials show no longer matches what the template writes.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight xml"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;Project&lt;/span&gt; &lt;span class="na"&gt;Sdk=&lt;/span&gt;&lt;span class="s"&gt;"Aspire.AppHost.Sdk/13.5.3"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;PropertyGroup&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;OutputType&amp;gt;&lt;/span&gt;Exe&lt;span class="nt"&gt;&amp;lt;/OutputType&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;IsAspireHost&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/IsAspireHost&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AspireUseCliBundle&amp;gt;&lt;/span&gt;true&lt;span class="nt"&gt;&amp;lt;/AspireUseCliBundle&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;UserSecretsId&amp;gt;&lt;/span&gt;dapraspiredemo-apphost-w36&lt;span class="nt"&gt;&amp;lt;/UserSecretsId&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/PropertyGroup&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;PackageReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"CommunityToolkit.Aspire.Hosting.Dapr"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;

  &lt;span class="nt"&gt;&amp;lt;ItemGroup&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ProjectReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"..\DaprAspireDemo.OrderService\DaprAspireDemo.OrderService.csproj"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ProjectReference&lt;/span&gt; &lt;span class="na"&gt;Include=&lt;/span&gt;&lt;span class="s"&gt;"..\DaprAspireDemo.InventoryService\DaprAspireDemo.InventoryService.csproj"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ItemGroup&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;/Project&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Aspire version lives on the &lt;code&gt;Sdk&lt;/code&gt; attribute of the &lt;code&gt;Project&lt;/code&gt; element, and there is no &lt;code&gt;Aspire.Hosting.AppHost&lt;/code&gt; package reference anywhere to match it: the only &lt;code&gt;PackageReference&lt;/code&gt; in the file is the Dapr integration. The entry point is &lt;code&gt;AppHost.cs&lt;/code&gt;, not &lt;code&gt;Program.cs&lt;/code&gt;. Material written against Aspire 9.x describes a different file, with a nested &lt;code&gt;&amp;lt;Sdk Name="Aspire.AppHost.Sdk" Version="..." /&amp;gt;&lt;/code&gt; element and a hosting package reference, so a &lt;code&gt;PropertyGroup&lt;/code&gt; copied from a 9.x post lands in a project that no longer expects it.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;AspireUseCliBundle&amp;gt;&lt;/code&gt; is the line worth stopping on. Setting it to true takes the dashboard and the orchestrator (DCP) from the installed Aspire CLI bundle rather than from NuGet, which is also what keeps &lt;code&gt;Aspire.Dashboard.Sdk&lt;/code&gt; and the DCP packages out of the restore graph, and it needs the &lt;code&gt;aspire&lt;/code&gt; CLI on &lt;code&gt;PATH&lt;/code&gt;. Build the project on 13.5 without it and MSBuild answers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;warning ASPIRE010: DaprAspireDemo.AppHost is configured with AspireUseCliBundle=false. Some Aspire
features require the Aspire CLI bundle. Set AspireUseCliBundle=true to enable those features, or
suppress ASPIRE010 to continue without the bundle. See https://aka.ms/aspire/diagnostics/aspire010
for more information.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;Aspire.Hosting.AppHost.props&lt;/code&gt; defaults the property to &lt;code&gt;false&lt;/code&gt; and &lt;code&gt;Aspire.Hosting.AppHost.targets&lt;/code&gt; then warns that it is false, which is an odd pairing until you reach the detail that makes it dangerous: &lt;code&gt;TreatWarningsAsErrors=true&lt;/code&gt; does &lt;strong&gt;not&lt;/strong&gt; promote ASPIRE010. It comes out of an MSBuild &lt;code&gt;&amp;lt;Warning&amp;gt;&lt;/code&gt; task rather than out of a Roslyn diagnostic, so a CI gate that turns warnings into errors passes it straight through. Only a rule that counts warnings catches it, which means a repository with a strict-looking gate can ship an AppHost missing whatever the bundle provides and never see a red build. The property is new in 13.5; it did not exist in 13.3.5, so an older sample carries no clue that it is missing.&lt;/p&gt;

&lt;p&gt;The one package reference is the one to get right, and the obvious search result is the wrong package. &lt;code&gt;Aspire.Hosting.Dapr&lt;/code&gt; is dead: it stopped at 9.1.0, and every version of it is &lt;a href="https://www.nuget.org/packages/Aspire.Hosting.Dapr" rel="noopener noreferrer"&gt;deprecated on nuget.org&lt;/a&gt; with the notice &lt;em&gt;"We will no longer be publishing new versions of this package. We recommend using the CommunityToolkit.Aspire.Hosting.Dapr package going forward."&lt;/em&gt; "Deprecated" reads as "abandoned", and that is not what happened here. The move was an ownership transfer, argued out in the comments of &lt;a href="https://github.com/CommunityToolkit/Aspire/issues/349" rel="noopener noreferrer"&gt;CommunityToolkit/Aspire#349&lt;/a&gt;: David Fowler laid out three options, keep it in core, move it to the Toolkit, or hand it to the Dapr .NET client team, and the thread settled on the Toolkit. The reason on the record is maintainer bandwidth, that Dapr was not a priority for the core team and every PR would still need core review, not a technical fault in the package. The confusing result is that &lt;a href="https://aspire.dev/integrations/frameworks/dapr/dapr-host/" rel="noopener noreferrer"&gt;the Dapr integration docs are first-party on aspire.dev&lt;/a&gt; while the code is community-maintained, so the page you read and the package you install do not share a name. &lt;code&gt;CommunityToolkit.Aspire.Hosting.Dapr&lt;/code&gt; 13.0.0 is the newest stable and depends on &lt;code&gt;Aspire.Hosting &amp;gt;= 13.0.0&lt;/code&gt;, so it rides the same 13.x train as the AppHost SDK above.&lt;/p&gt;

&lt;p&gt;That is the whole project file. Here is the program it builds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;CommunityToolkit.Aspire.Hosting.Dapr&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;DistributedApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddDapr&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;stateStore&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddDaprStateStore&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="s"&gt;"statestore"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DaprComponentOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;LocalPath&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Path&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Combine&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppHostDirectory&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;".."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"components"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"statestore.yaml"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;inventory&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddProject&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Projects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DaprAspireDemo_InventoryService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"inventory-service"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithDaprSidecar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sidecar&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sidecar&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DaprSidecarOptions&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;AppId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"inventory-service"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;}));&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;orders&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddProject&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Projects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DaprAspireDemo_OrderService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"order-service"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithDaprSidecar&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sidecar&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sidecar&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithOptions&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;DaprSidecarOptions&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;AppId&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"order-service"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stateStore&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

&lt;span class="n"&gt;orders&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WaitFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;inventory&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;Run&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv7udi3y6r2w0a3sd8o5l.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fv7udi3y6r2w0a3sd8o5l.png" alt="Four resources under one AppHost: two services, two Dapr sidecars, one component file" width="800" height="1009"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;builder.AddDapr()&lt;/code&gt; is optional, which is the kind of claim worth distrusting, so I commented the line out and ran it again: both &lt;code&gt;*-dapr-cli&lt;/code&gt; resources still started, &lt;code&gt;POST /orders&lt;/code&gt; still returned 201, and the &lt;code&gt;dapr run&lt;/code&gt; command line the integration assembled came back character-identical modulo ports. &lt;code&gt;WithDaprSidecar()&lt;/code&gt; calls &lt;code&gt;builder.ApplicationBuilder.AddDapr()&lt;/code&gt; itself, and &lt;code&gt;AddDapr&lt;/code&gt; registers its lifecycle hook through &lt;code&gt;TryAddEventingSubscriber&lt;/code&gt;, so the second call is a no-op. What writing the line buys you is the &lt;code&gt;AddDapr(Action&amp;lt;DaprOptions&amp;gt;)&lt;/code&gt; overload, and &lt;code&gt;DaprOptions&lt;/code&gt; has exactly three members: &lt;code&gt;DaprPath&lt;/code&gt; for a Dapr CLI that is not on &lt;code&gt;PATH&lt;/code&gt;, &lt;code&gt;EnableTelemetry&lt;/code&gt; for turning the sidecars' dashboard telemetry off, and &lt;code&gt;PublishingConfigurationAction&lt;/code&gt; for the publish step. Called with no callback, as here, it is the line that names the dependency: documentation rather than wiring.&lt;/p&gt;

&lt;p&gt;The lifecycle hook it registers does not check whether Dapr is initialised. It probes for the &lt;code&gt;dapr&lt;/code&gt; CLI binary, Homebrew prefix included, so a machine where somebody ran &lt;code&gt;brew install dapr&lt;/code&gt; and stopped there passes the check, the AppHost starts clean, and the &lt;code&gt;order-service-dapr-cli&lt;/code&gt; resource fails on its own some seconds later because &lt;code&gt;dapr run&lt;/code&gt; has no &lt;code&gt;daprd&lt;/code&gt; to launch. The tell is &lt;code&gt;dapr --version&lt;/code&gt; answering with a CLI version and a runtime version of &lt;code&gt;n/a&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AddDaprStateStore&lt;/code&gt; gets the second aside below, because the argument that looks optional is the one that decides whether your data outlives a process. The name is doing three jobs in the meantime: &lt;code&gt;statestore&lt;/code&gt; is the Aspire resource name, the &lt;code&gt;metadata.name&lt;/code&gt; in the component YAML, and the first argument &lt;code&gt;order-service&lt;/code&gt; passes to &lt;code&gt;SaveStateAsync&lt;/code&gt;. All three have to be the same string, and nothing checks that they are.&lt;/p&gt;

&lt;p&gt;Both &lt;code&gt;WithDaprSidecar&lt;/code&gt; calls take a callback rather than an options object, and the callback receives a sidecar builder carrying its own &lt;code&gt;WithOptions&lt;/code&gt; and &lt;code&gt;WithReference&lt;/code&gt;. &lt;code&gt;DaprSidecarOptions&lt;/code&gt; has 32 properties; this file sets one of them, twice. What the integration fills in when you set nothing is the part to know before you start overriding things: &lt;code&gt;--app-id&lt;/code&gt; falls back to the Aspire resource name, &lt;code&gt;--app-port&lt;/code&gt; to the HTTP endpoint Aspire allocated for the app, and &lt;code&gt;--config&lt;/code&gt; is not passed at all. The two &lt;code&gt;AppId&lt;/code&gt; values above are the fallback spelled out, which is what stops a later rename of the Aspire resource from silently breaking every caller. The Source column shows you the resulting &lt;code&gt;dapr run&lt;/code&gt; command line without a debugger.&lt;/p&gt;

&lt;p&gt;One number in that command line will not match the one your application sees. On the run behind this article, &lt;code&gt;order-service&lt;/code&gt; was handed &lt;code&gt;DAPR_HTTP_PORT=57679&lt;/code&gt; while its own daprd started with &lt;code&gt;--dapr-http-port 57685&lt;/code&gt;. DCP puts a proxy in front of the sidecar, so the port the app talks to is not the port daprd binds. Both answer.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;orders.WaitFor(inventory)&lt;/code&gt; is the last line and it is not a Dapr feature at all. Part 3 dealt with the same window from inside the caller: when the sidecar cannot route to an app ID it answers HTTP 500 with an &lt;code&gt;ERR_DIRECT_INVOKE&lt;/code&gt; body, and &lt;code&gt;InventoryClient&lt;/code&gt; translated that into a retryable failure rather than a flat 502. &lt;code&gt;WaitFor&lt;/code&gt; addresses it from the other end, by refusing to start the caller until the callee reports healthy. They are not alternatives. The ordering is there so the startup case cannot arise; the error translation stays because the target can also fall over at three in the morning, when nothing is starting up.&lt;/p&gt;

&lt;h3&gt;
  
  
  Three ways to write that reference, one that compiles
&lt;/h3&gt;

&lt;p&gt;The form printed in the package's own README does not build in this repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddProject&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;Projects&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;DaprAspireDemo_OrderService&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="s"&gt;"order-service"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithDaprSidecar&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;WithReference&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;stateStore&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;   &lt;span class="c1"&gt;// &amp;lt;- [Obsolete]; fails the build&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppHost.cs(10,1): error CS0618: 'IDistributedApplicationResourceBuilderExtensions.WithReference&amp;lt;TDestination&amp;gt;(IResourceBuilder&amp;lt;TDestination&amp;gt;, IResourceBuilder&amp;lt;IDaprComponentResource&amp;gt;)' is obsolete: 'Add reference to the sidecar resource instead of the project resource'

Build FAILED.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The error is harder to act on than it looks. The position is &lt;code&gt;(10,1)&lt;/code&gt;, the start of the whole chained expression, not the &lt;code&gt;.WithReference&lt;/code&gt; token three lines further down, so an editor puts the squiggle on &lt;code&gt;builder.AddProject&lt;/code&gt; and the method it is complaining about is off the highlighted line entirely. And the parameterless &lt;code&gt;.WithDaprSidecar()&lt;/code&gt; in the middle is fine: it carries no diagnostic of its own, which sends you looking at the wrong call first. Only &lt;code&gt;WithReference&lt;/code&gt; on the &lt;em&gt;project&lt;/em&gt; builder is obsolete.&lt;/p&gt;

&lt;p&gt;Under &lt;code&gt;TreatWarningsAsErrors&lt;/code&gt; this fails the build, which is the good outcome. Without that setting it is a warning you can live with for months, and it is not cosmetic. Published both ways, the obsolete form emits a &lt;code&gt;dapr.v0&lt;/code&gt; resource with no &lt;code&gt;components&lt;/code&gt; array at all, while the sidecar-callback form emits &lt;code&gt;"components": ["statestore", "pubsub"]&lt;/code&gt;. Same C# intent, different published output, and what that difference costs you comes back at the end, when this model meets &lt;code&gt;aspire publish&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Two other spellings look plausible and are not. &lt;code&gt;builder.AddDaprSidecar("order-service")&lt;/code&gt; appears in enough posts to feel like an API:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppHost.cs(5,9): error CS1061: 'IDistributedApplicationBuilder' does not contain a definition for 'AddDaprSidecar' and no accessible extension method 'AddDaprSidecar' accepting a first argument of type 'IDistributedApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Reading the assembly explains why: the builder-level Dapr surface is exactly four methods, &lt;code&gt;AddDapr&lt;/code&gt;, &lt;code&gt;AddDaprComponent&lt;/code&gt;, &lt;code&gt;AddDaprPubSub&lt;/code&gt; and &lt;code&gt;AddDaprStateStore&lt;/code&gt;, and &lt;code&gt;AddDaprSidecar&lt;/code&gt; is not among them. A sidecar attaches to a resource; it is never declared standalone.&lt;/p&gt;

&lt;p&gt;The third one is the &lt;code&gt;using&lt;/code&gt; at the top of &lt;code&gt;AppHost.cs&lt;/code&gt;, which is easy to read as decoration and is not:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;AppHost.cs(11,26): error CS0246: The type or namespace name 'DaprSidecarOptions' could not be found (are you missing a using directive or an assembly reference?)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The extension methods are declared in the &lt;code&gt;Aspire.Hosting&lt;/code&gt; namespace, which the AppHost's implicit usings already bring in, so &lt;code&gt;AddDapr&lt;/code&gt; and &lt;code&gt;WithDaprSidecar&lt;/code&gt; resolve with no using directive at all. &lt;code&gt;DaprSidecarOptions&lt;/code&gt; and &lt;code&gt;DaprComponentOptions&lt;/code&gt; are not in that namespace. Write the callback form without &lt;code&gt;using CommunityToolkit.Aspire.Hosting.Dapr;&lt;/code&gt; and the calls compile while the options types do not, which is exactly the kind of half-working state that sends you back to the package reference. The sample on aspire.dev omits the using.&lt;/p&gt;

&lt;p&gt;What compiles, and what the file above already uses, is the reference on the sidecar builder: &lt;code&gt;.WithDaprSidecar(sidecar =&amp;gt; sidecar.WithOptions(...).WithReference(stateStore))&lt;/code&gt;. One callback, everything Dapr-shaped inside it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The state store you did not write is in memory
&lt;/h3&gt;

&lt;p&gt;Delete the &lt;code&gt;LocalPath&lt;/code&gt; argument from &lt;code&gt;AddDaprStateStore&lt;/code&gt; and everything keeps working. That is the problem.&lt;/p&gt;

&lt;p&gt;The integration does not go looking for a component you might already have. It writes its own, into a temp directory, and this is what it writes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="na"&gt;apiVersion&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;dapr.io/v1alpha1&lt;/span&gt;
&lt;span class="na"&gt;kind&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Component&lt;/span&gt;
&lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;statestore&lt;/span&gt;
&lt;span class="na"&gt;spec&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt;
  &lt;span class="na"&gt;type&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;state.in-memory&lt;/span&gt;
  &lt;span class="na"&gt;version&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;v1&lt;/span&gt;
  &lt;span class="na"&gt;metadata&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;[]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then it passes that directory to the sidecar as &lt;code&gt;--resources-path&lt;/code&gt;. The mechanism is in that flag, and it is the part the advice you will find online gets backwards: &lt;code&gt;--resources-path&lt;/code&gt; &lt;strong&gt;replaces&lt;/strong&gt; &lt;code&gt;--components-path&lt;/code&gt;, it does not add to it. Whatever is in the machine's &lt;code&gt;~/.dapr/components&lt;/code&gt;, including the Redis state store &lt;code&gt;dapr init&lt;/code&gt; put there, is invisible to a sidecar started that way.&lt;/p&gt;

&lt;p&gt;The proof is an asymmetry inside a single launch. Two daprd processes, one &lt;code&gt;ps&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;daprd ... --components-path /Users/martino/.dapr/components  --app-id inventory-service
daprd ... --resources-path /var/folders/.../T/aspire-dapr.2X7RwV/statestore --app-id order-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;inventory-service&lt;/code&gt; has no &lt;code&gt;WithReference&lt;/code&gt;, so it keeps the default &lt;code&gt;--components-path&lt;/code&gt; and sees the machine's real components: its &lt;code&gt;/v1.0/metadata&lt;/code&gt; returns two, &lt;code&gt;pubsub&lt;/code&gt; on &lt;code&gt;pubsub.redis&lt;/code&gt; and &lt;code&gt;statestore&lt;/code&gt; on &lt;code&gt;state.redis&lt;/code&gt;. &lt;code&gt;order-service&lt;/code&gt;, the one service in the solution that actually stores anything, has the reference, gets &lt;code&gt;--resources-path&lt;/code&gt;, and returns exactly one component: &lt;code&gt;statestore&lt;/code&gt; on &lt;code&gt;state.in-memory&lt;/code&gt;. The service that needs a database is the service that lost it.&lt;/p&gt;

&lt;p&gt;Nothing about this announces itself, because the generated store is fully functional. &lt;code&gt;SaveStateAsync&lt;/code&gt; succeeds, &lt;code&gt;GetStateAsync&lt;/code&gt; hands the value back, the dashboard trace has the same shape either way, and no log line anywhere mentions that the store is in memory. It fails on one event only: the sidecar restarting. Which is to say never on a laptop, and eventually in production.&lt;/p&gt;

&lt;p&gt;Pointing &lt;code&gt;LocalPath&lt;/code&gt; at the component file in the repository is the fix, and Redis can be asked whether it took:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;$ &lt;/span&gt;docker &lt;span class="nb"&gt;exec &lt;/span&gt;dapr_redis redis-cli KEYS &lt;span class="s1"&gt;'*'&lt;/span&gt;
order-service||ORD-2001
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With &lt;code&gt;LocalPath&lt;/code&gt; set, &lt;code&gt;/v1.0/metadata&lt;/code&gt; on the order sidecar reports &lt;code&gt;state.redis&lt;/code&gt; and that key appears after a write; without it, &lt;code&gt;KEYS '*'&lt;/code&gt; comes back empty and the metadata says &lt;code&gt;state.in-memory&lt;/code&gt;. The key is also Part 3's point arriving intact: the application passed &lt;code&gt;ORD-2001&lt;/code&gt;, and &lt;code&gt;order-service||&lt;/code&gt; in front of it was added by the sidecar, not by the SDK, so the app ID is still part of the physical key even though nothing in the AppHost or the service ever wrote it there.&lt;/p&gt;

&lt;p&gt;Check it before you trust it. The sidecar will tell you what it loaded:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-s&lt;/span&gt; http://localhost:&amp;lt;daprHttpPort&amp;gt;/v1.0/metadata | jq &lt;span class="s1"&gt;'.components'&lt;/span&gt;
&lt;span class="c"&gt;# [{"name":"statestore","type":"state.in-memory","version":"v1", ...}]   &amp;lt;- the bug, visible&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;daprHttpPort&lt;/code&gt; is the one on the &lt;code&gt;dapr run&lt;/code&gt; line in the dashboard, not the one in the app's &lt;code&gt;DAPR_HTTP_PORT&lt;/code&gt;, though as noted above both answer. If you would rather not leave the browser, the same dashboard Source column answers the question without a request: look at which of &lt;code&gt;--resources-path&lt;/code&gt; and &lt;code&gt;--components-path&lt;/code&gt; the sidecar was given.&lt;/p&gt;

&lt;h2&gt;
  
  
  ServiceDefaults: what every service inherits
&lt;/h2&gt;

&lt;p&gt;Both services start with the same line, and that line is the entire footprint Aspire has inside a service process. All four calls it makes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="n"&gt;AddServiceDefaults&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;TBuilder&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;where&lt;/span&gt; &lt;span class="n"&gt;TBuilder&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;IHostApplicationBuilder&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ConfigureOpenTelemetry&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddDefaultHealthChecks&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddServiceDiscovery&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ConfigureHttpClientDefaults&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// Turn on resilience by default&lt;/span&gt;
        &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddStandardResilienceHandler&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="c1"&gt;// Turn on service discovery by default&lt;/span&gt;
        &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddServiceDiscovery&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="p"&gt;});&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nothing in this sample was customised. &lt;code&gt;Extensions.cs&lt;/code&gt; is byte-identical between the 13.3.5 and 13.5.3 templates and byte-identical again to the copy sitting in the repository's older &lt;code&gt;AspireDemo&lt;/code&gt; solution, so the file above is current for the whole 13.x line and you can read someone else's copy as if it were your own.&lt;/p&gt;

&lt;p&gt;It can stay identical because there is nothing to version. No &lt;code&gt;Aspire.ServiceDefaults&lt;/code&gt; package exists to install. The template stamps a class library into your solution and from then on the code is yours, which is why you read the four calls above rather than trusting them. Look at what the project file references and the ownership gets clearer: &lt;code&gt;Microsoft.Extensions.Http.Resilience&lt;/code&gt;, &lt;code&gt;Microsoft.Extensions.ServiceDiscovery&lt;/code&gt;, and five &lt;code&gt;OpenTelemetry.*&lt;/code&gt; packages. Not one &lt;code&gt;Aspire.*&lt;/code&gt; reference anywhere. Resilience and service discovery ship out of &lt;code&gt;dotnet/extensions&lt;/code&gt; on the 10.x line while the AppHost next door is pinned to 13.5.3, so upgrading Aspire does not upgrade this, and the three-way version skew from earlier does not reach it. &lt;a href="https://aspire.dev/get-started/csharp-service-defaults/" rel="noopener noreferrer"&gt;First-party guidance&lt;/a&gt; is firm about keeping it that way: &lt;em&gt;"Don't include other shared functionality or models in this project."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One call is missing from the list, and it is the one people assume is there. &lt;code&gt;MapDefaultEndpoints&lt;/code&gt; is not invoked by &lt;code&gt;AddServiceDefaults&lt;/code&gt;; you write it yourself in &lt;code&gt;Program.cs&lt;/code&gt;. The reason is a type mismatch rather than an oversight. Everything inside &lt;code&gt;AddServiceDefaults&lt;/code&gt; is generic over &lt;code&gt;TBuilder : IHostApplicationBuilder&lt;/code&gt;, so it works on a worker host or a MAUI builder as happily as on a web app, while &lt;code&gt;MapDefaultEndpoints&lt;/code&gt; takes a concrete &lt;code&gt;WebApplication&lt;/code&gt;. A background worker can register health checks and has nothing to map them on, so registration and mapping had to be two calls. The aside below is about what those endpoints do once you have mapped them, which is less than the name suggests.&lt;/p&gt;

&lt;p&gt;The interesting default is one method deeper than the list above, in the private &lt;code&gt;AddOpenTelemetryExporters&lt;/code&gt; that &lt;code&gt;ConfigureOpenTelemetry&lt;/code&gt; calls on its last line, and it is a conditional:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;useOtlpExporter&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;!&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsNullOrWhiteSpace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Configuration&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"OTEL_EXPORTER_OTLP_ENDPOINT"&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;useOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddOpenTelemetry&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;UseOtlpExporter&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Everything &lt;code&gt;ConfigureOpenTelemetry&lt;/code&gt; does before reaching that call is unconditional: logging with formatted messages and scopes, ASP.NET Core, HttpClient and runtime metrics, ASP.NET Core and HttpClient tracing. The exporter is the only part that asks a question first, and the question is whether &lt;code&gt;OTEL_EXPORTER_OTLP_ENDPOINT&lt;/code&gt; has a value. If it does not, no exporter is registered at all. The instrumentation still runs, still allocates, still builds every span, and then drops the lot. Nothing warns, because from the SDK's point of view nothing is wrong.&lt;/p&gt;

&lt;p&gt;Under the AppHost that variable is always set, along with &lt;code&gt;OTEL_EXPORTER_OTLP_PROTOCOL&lt;/code&gt;, &lt;code&gt;OTEL_SERVICE_NAME&lt;/code&gt; (literally the string you passed to &lt;code&gt;AddProject&lt;/code&gt;), a per-run &lt;code&gt;service.instance.id&lt;/code&gt; in &lt;code&gt;OTEL_RESOURCE_ATTRIBUTES&lt;/code&gt;, and an &lt;code&gt;x-otlp-api-key&lt;/code&gt; header for the dashboard's ingest endpoint. That is why nothing in either &lt;code&gt;Program.cs&lt;/code&gt; names a collector: the orchestrator names it, on every child process it starts, including the two &lt;code&gt;dapr run&lt;/code&gt; executables. Two of the injected values are Development-only, and they explain a mismatch people blame on their APM vendor: locally you get &lt;code&gt;OTEL_TRACES_SAMPLER=always_on&lt;/code&gt; and one-second export intervals, and in production Aspire sets neither, leaving you on the OTel SDK's own defaults. Dashboards that feel instant on a laptop lag in production for that reason and no other.&lt;/p&gt;

&lt;p&gt;Take the same service and deploy it to App Service or a plain container without that variable and you get zero telemetry with zero warnings. Setting the variable is the fix, not editing &lt;code&gt;Extensions.cs&lt;/code&gt;. And resist the reflex of adding your vendor's OTLP exporter beside the defaults: &lt;code&gt;UseOtlpExporter&lt;/code&gt; is single-shot, so a second call, or a signal-specific &lt;code&gt;AddOtlpExporter()&lt;/code&gt; on the same service collection, throws &lt;code&gt;NotSupportedException&lt;/code&gt; at startup rather than warning.&lt;/p&gt;

&lt;p&gt;That is the whole inheritance, and from the consuming side it is one line in &lt;code&gt;OrderService/Program.cs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;Dapr.Client&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;DaprAspireDemo.OrderService.Inventory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;DaprAspireDemo.OrderService.Orders&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateBuilder&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddServiceDefaults&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;AddDaprClient&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Keyed singleton rather than AddHttpClient, to keep the app ID out of reach of service discovery.&lt;/span&gt;
&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddKeyedSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;HttpClient&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;(&lt;/span&gt;
    &lt;span class="n"&gt;InventoryClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AppId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;DaprClient&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;CreateInvokeHttpClient&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;appId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="p"&gt;!));&lt;/span&gt;

&lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Services&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;AddSingleton&lt;/span&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;InventoryClient&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;();&lt;/span&gt;

&lt;span class="kt"&gt;var&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Build&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapDefaultEndpoints&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapOrderEndpoints&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;RunAsync&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two frameworks, two lines, and neither knows the other exists. &lt;code&gt;AddServiceDefaults&lt;/code&gt; never mentions Dapr. &lt;code&gt;AddDaprClient&lt;/code&gt; never mentions Aspire: it reads &lt;code&gt;DAPR_HTTP_PORT&lt;/code&gt; and &lt;code&gt;DAPR_GRPC_PORT&lt;/code&gt; out of its own environment, exactly as it did in Part 3, and the only thing that changed is who set them. There it was &lt;code&gt;dapr run&lt;/code&gt; from the multi-app file. Here it is the hosting integration, one layer further out. The defaults 3500 and 50001 appear nowhere in this file precisely because nothing in it assumes a port.&lt;/p&gt;

&lt;p&gt;Service invocation itself runs over an ordinary &lt;code&gt;HttpClient&lt;/code&gt;. &lt;code&gt;CreateInvokeHttpClient&lt;/code&gt; gives the client a base address whose host is the app ID, &lt;code&gt;inventory-service&lt;/code&gt; over plain http, and installs the handler that rewrites each request into &lt;code&gt;{daprEndpoint}/v1.0/invoke/inventory-service/method/{path}&lt;/code&gt;, and that factory is the supported surface now that &lt;code&gt;DaprClient.InvokeMethodAsync&lt;/code&gt; has carried &lt;code&gt;[Obsolete]&lt;/code&gt; since the Dapr .NET SDK 1.17.&lt;/p&gt;

&lt;p&gt;The keyed registration in the middle is the one line in the file that is a judgement call, and it deserves a more honest defence than "the factory would break", because the factory does not break. Registering the same client through &lt;code&gt;AddHttpClient&lt;/code&gt;, same &lt;code&gt;inventory-service&lt;/code&gt; base address, same Dapr &lt;code&gt;InvocationHandler&lt;/code&gt;, resolved through &lt;code&gt;IHttpClientFactory&lt;/code&gt;, returns HTTP 201 on &lt;code&gt;POST /orders&lt;/code&gt;. Two independent launches, no exception at &lt;code&gt;CreateClient&lt;/code&gt; and none at request time.&lt;/p&gt;

&lt;p&gt;It works because of what &lt;code&gt;AddServiceDiscovery()&lt;/code&gt; registers by default: a pass-through provider. A host name with no matching configuration entry is not an error, it is a name that gets handed onward untouched to ordinary DNS. A pair of probe clients in one launch proves both halves of that sentence live. The one with a configuration entry resolved and then failed at connect with &lt;code&gt;Connection refused (localhost:59999)&lt;/code&gt;, so service discovery is genuinely in the pipeline and genuinely rewriting. The one without an entry failed at the socket with &lt;code&gt;nodename nor servname provided, or not known (inventory-service:80)&lt;/code&gt;, so the URI reached DNS with the app ID still in it. On the real invoke client the Dapr handler intercepts before any socket opens and rewrites the authority to the sidecar, so the DNS failure never happens.&lt;/p&gt;

&lt;p&gt;The trap is on the other side of that condition, and it is one line in the AppHost away. Add &lt;code&gt;.WithReference(inventory)&lt;/code&gt; to the order-service resource, the ordinary service-discovery overload and not the obsolete component one from the AppHost earlier, and Aspire hands the order-service process four new environment variables: the lowercase &lt;code&gt;http&lt;/code&gt; and &lt;code&gt;https&lt;/code&gt; service-discovery entries, and the uppercase &lt;code&gt;INVENTORY_SERVICE_HTTP&lt;/code&gt; and &lt;code&gt;INVENTORY_SERVICE_HTTPS&lt;/code&gt; forms of the same thing. A full environment diff against a control launch found those four and nothing else. Service discovery now has something to resolve, so it rewrites the request before Dapr ever sees it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;services__inventory-service__http__0=http://localhost:5049

http://inventory-service/stock/check  -&amp;gt;  http://localhost:5049/stock/check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The handler then reads &lt;code&gt;uri.Host&lt;/code&gt; off the rewritten URI, which drops the port, and the sidecar is asked to invoke a service called &lt;code&gt;localhost&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"errorCode"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ERR_DIRECT_INVOKE"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"failed to invoke, id: localhost, err: couldn't find service: localhost"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;POST /orders&lt;/code&gt; comes back 503. I ran that rather than inferring it from the error message: same AppHost, the factory registration in place, 503 on the order and that body verbatim out of the sidecar. Seeing the rewrite behind it took a separate run. A second client in the same launch, same base address, service discovery in its pipeline and no &lt;code&gt;InvocationHandler&lt;/code&gt;, reached inventory-service's own Kestrel and came back 200, which is only possible if something had already replaced the authority.&lt;/p&gt;

&lt;p&gt;Run that same AppHost against the sample as it ships and the reference changes nothing: 201, 200, 409, byte-identical to a control launch without it. The registration style, not the AppHost, is what decides the outcome. &lt;code&gt;DaprClient.CreateInvokeHttpClient&lt;/code&gt; builds its client directly, so it never passes through &lt;code&gt;IHttpClientFactory&lt;/code&gt;, &lt;code&gt;ConfigureHttpClientDefaults&lt;/code&gt; never reaches it, and the injected configuration sits there inert. The two mechanisms are not exclusive, they are ordered, and service discovery is first. Keeping the invoke client out of the factory keeps the app ID out of the pipeline service discovery reads, which is a smaller claim than "the factory would break" and the one the runs actually support.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AddStandardResilienceHandler&lt;/code&gt; in the shared defaults is quietly wrapping every factory-created client in retries, a circuit breaker and two layers of timeout, which is a good thing to know before you write your own retry loop on top of it; Part 5 pulls that apart properly, because it belongs to the migration story rather than to this one.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;InventoryService/Program.cs&lt;/code&gt; is the shortest argument in the whole sample. It calls &lt;code&gt;AddServiceDefaults&lt;/code&gt;, maps its endpoints, and stops. Its project file references &lt;code&gt;DaprAspireDemo.ServiceDefaults&lt;/code&gt; and nothing else: no &lt;code&gt;Dapr.Client&lt;/code&gt;, no &lt;code&gt;Dapr.AspNetCore&lt;/code&gt;, no Dapr type anywhere in its source. It is reachable as &lt;code&gt;inventory-service&lt;/code&gt; because the AppHost attached a sidecar with that app ID, and Part 3's asymmetry survives the move intact. Being callable by app ID still costs the callee zero lines.&lt;/p&gt;

&lt;h3&gt;
  
  
  The health endpoints disappear outside Development
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;MapDefaultEndpoints&lt;/code&gt; is nine lines of code, and the first of them is a condition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="nf"&gt;MapDefaultEndpoints&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt; &lt;span class="n"&gt;WebApplication&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Adding health checks endpoints to applications in non-development environments has security implications.&lt;/span&gt;
    &lt;span class="c1"&gt;// See https://aka.ms/aspire/healthchecks for details before enabling these endpoints in non-development environments.&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Environment&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;IsDevelopment&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// All health checks must pass for app to be considered ready to accept traffic after starting&lt;/span&gt;
        &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;HealthEndpointPath&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="c1"&gt;// Only health checks tagged with the "live" tag must pass for app to be considered alive&lt;/span&gt;
        &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MapHealthChecks&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;AlivenessEndpointPath&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="n"&gt;HealthCheckOptions&lt;/span&gt;
        &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;Predicate&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="p"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;Tags&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"live"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Outside Development neither &lt;code&gt;/health&lt;/code&gt; nor &lt;code&gt;/alive&lt;/code&gt; is mapped. Not "returns 503", not "returns an empty body": there is no route. Point an AKS readiness probe or a Container Apps health probe at &lt;code&gt;/health&lt;/code&gt;, get a 404, and the rollout stalls with a pod that never goes ready and not one log line anywhere mentioning health checks. &lt;a href="https://aspire.dev/fundamentals/health-checks/" rel="noopener noreferrer"&gt;aspire.dev states it plainly&lt;/a&gt;: "In non-development environments, the &lt;code&gt;/health&lt;/code&gt; and &lt;code&gt;/alive&lt;/code&gt; endpoints are disabled by default."&lt;/p&gt;

&lt;p&gt;The reason is defensible. An unauthenticated &lt;code&gt;/health&lt;/code&gt; that fans out to your database, cache and message broker on every request is a DoS amplifier that anyone on the internet can aim at your dependencies, and its response body enumerates those dependencies by name.&lt;/p&gt;

&lt;p&gt;Before you go rewriting them, get the tag semantics right, because the version repeated in most posts is backwards. &lt;code&gt;/health&lt;/code&gt; is mapped with &lt;strong&gt;no predicate&lt;/strong&gt;, so it runs every registered check, including the ones tagged &lt;code&gt;live&lt;/code&gt;. &lt;code&gt;/alive&lt;/code&gt; filters to &lt;code&gt;live&lt;/code&gt; only, so untagged checks never reach it. A probe app registering the template's &lt;code&gt;"self"&lt;/code&gt; check plus a second untagged check returning &lt;code&gt;Unhealthy&lt;/code&gt; answers 503 on &lt;code&gt;/health&lt;/code&gt; and 200 on &lt;code&gt;/alive&lt;/code&gt; at the same moment, which is exactly the Kubernetes semantic you want: a dead dependency should fail readiness and pull the pod out of the load balancer, and must not fail liveness and trigger a restart that cannot possibly help. Every Aspire client integration that registers a check (&lt;code&gt;AddNpgsqlDataSource&lt;/code&gt;, &lt;code&gt;AddRedisClient&lt;/code&gt;) registers it untagged, so this is the behaviour you inherit whether you thought about it or not.&lt;/p&gt;

&lt;p&gt;The fix is not deleting the &lt;code&gt;if&lt;/code&gt;. The documented alternative keeps the endpoints cheap and quiet: a 5-second request timeout policy, a 10-second output cache so a probe storm hits the cache rather than the database, both applied through a &lt;code&gt;MapGroup&lt;/code&gt;, and host filtering or authorization on that group so only the platform's probe can reach it. That is a handful of lines in the same method, and it is the variant to copy.&lt;/p&gt;

&lt;p&gt;One consequence reaches back into the AppHost. &lt;code&gt;WithHttpHealthCheck("/health")&lt;/code&gt; combined with &lt;code&gt;WaitFor&lt;/code&gt; is what turns "start B after A" into "start B after A is actually answering", which is the mechanism &lt;code&gt;orders.WaitFor(inventory)&lt;/code&gt; leaned on back in the AppHost. If the endpoint it probes exists only in Development, that gate exists only in Development too, and nothing tells you when it stops applying.&lt;/p&gt;

&lt;h2&gt;
  
  
  One request, seven spans
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;POST /orders&lt;/code&gt; does three things: it takes an order, asks &lt;code&gt;inventory-service&lt;/code&gt; whether the lines can be filled, and writes the accepted order to the state store. Two of those cross a process boundary, and nothing in the order-service source names a host, a port or a URL to make them happen.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-X&lt;/span&gt; POST http://localhost:5037/orders &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-H&lt;/span&gt; &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'{"orderId":"ORD-1001","customerId":"CUST-42","lines":[{"sku":"AZ-KEYBOARD","quantity":2,"unitPrice":79.99},{"sku":"AZ-MOUSE","quantity":1,"unitPrice":24.50}]}'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{"orderId":"ORD-1001","customerId":"CUST-42","lines":[...],"total":184.48,"status":0,"placedAt":"2026-08-28T06:47:16.941436+00:00"}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;HTTP 201, with the total computed from the lines the inventory service agreed to reserve. Order something the warehouse does not have and the same endpoint answers 409 with the shortfall rather than a stack trace:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"orderId"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ORD-1002"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"shortfalls"&lt;/span&gt;&lt;span class="p"&gt;:[{&lt;/span&gt;&lt;span class="nl"&gt;"sku"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"AZ-DOCK"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"requested"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"onHand"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;}]}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Part 3's run file could produce both of those responses. What it could not produce is the next block. The dashboard's trace detail for &lt;code&gt;order-service: POST /orders/&lt;/code&gt; reports Duration 0.18s, Resources 4, Depth 5, Total spans 7, and the tree behind those numbers is this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;POST /orders/                                     order-service
  HTTP POST 200                                   order-service
    HTTP POST                                     order-service-dapr-cli
      CallLocal/inventory-service/stock/check     inventory-service-dapr-cli
        POST /stock/check                         inventory-service
  DATA state /dapr.proto.runtime.v1.Dapr/SaveState  order-service-dapr-cli
  HTTP POST 200 order-service-dapr-cli            order-service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The right-hand column is the resource each span came from, and it is the column that makes this worth printing. Both &lt;code&gt;*-dapr-cli&lt;/code&gt; resources are in it. The sidecar is not a black box that the trace jumps over: &lt;code&gt;order-service-dapr-cli&lt;/code&gt; records the outbound &lt;code&gt;HTTP POST&lt;/code&gt; it received, and &lt;code&gt;inventory-service-dapr-cli&lt;/code&gt; records &lt;code&gt;CallLocal/inventory-service/stock/check&lt;/code&gt;, the sidecar-to-sidecar hop, as a real span with the callee's own ASP.NET Core span nested underneath it. The &lt;code&gt;SaveState&lt;/code&gt; call is there too, as its own span on the order sidecar, tagged with the gRPC method the SDK actually invoked (&lt;code&gt;/dapr.proto.runtime.v1.Dapr/SaveState&lt;/code&gt;) rather than with anything the application wrote. Four resources, one trace, and not a line of telemetry configuration in either &lt;code&gt;Program.cs&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Two separate things have to be true for that tree to exist, and only one of them is about the dashboard. The first is instrumentation: the single &lt;code&gt;AddServiceDefaults&lt;/code&gt; call in each service registers inbound ASP.NET Core instrumentation on both services and outbound &lt;code&gt;HttpClient&lt;/code&gt; instrumentation on the caller, so order-service writes a &lt;code&gt;traceparent&lt;/code&gt; on the way out and inventory-service reads one on the way in. The second is delivery: the AppHost sets &lt;code&gt;OTEL_EXPORTER_OTLP_ENDPOINT&lt;/code&gt; on the two service processes &lt;em&gt;and&lt;/em&gt; on the two &lt;code&gt;dapr run&lt;/code&gt; executables, along with the protocol, a per-resource &lt;code&gt;OTEL_SERVICE_NAME&lt;/code&gt; and the dashboard's OTLP API key, so all four processes ship to the same collector without any of them knowing where it is. Miss the difference between those two and you will draw the wrong conclusion the first time a trace comes back fragmented: curl a callee directly, with no caller upstream, and you get a separate trace with a single span in it, because spans link on propagated context and not on a shared destination.&lt;/p&gt;

&lt;p&gt;Before you build a habit around that dashboard, know what it is and is not. Its telemetry is capped at 10,000 traces and 10,000 logs shared across every resource, and &lt;a href="https://aspire.dev/dashboard/standalone/" rel="noopener noreferrer"&gt;Microsoft's own framing of the scope&lt;/a&gt; is that "the dashboard is designed as a development and short-term diagnostic tool", which "persists telemetry in-memory" and where "no telemetry is persisted when the dashboard is restarted". And you reach it through a one-time &lt;code&gt;?t=&lt;/code&gt; token, which is regenerated on every launch, on whichever port the template wrote into the AppHost's &lt;code&gt;launchSettings.json&lt;/code&gt; when it scaffolded the project. That port is randomised once, at scaffold time, and then pinned: 17004 for this sample on every run, and some other five-digit number for yours. Either way, any instruction that tells you to browse to &lt;code&gt;localhost:18888&lt;/code&gt; is describing the standalone dashboard container, not the one &lt;code&gt;aspire run&lt;/code&gt; just printed a URL for.&lt;/p&gt;

&lt;p&gt;One open risk belongs here rather than in a footnote, because it is specifically a multi-sidecar risk. &lt;a href="https://github.com/CommunityToolkit/Aspire/issues/1509" rel="noopener noreferrer"&gt;CommunityToolkit/Aspire#1509&lt;/a&gt;, open since August 2026, reports one sidecar per launch dying while the dashboard continues to show it as &lt;code&gt;Finished&lt;/code&gt;, with a rotating victim and the &lt;code&gt;dapr&lt;/code&gt; CLI's serialised startup as the suspected cause. I never saw it across three launches on Aspire 13.5.3 with toolkit 13.0.0: both sidecars reached &lt;code&gt;Running&lt;/code&gt;, stayed there, answered &lt;code&gt;/v1.0/metadata&lt;/code&gt; and contributed spans every time. Three launches against a race, with no attempt on my part to provoke it, is evidence of absence and not much more. Read it as a reason to check the resource list rather than as a reason to assume the issue is gone.&lt;/p&gt;

&lt;h3&gt;
  
  
  Restarting the app proves nothing about durability
&lt;/h3&gt;

&lt;p&gt;The dashboard puts a Restart button next to every resource, which makes it the obvious way to answer "does my data survive a restart?". It answers a different question.&lt;/p&gt;

&lt;p&gt;Restart &lt;code&gt;order-service&lt;/code&gt; from the dashboard and the app process is genuinely replaced: PID 54221 became PID 60531, and the start time in the resource list moved with it. Neither daprd moved. &lt;code&gt;order-service-dapr-cli&lt;/code&gt; stayed on PID 54223 with the dashboard still showing its original start time, and &lt;code&gt;inventory-service-dapr-cli&lt;/code&gt; stayed on 54222. The sidecar is a top-level resource in its own right, and restarting its app does not touch it.&lt;/p&gt;

&lt;p&gt;That is a useful property most of the time and a trap once. Because the sidecar survives, anything the sidecar was holding survives with it, and a state store living inside daprd's own memory is exactly that. &lt;code&gt;GET /orders/ORD-1001&lt;/code&gt; on an order written before the restart came back HTTP 200 on the configuration with no &lt;code&gt;LocalPath&lt;/code&gt; set, the one that resolves to &lt;code&gt;state.in-memory&lt;/code&gt;. The store that loses everything the moment the sidecar dies passes the restart-the-app test with full marks. Restart the &lt;code&gt;*-dapr-cli&lt;/code&gt; resource instead and the two configurations finally disagree: 404 with the generated in-memory component, 200 with the repository's Redis one. That is the test worth writing down.&lt;/p&gt;

&lt;p&gt;Two small details from the same menu. An app resource offers Stop, Restart and Rebuild; a &lt;code&gt;*-dapr-cli&lt;/code&gt; resource offers Stop and Restart with no Rebuild, which is one more reminder that the sidecar is an executable Aspire launched and not a project it built. And Restart is not Rebuild even where both exist: the product's own description of it is "Source code is not recompiled."&lt;/p&gt;

&lt;h3&gt;
  
  
  If you switch to the http profile
&lt;/h3&gt;

&lt;p&gt;The AppHost template writes two launch profiles, &lt;code&gt;https&lt;/code&gt; and &lt;code&gt;http&lt;/code&gt;, and on Aspire 13.5.3 the second one does not start:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Unhandled exception. System.AggregateException: One or more errors occurred. (The 'applicationUrl'
setting must be an https address unless the 'ASPIRE_ALLOW_UNSECURED_TRANSPORT' environment variable
is set to true. ...)
 ---&amp;gt; Microsoft.Extensions.Options.OptionsValidationException: The 'applicationUrl' setting must be
an https address unless the 'ASPIRE_ALLOW_UNSECURED_TRANSPORT' environment variable is set to true.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The template-generated &lt;code&gt;http&lt;/code&gt; profile does not set that variable, so the profile the template ships is dead on arrival. This is the good kind of failure: loud, immediate, and naming the variable it wants.&lt;/p&gt;

&lt;p&gt;Getting far enough to see it is the awkward half. &lt;code&gt;aspire run&lt;/code&gt; has no &lt;code&gt;--launch-profile&lt;/code&gt; flag at all, and with &lt;code&gt;AspireUseCliBundle=true&lt;/code&gt; the &lt;code&gt;dotnet run --launch-profile http&lt;/code&gt; you would reach for next is routed through &lt;code&gt;aspire run&lt;/code&gt; and the profile is dropped on the floor: the AppHost came up with &lt;code&gt;DOTNET_LAUNCH_PROFILE=https&lt;/code&gt; regardless, with nothing in the output admitting the switch was ignored. Any instruction of the form "run it with the http profile" has to say how, which in this case meant running the built AppHost binary directly with the profile's environment variables set by hand.&lt;/p&gt;

&lt;p&gt;Once &lt;code&gt;ASPIRE_ALLOW_UNSECURED_TRANSPORT=true&lt;/code&gt; is set and the app comes up, the interesting part is that nothing about the trace changes. Same tree, 4 resources, depth 5, 7 spans, both sidecars contributing, over a plain http OTLP endpoint, with &lt;code&gt;OTEL_EXPORTER_OTLP_INSECURE&lt;/code&gt; never set on either daprd process. The insecure-endpoint story you may have read about Dapr and OTLP is not what bites you on this stack; the launch profile is.&lt;/p&gt;

&lt;p&gt;One more observation from reading those environments, because it explains where the sidecars' configuration is &lt;em&gt;not&lt;/em&gt; coming from. Both daprd processes were started with &lt;code&gt;--config ~/.dapr/config.yaml&lt;/code&gt;, and that flag arrives the same way &lt;code&gt;--components-path&lt;/code&gt; does: it is the &lt;code&gt;dapr&lt;/code&gt; CLI's own default, not something the integration passed. The file it points at declares only a Zipkin exporter and has no OTLP section anywhere in it, yet both sidecars exported to the dashboard anyway. daprd 1.18.3 honours the &lt;code&gt;OTEL_EXPORTER_OTLP_*&lt;/code&gt; variables independently of the Dapr Configuration resource. I did not check whether the spans reached Zipkin at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the model stops
&lt;/h2&gt;

&lt;p&gt;Everything above is one machine. The introduction called the AppHost a development-time orchestrator on Microsoft's own authority, and this is the section that says what that costs you, because the parts of the model that do not cross the deployment boundary do not announce that they are staying behind.&lt;/p&gt;

&lt;p&gt;Start with the components, because that is the one people find last. An AppHost carrying &lt;code&gt;AddAzureContainerAppEnvironment("cae").WithDaprComponents()&lt;/code&gt; alongside an &lt;code&gt;AddDaprStateStore&lt;/code&gt; and an &lt;code&gt;AddDaprPubSub&lt;/code&gt; publishes cleanly: &lt;code&gt;aspire publish -o ./out&lt;/code&gt; reported all five steps succeeded. The &lt;code&gt;cae.bicep&lt;/code&gt; it wrote contains a managed identity, a container registry, a role assignment, a Log Analytics workspace, the &lt;code&gt;Microsoft.App/managedEnvironments&lt;/code&gt; resource itself, the dashboard's &lt;code&gt;dotNetComponents&lt;/code&gt; resource, and the outputs. It contains no &lt;code&gt;Microsoft.App/managedEnvironments/daprComponents&lt;/code&gt; resource of any kind. The two components declared in C# have no representation anywhere in the emitted infrastructure.&lt;/p&gt;

&lt;p&gt;Reading the publishing code explains that rather than excusing it. &lt;code&gt;WithDaprComponents&lt;/code&gt; invokes a component's publishing action only when that component carries an &lt;code&gt;AzureDaprComponentPublishingAnnotation&lt;/code&gt;, and a plain &lt;code&gt;AddDaprStateStore&lt;/code&gt; is never given one. The annotation comes from the Azure helper packages, in practice from &lt;code&gt;CommunityToolkit.Aspire.Hosting.Azure.Dapr.Redis&lt;/code&gt;, and only when you call &lt;code&gt;WithReference&lt;/code&gt; on the component with an &lt;code&gt;AddAzureManagedRedis&lt;/code&gt; resource as the argument; &lt;code&gt;AddRedis&lt;/code&gt; and &lt;code&gt;AddAzureRedis&lt;/code&gt; do not qualify, and neither does the local YAML file that made everything work on your laptop. The place not to look for the missing components is azd. It deploys the bicep it was handed, and the bicep never had them.&lt;/p&gt;

&lt;p&gt;Sidecar enablement does survive publish, and one value in it needs checking before anything reaches a cluster:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dapr: { enabled: true, appId: 'svc', appProtocol: 'http', appPort: 8080, logLevel: 'info', enableApiLogging: false }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That &lt;code&gt;appPort&lt;/code&gt; was not inferred. The probe container behind that line listens on 80, and the bicep still said 8080, because the publishing code falls back to a literal 8080 whenever &lt;code&gt;DaprSidecarOptions.AppPort&lt;/code&gt; is unset. Port inference from the app's allocated endpoint happens at run time only, and has no publish-mode equivalent. A container that does not happen to listen on 8080 gets a deployed sidecar that cannot reach it, and the first symptom is a health check rather than an error about ports.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;AppPort&lt;/code&gt; is also one of the survivors, which is the more useful way to read that line. Of the 32 properties on &lt;code&gt;DaprSidecarOptions&lt;/code&gt;, the publishing path translates five into an ACA sidecar: &lt;code&gt;AppId&lt;/code&gt;, &lt;code&gt;AppPort&lt;/code&gt;, &lt;code&gt;EnableApiLogging&lt;/code&gt;, &lt;code&gt;LogLevel&lt;/code&gt; and &lt;code&gt;AppProtocol&lt;/code&gt;. The other 27 have no destination in the emitted bicep, including every &lt;code&gt;AppHealth*&lt;/code&gt; property, the port overrides, &lt;code&gt;ResourcesPaths&lt;/code&gt;, and &lt;code&gt;Config&lt;/code&gt;. &lt;code&gt;Config&lt;/code&gt; being dropped costs nothing in practice, because &lt;a href="https://learn.microsoft.com/azure/container-apps/dapr-overview" rel="noopener noreferrer"&gt;Azure Container Apps lists the Dapr Configuration spec first among the things it does not support&lt;/a&gt;: the capability is not available on that platform whether Aspire forwards the setting or not.&lt;/p&gt;

&lt;p&gt;Which matters mostly because Aspire never writes a Dapr &lt;code&gt;Configuration&lt;/code&gt; resource in the first place. The integration passes &lt;code&gt;--config&lt;/code&gt; only when you point &lt;code&gt;DaprSidecarOptions.Config&lt;/code&gt; at a file you wrote yourself, and there is no C# surface that produces one. Tracing sampling rates, mTLS, access control lists, resiliency policies, middleware pipelines: all of it is hand-written YAML on the local side, and a separate question again about what the target platform accepts.&lt;/p&gt;

&lt;p&gt;Line those up and they resolve into one uncomfortable symmetry. &lt;code&gt;components/statestore.yaml&lt;/code&gt;, the one file you had to write by hand because the generated alternative was an in-memory store, is the artifact from this whole exercise that crosses the boundary intact. It is a real file, in source control, describing a real Redis instance, and getting it onto Container Apps or Kubernetes is an ordinary deployment problem with ordinary answers. The component the AppHost wrote for you lived in a temp directory that was deleted at shutdown and has no counterpart on the far side of publish. The half you had to do by hand is the half that ships.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Both files are deleted at the deployment boundary, so whatever the C# one is worth had to show up before then, and it does. One &lt;code&gt;aspire run&lt;/code&gt; started four processes, held the caller back until the callee's health check answered rather than until it happened to be up, and put seven spans from four resources into one trace, with no line in either &lt;code&gt;Program.cs&lt;/code&gt; naming a collector, a port, or the other service. &lt;code&gt;dapr run -f .&lt;/code&gt; starts the same four processes and hands you back a terminal.&lt;/p&gt;

&lt;p&gt;What you give up for it is one thing rather than a list. Everything the AppHost inferred for you it inferred at run time and nowhere else: the component YAML, the wiring, the ports, the health-gated ordering. None of it is waiting on the far side of &lt;code&gt;aspire publish&lt;/code&gt;, and the one Dapr artifact the AppHost could not generate, because the generated version would have quietly lost your data, is the one you can actually deploy. Treat that as the rule for how much of this model to trust: whatever the AppHost saved you from writing, you will write eventually, and the sooner you write it the less of it is a surprise.&lt;/p&gt;

&lt;p&gt;Part 5 takes the same boundary from the other side, moving an existing Functions app across it one piece at a time, and works out what happens when Dapr's built-in service-invocation retries, the standard resilience handler ServiceDefaults installs on every &lt;code&gt;HttpClient&lt;/code&gt;, and your own retry loop all fire on the same failed request.&lt;/p&gt;

</description>
      <category>azure</category>
      <category>dotnet</category>
      <category>cloudnative</category>
      <category>aspire</category>
    </item>
  </channel>
</rss>
