Search code examples
azureterraformterraform-provider-azure

Terraform, Azure and AKS, can I create a route table to a NAT GW in a peered vnet?


I have a Hub & Spoke network with an AKS in one spoke:

                            [NAT GW]
[Hub Vnet]  <--peering--> [Spoke Vnet]
                             [AKS]

Maybe over-engineering here, but I would like to move the NAT Gateway to the hub:

 [NAT GW]
[Hub Vnet]  <--peering--> [Spoke Vnet]
                             [AKS]

Is it possible to get the Spoke Vnet, or rather the routing table for AKS, to route 0.0.0.0/0-traffic to the hub GW? I only manage to make it work through Terraform as in the first sketch. The VNet and NAT config with peering is working fine, what I don't seem to get working is the network_profile setup in AKS.


Solution

  • Yep, you can totally do this. The docs are ok : https://learn.microsoft.com/en-us/azure/aks/egress-outboundtype#outbound-type-of-userdefinedrouting

    You simply need to specify a different outboundType in the network profile. When you do this, it will check to make sure that a UDR is in place on the subnet, so you really need to make sure all of the config is sequenced correctly.

    enter image description here