<p>I have an Azure question. I use terraform in the Azure Cloud service. I try to start up 2 AKS cluster there. But I always get an error that my CIDR settings are wrong.</p>
<p>I use in Cluster one:</p>
<pre><code>resource &quot;azurerm_subnet&quot; &quot;cluster1-node-pool-subnet&quot; {

  name                 = &quot;cluster1-node-pool-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.1.0/19&quot;]

}

resource &quot;azurerm_subnet&quot; &quot;cluster1-execution-nodes-subnet&quot; {

  name                 = &quot;cluster1-execution-nodes-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.33.0/19&quot;]

}

resource &quot;azurerm_subnet&quot; &quot;cluster1-gpu-nodes-subnet&quot; {
  count                = var.gpuNodePool ? 1 : 0
  name                 = &quot;execution-nodes-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.48.0/20&quot;]

}

network_profile {
  network_plugin     = &quot;azure&quot;
  service_cidr       = &quot;10.0.65.0/19&quot;  
  dns_service_ip     = &quot;10.0.65.10&quot;    
  docker_bridge_cidr = &quot;172.17.0.1/16&quot; 
}

</code></pre>
<p>and in Cluster two:</p>
<pre><code>resource &quot;azurerm_subnet&quot; &quot;default-node-pool-subnet&quot; {

  name                 = &quot;default-node-pool-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.0.0/19&quot;]

}

resource &quot;azurerm_subnet&quot; &quot;execution-nodes-subnet&quot; {

  name                 = &quot;execution-nodes-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.32.0/19&quot;]

}

resource &quot;azurerm_subnet&quot; &quot;gpu-nodes-subnet&quot; {
  count                = var.gpuNodePool ? 1 : 0
  name                 = &quot;execution-nodes-subnet&quot;
  resource_group_name  = azurerm_virtual_network.cluster-vnet.resource_group_name
  virtual_network_name = azurerm_virtual_network.cluster-vnet.name
  address_prefixes     = [&quot;10.0.48.0/20&quot;]
}

network_profile {
  network_plugin     = &quot;azure&quot;
  service_cidr       = &quot;10.0.64.0/19&quot;
  dns_service_ip     = &quot;10.0.64.10&quot;
  docker_bridge_cidr = &quot;172.17.0.1/16&quot;
}
</code></pre>
<p>Azur now tell me that the prefix is wrong.</p>
<pre><code>│ Error: creating Subnet: (Name &quot;cluster1-node-pool-subnet&quot; / Virtual Network Name &quot;cluster-vnet&quot; / Resource Group &quot;cluster-infra-network&quot;): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code=&quot;InvalidCIDRNotation&quot; Message=&quot;The address prefix 10.0.1.0/19 in resource /subscriptions/xxx/resourceGroupscluster-infra-network/providers/Microsoft.Network/virtualNetworks/cluster-vnet/subnets/cluster1-node-pool-subnet has an invalid CIDR notation. For the given prefix length, the address prefix should be 10.0.0.0/19.&quot; Details=[]
│
│   with azurerm_subnet.cluster1-node-pool-subnet,
│   on k8s-rtc.tf line 7, in resource &quot;azurerm_subnet&quot; &quot;cluster1-node-pool-subnet&quot;:
│    7: resource &quot;azurerm_subnet&quot; &quot;cluster1-node-pool-subnet&quot; {
│
╵
╷
│ Error: creating Subnet: (Name &quot;cluster1-execution-nodes-subnet&quot; / Virtual Network Name &quot;cluster-vnet&quot; / Resource Group &quot;cluster-infra-network&quot;): network.SubnetsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code=&quot;InvalidCIDRNotation&quot; Message=&quot;The address prefix 10.0.33.0/19 in resource /subscriptions/xxx/resourceGroups/cluster-infra-network/providers/Microsoft.Network/virtualNetworks/cluster-vnet/subnets/cluster1-execution-nodes-subnet has an invalid CIDR notation. For the given prefix length, the address prefix should be 10.0.32.0/19.&quot; Details=[]
│
│   with azurerm_subnet.cluster1-execution-nodes-subnet,
│   on k8s-rtc.tf line 14, in resource &quot;azurerm_subnet&quot; &quot;cluster1-execution-nodes-subnet&quot;:
│   14: resource &quot;azurerm_subnet&quot; &quot;cluster1-execution-nodes-subnet&quot; {
</code></pre>
<p>In my mind the CIDR and prefix are valid. any idea what is wrong?</p>

IFThenElse
<p>There are basically two issues in your subnet definitions:</p>
<ol>
<li><p>Azure tells you that you are using invalid CIDR notations. E.g. in case of <code>cluster1-node-pool-subnet</code> you are specifying in address prefix <code>[&quot;10.0.1.0/19&quot;]</code>. While <code>10.0.1.0/19</code> is a valid IP address, it belongs to the subnet <code>10.0.0.0/19</code> and Azure insists that you need to specify the address prefix based on the network address of the subnet.</p>
<p>The same applies to e.g. <code>10.0.33.0/19</code> which belongs to the subnet <code>10.0.32.0/19</code>.</p>
</li>
<li><p>This unveils the second issue, which Azure will report to you once the first is fixed: In both subnets you are using the same address prefixes in the subnets you are defining. To overcome this you could use e.g. <code>[&quot;10.0.0.0/19&quot;]</code> for <code>cluster1-node-pool-subnet</code> and <code>[&quot;10.1.0.0/19&quot;]</code> for <code>default-node-pool-subnet</code> and so on.</p>
</li>
</ol>
