<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by MM_Diaries on Medium]]></title>
        <description><![CDATA[Stories by MM_Diaries on Medium]]></description>
        <link>https://medium.com/@mm_diaries?source=rss-ec6397688155------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*v87GvIM0fjX-nOlRXIAk5A.jpeg</url>
            <title>Stories by MM_Diaries on Medium</title>
            <link>https://medium.com/@mm_diaries?source=rss-ec6397688155------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:51:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mm_diaries/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Making Complex Azure Deployments Simple with Bicep Functions]]></title>
            <link>https://medium.com/@mm_diaries/making-complex-azure-deployments-simple-with-bicep-functions-11d3d859946e?source=rss-ec6397688155------2</link>
            <guid isPermaLink="false">https://medium.com/p/11d3d859946e</guid>
            <category><![CDATA[azure-devops]]></category>
            <category><![CDATA[nested-loop]]></category>
            <category><![CDATA[microsoft-azure]]></category>
            <category><![CDATA[azure-bicep]]></category>
            <dc:creator><![CDATA[MM_Diaries]]></dc:creator>
            <pubDate>Sun, 16 Nov 2025 14:44:32 GMT</pubDate>
            <atom:updated>2025-11-16T15:08:08.800Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n-yxLve45xWyAPWd8QjnMg.png" /></figure><p>When you start writing Bicep, everything feels simple..until you try to model a real Azure service with multiple levels of configuration.<br>You quickly discover that Bicep doesn’t allow <em>nested</em> loops inside a resource. Meanwhile, Azure services often depend on <strong>hierarchical structures</strong>.</p><p>This is where <strong>Bicep functions</strong> become essential.<br>They let you reshape your data so it fits the flat, predictable format Azure resources expect.</p><p>Let’s look at three functions that really simplified my own Bicep deployments and how i’ve used them to handle a Topics → Subscriptions → Rules setup</p><h3>Why Bicep Functions Matter</h3><p>Most Azure services are naturally structured in layers:</p><ul><li>Event Grid → Topics → Subscriptions</li><li>API Management → APIs → Operations → Policies</li><li>Storage → Containers → Access rules</li><li>Service Bus → Topics → Subscriptions → Rules</li></ul><p>But Bicep’s resource loops can only handle <strong>one level at a time</strong>.</p><p>This isn’t a limitation but it’s how declarative languages maintain predictable deployments.<br>To work with deeper hierarchies, we use Bicep functions to prepare the data.</p><h3>The Functions That Do the Hard Work</h3><h3>1. map() : Transform each item in a list</h3><p>map() walks through a list and produces a <strong>reshaped version</strong> of each item.</p><p><strong>(Bicep code)</strong></p><pre>map([&#39;a&#39;, &#39;b&#39;], x =&gt; &#39;${x}-done&#39;)</pre><p>Output:</p><pre>[&#39;a-done&#39;, &#39;b-done&#39;]</pre><h3>2. Loop indexes : Knowing where you are</h3><p><strong>(Bicep code)</strong></p><pre>for (topic, i) in topics:</pre><p>i simply tells you the position of the topic (i.e., its the index) (0, 1, 2…).<br>This becomes helpful when building structured objects that keep track of where they came from.</p><h3>3. flatten() : Turn nested lists into a single list</h3><p>Whenever you do transformations at multiple levels, you usually end up with a list of lists:</p><pre>[<br>  [A, B],<br>  [C],<br>  [D, E]<br>]</pre><p>flatten() turns it into:</p><pre>[A, B, C, D, E]</pre><p>Exactly what Azure expects.</p><h3>Why You Can’t Use Nested Loops in Bicep</h3><p>If your hierarchy is:</p><p><strong>Topic → Subscription → Rule</strong></p><p>You might want to write something like:</p><p><strong>(Bicep code: <em>invalid</em>)</strong></p><pre>resource rules = [<br>  for topic in topics:<br>    for sub in topic.subscriptions:<br>      for rule in sub.rules: {<br>        ...<br>      }<br>]</pre><p>Bicep won’t allow this.<br>It supports <strong>one loop per resource</strong>, and only one.</p><p>So instead of forcing loops, we reshape the data with functions.</p><h3>A Simple Example: Topics → Subscriptions → Rules</h3><p>Imagine your configuration as below:</p><pre>Topic A<br>  Sub1<br>    Rule1<br>    Rule2<br>  Sub2<br>    Rule3<br><br>Topic B<br>  Sub3<br>    Rule4</pre><p>We need to convert this hierarchy into a <strong>flat list of rule objects</strong> that Azure can deploy.</p><h3>Step 1: Loop through topics and reshape subscriptions</h3><p>We begin by looping over the list of topics.<br>Inside that loop, we use <strong>map()</strong> to turn each subscription into a simple object that also includes its topic’s index.</p><p><strong>(Bicep code)</strong></p><pre>var subscriptionsByTopic = [<br>  for (topic, topicIndex) in topics: map(topic.subscriptions, subscription =&gt; {<br>    topicIndex: topicIndex<br>    name: subscription.name<br>    rules: subscription.rules<br>  })<br>]</pre><p>What this produces (conceptually):</p><pre>[<br>  [ subscriptions under topic 0 ],<br>  [ subscriptions under topic 1 ],<br>  [ subscriptions under topic 2 ]<br>]</pre><p>This gives us groups of subscriptions by topic which is great for structure,<br>but <strong>not</strong> deployable yet because it’s a nested list.</p><h3>Step 2: Flatten the subscriptions</h3><p>We collapse all those small lists into one clean list:</p><p><strong>(Bicep code)</strong></p><pre>var subscriptions = flatten(subscriptionsByTopic)</pre><p>Now we have something like:</p><pre>[<br>  subA_of_topic0,<br>  subB_of_topic0,<br>  subC_of_topic1,<br>  ...<br>]</pre><p>This flat list is now perfect for the subscription resource loop</p><h3>Step 3: Build rule objects from the flattened subscription list</h3><p>Now that subscriptions are flat, we can process rules.</p><p>Each subscription may have a list of rules, so we loop over the subscriptions and use <strong>map()</strong> to turn each rule into a clean object that carries:</p><ul><li>which topic it belongs to</li><li>which subscription it belongs to</li><li>its rule name and properties if present</li></ul><p><strong>(Bicep code)</strong></p><pre>var rulesBySubscription = [<br>  for (subscription, subscriptionIndex) in subscriptions: map(subscription.rules, rule =&gt; {<br>    topicIndex: subscription.topicIndex<br>    subscriptionIndex: subscriptionIndex<br>    name: rule.name<br>  })<br>]</pre><p>Again, this produces a <strong>list of lists</strong> because every subscription may have multiple rules.</p><h3>Step 4: Flatten the rules</h3><p>We merge those small rule lists into a single, clean array:</p><p><strong>(Bicep code)</strong></p><pre>var rules = flatten(rulesBySubscription)</pre><p>Now the structure is:</p><pre>[<br>  rule1_under_sub0,<br>  rule2_under_sub0,<br>  rule_under_sub1,<br>  ...<br>]</pre><p>This single array is precisely what Azure expects for a resource loop.</p><h3>Step 5: Deploy using clean, flat lists</h3><p>Deploying becomes simple because we already did all the reshaping earlier.</p><p><strong>(Bicep code: simplified for clarity)</strong></p><pre>resource subscriptionResources = [<br>  for s in subscriptions: {<br>    name: s.name<br>    parent: topics[s.topicIndex]<br>  }<br>]<br><br>resource ruleResources = [<br>  for r in rules: {<br>    name: r.name<br>    parent: subscriptionResources[r.subscriptionIndex]<br>  }<br>]</pre><p>No nested loops.<br>No complex transformations inside the resource block.</p><p>Just clean data → clean resources.</p><h3>Final Takeaway</h3><p>If you’re working with deeply nested Azure structures, remember:</p><ul><li><strong>map() reshapes your data</strong></li><li><strong>indexes preserve the hierarchy</strong></li><li><strong>flatten() collapses nesting</strong></li><li><strong>and Bicep stays clean and declarative</strong></li></ul><p>Once you apply this pattern, complex Azure deployments start feeling surprisingly simple and even enjoyable.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11d3d859946e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[When loadJsonContent() Hit a Wall: How I Moved JSON Configuration Loading from Bicep to YAML]]></title>
            <link>https://medium.com/@mm_diaries/when-loadjsoncontent-hit-a-wall-how-i-moved-json-configuration-loading-from-bicep-to-yaml-00c6ccdc63f2?source=rss-ec6397688155------2</link>
            <guid isPermaLink="false">https://medium.com/p/00c6ccdc63f2</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[yaml]]></category>
            <category><![CDATA[infrastructure-as-code]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[bicep]]></category>
            <dc:creator><![CDATA[MM_Diaries]]></dc:creator>
            <pubDate>Wed, 22 Oct 2025 17:48:37 GMT</pubDate>
            <atom:updated>2025-10-22T17:48:37.976Z</atom:updated>
            <content:encoded><![CDATA[<p>In large Azure projects, configuration management can get complex fast.<br>We maintain several JSON files, for example:</p><ul><li>queues.json and topics.json for Service Bus queues and topics</li><li>bicepparam.json for standard Bicep parameters</li></ul><p>Our idea was simple:<br>👉 <em>Why not just reference these JSON files directly in Bicep using </em><em>loadJsonContent()?</em></p><p>That way, we could keep configurations neatly externalized while deploying everything in a single ARM/Bicep deployment.</p><p>Turns out, it wasn’t that simple.</p><h3><strong>The Problem: Parameterised Paths Don’t Work with </strong><strong>loadJsonContent()</strong></h3><p>Bicep’s loadJsonContent() works beautifully but only when given a <strong>literal string</strong>.</p><p>For example, this works fine:</p><p>📘 Bicep snippet:</p><pre>var queueConfig = loadJsonContent(&#39;config/queues.json&#39;)</pre><p>❌ Won’t work (parameterised path):</p><pre>var queueConfig = loadJsonContent(&#39;config/${environment}/queues.json&#39;)</pre><p>If you try this, Bicep throws an error saying the function expects a <strong>compile-time constant</strong>. That means you can’t dynamically load environment specific JSON files at deployment time.</p><p>For a setup like ours with multiple environments (dev, stage, prod), this limitation made loadJsonContent() unusable.</p><h3><strong>The Pivot: Moving JSON Loading to YAML</strong></h3><p>Instead of forcing Bicep to do what it couldn’t, we changed our approach.<br>We decided to <strong>remove JSON loading from Bicep</strong> altogether and handle it at the pipeline level using <strong>Azure CLI tasks</strong>.</p><p>This gave us more control, flexibility, and fewer surprises during deployments.</p><h3>The YAML Setup</h3><p>We started by maintaining a simple variable file (let’s call it vars.yml) for pipeline level configurations which had to be loaded before the pipeline logic starts. It included project wide values such as environment, subscription IDs, service connection, agent pool, and we also added paths to environment specific JSON files. These vars.yml files are created separately for each environment ( Eg: dev.yml, qa.yml etc., )</p><p>Here’s a simplified example:</p><pre>variables:<br>  subscriptionId: &#39;xxxx-xxxx-xxxx&#39;<br>  serviceConnection: &#39;My-SPN&#39;<br>  agentPool: &#39;ubuntu-latest&#39;<br>  parametersFile: &#39;config/dev/parameters.json&#39;<br>  queuesConfigPath: &#39;config/dev/queues.json&#39;<br>  topicsConfigPath: &#39;config/dev/topics.json&#39;</pre><h3>Updating Bicep Parameters</h3><p>Since we planned to pass JSON files directly through the Azure CLI, we updated our Bicep file to accept these as <strong>array parameters</strong>.</p><pre>@description(&#39;Service Bus queues configuration&#39;)<br>param queueConfig array<br><br>@description(&#39;Service Bus topics configuration&#39;)<br>param topicConfig array</pre><p>This way, Bicep can receive parsed JSON objects for queues and topics, instead of trying to load them internally.</p><h3><strong>Referencing JSON Paths in Azure CLI Tasks</strong></h3><p>Now that the Bicep parameters were ready to accept objects, we updated our YAML pipeline to use the <strong>Azure CLI task</strong>.<br>The key here is that Azure CLI allows you to <strong>reference JSON files directly</strong> using the @ symbol so no need to manually read or encode them. This preserves JSON types (objects/arrays) and keeps the pipeline clean.</p><p>Example snippet:</p><pre>- task: AzureCLI@2<br>  inputs:<br>    azureSubscription: $(serviceConnection)<br>    scriptType: pscore<br>    scriptLocation: inlineScript<br>    inlineScript: |<br>      echo &quot;Deploying Service Bus Queues and Topics...&quot;<br>      az deployment group create \<br>        --name sb-deploy-$(environment) \<br>        --resource-group $(resourceGroup) \<br>        --template-file main.bicep \<br>        --parameters @$(parametersFile) \<br>                     queueConfig=@$(queuesConfigPath) \<br>                     topicConfig=@$(topicsConfigPath)</pre><h3>Keeping Bicep Parameters Separate</h3><p>We still maintained a separate bicepparam.json file but it was used only for <strong>standard Bicep parameters</strong> containing all the resource specific parameters like resource name, sku, location etc.,</p><p>There was <strong>no need</strong> to include Service Bus queue or topic configurations inside this file anymore.<br>Those were now fully managed by the YAML pipeline and passed dynamically to Bicep during deployment.</p><p>This kept bicepparam.json clean and reusable across environments, while all environment specific details stayed external.</p><h3>Why This Works Better for Us</h3><ul><li><strong>Dynamic and Flexible Deployments : </strong>No need for hardcoded paths or static templates</li><li><strong>Pipeline Centric Control: </strong>YAML handles environment logic; Bicep stays clean and reusable</li><li><strong>Separation of Concerns: </strong>Configurations live in JSON, logic in Bicep, orchestration in YAML</li><li><strong>Scalable and Debuggable : </strong>It’s easy to trace which JSON config was loaded for which environment</li></ul><h3>Lessons Learned</h3><ul><li>Bicep’s loadJsonContent() is great but only when your paths are static.</li><li>Don’t hesitate to move configuration logic higher up in the deployment chain.</li><li>Azure CLI tasks give more runtime flexibility than ARM deployment tasks.</li><li>Keep environment configuration and Bicep parameters clearly separated, it keeps your templates simpler and cleaner.</li></ul><h3>Final Thoughts</h3><p>Sometimes, the best solution isn’t to push harder against a limitation, it’s to pivot.<br>By moving JSON handling out of Bicep and into YAML, we made our deployments cleaner, dynamic, and easier to scale.</p><p>If you’re struggling with dynamic JSON configuration in Bicep, this approach might just save you a few hours (and a few failed pipeline runs 😅).</p><h3>🧩 Tags:</h3><p>#Azure #Bicep #DevOps #YAMLPipelines #InfrastructureAsCode #CloudAutomation #AzureCLI</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=00c6ccdc63f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>