<?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: david</title>
    <description>The latest articles on DEV Community by david (@dwoitzik).</description>
    <link>https://dev.to/dwoitzik</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3933869%2F1fb8aa5b-2239-46a7-bf78-b5352809883c.png</url>
      <title>DEV Community: david</title>
      <link>https://dev.to/dwoitzik</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dwoitzik"/>
    <language>en</language>
    <item>
      <title>Breaking the Loop: Solving Circular Dependencies in Azure Firewall Routing with Terraform</title>
      <dc:creator>david</dc:creator>
      <pubDate>Fri, 15 May 2026 20:39:45 +0000</pubDate>
      <link>https://dev.to/dwoitzik/breaking-the-loop-solving-circular-dependencies-in-azure-firewall-routing-with-terraform-2dbe</link>
      <guid>https://dev.to/dwoitzik/breaking-the-loop-solving-circular-dependencies-in-azure-firewall-routing-with-terraform-2dbe</guid>
      <description>&lt;p&gt;You add a Route Table to force all internet-bound traffic (&lt;code&gt;0.0.0.0/0&lt;/code&gt;) from your Spoke VNets into an Azure Firewall. You run &lt;code&gt;terraform plan&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;Error: Cycle: azurerm_subnet_route_table_association.spoke_binding,
azurerm_route_table.spoke_udr, azurerm_firewall.fw ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Terraform has deadlocked. And even if you fix the cycle — a plain &lt;code&gt;0.0.0.0/0&lt;/code&gt; route will silently break Windows VM activation and Managed Identity authentication three days later.&lt;/p&gt;

&lt;p&gt;Here's why both happen and how to fix them cleanly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Cycle Error
&lt;/h2&gt;

&lt;p&gt;Terraform can't resolve the dependency graph:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Route Table needs the Firewall's &lt;code&gt;private_ip_address&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;The Firewall needs &lt;code&gt;AzureFirewallSubnet&lt;/code&gt; to exist first&lt;/li&gt;
&lt;li&gt;The Subnet Association tries to bind everything simultaneously&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;The fix:&lt;/strong&gt; directly reference &lt;code&gt;azurerm_firewall.fw.ip_configuration[0].private_ip_address&lt;/code&gt; in the Route Table. Terraform can now unambiguously resolve the order:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Firewall → (has IP) → Route Table → Subnet Association
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;No workarounds. Just correct resource ordering.&lt;/p&gt;

&lt;h2&gt;
  
  
  The PaaS Trap
&lt;/h2&gt;

&lt;p&gt;Once the cycle is fixed, most engineers celebrate and move on. Three days later:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Windows VMs lose activation&lt;/strong&gt; — Azure KMS traffic is trapped by &lt;code&gt;0.0.0.0/0&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Managed Identities stop authenticating&lt;/strong&gt; — Azure AD traffic hits the unconfigured firewall&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The fix is two explicit bypass routes that must exist &lt;em&gt;before&lt;/em&gt; the Route Table is attached to any subnet:&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;# KMS Bypass — required for Windows VM activation&lt;/span&gt;
&lt;span class="c1"&gt;# 23.102.135.246/32 is Azure's global KMS endpoint (officially documented)&lt;/span&gt;
&lt;span class="nx"&gt;route&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;"bypass-azure-kms"&lt;/span&gt;
  &lt;span class="nx"&gt;address_prefix&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"23.102.135.246/32"&lt;/span&gt;
  &lt;span class="nx"&gt;next_hop_type&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Internet"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;# Azure AD Bypass — prevents Managed Identity auth lockouts&lt;/span&gt;
&lt;span class="nx"&gt;route&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;"bypass-azure-ad"&lt;/span&gt;
  &lt;span class="nx"&gt;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="nx"&gt;next_hop_type&lt;/span&gt;  &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Internet"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;code&gt;next_hop_type = "Internet"&lt;/code&gt; for Azure-owned IP ranges routes traffic over Azure's internal backbone — it never leaves Microsoft's network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scaling to Multiple Spokes
&lt;/h2&gt;

&lt;p&gt;Instead of duplicating the association resource for every Spoke, use &lt;code&gt;for_each&lt;/code&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;resource&lt;/span&gt; &lt;span class="s2"&gt;"azurerm_subnet_route_table_association"&lt;/span&gt; &lt;span class="s2"&gt;"spoke_routing"&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;spoke_subnet_ids&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;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;route_table_id&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;azurerm_route_table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;spoke_udr&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;Add a new Spoke to the variable map, run &lt;code&gt;terraform apply&lt;/code&gt; — done.&lt;/p&gt;




&lt;p&gt;The free baseline (cycle fix + route table structure) is on GitHub. The full article with complete code, IP Group scaling, and FQDN baseline policies is on my blog.&lt;/p&gt;

&lt;p&gt;👉 &lt;a href="https://woitzik.dev/blog/azure-firewall-cycle-error" rel="noopener noreferrer"&gt;Full article on woitzik.dev&lt;/a&gt;&lt;br&gt;&lt;br&gt;
👉 &lt;a href="https://github.com/dwoitzik/azure-firewall-forced-tunneling" rel="noopener noreferrer"&gt;Free GitHub repo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>terraform</category>
      <category>azure</category>
      <category>devops</category>
      <category>security</category>
    </item>
  </channel>
</rss>
