Skip to content

Commit

Permalink
Merge pull request #1155 from tanmay-j/RTSupportForSubnet
Browse files Browse the repository at this point in the history
Added route table support for subnets
  • Loading branch information
ninjarobot authored Nov 8, 2024
2 parents b16265c + e83891e commit c8c0892
Show file tree
Hide file tree
Showing 9 changed files with 212 additions and 4 deletions.
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Release Notes

## 1.9.4
* Network Security Groups: Use a common protocol in security rules with multiple sources. Defaults to Any if sources use different protocols.
* Virtual Network: Specify the route table for a subnet.

## 1.9.3
* Deployments: Default to resource group location rather than West Europe.
Expand All @@ -14,6 +15,7 @@ Release Notes
* Az: Update `ad` commands to work with latest (breaking) structure.
* PostgreSQL: Fix a number of issues around the introduction of Flexible Servers.


## 1.9.2
* Container Apps: Fix to container registry credential to not emit a secret for a managed identity.
* Container Groups: followup to #ff78f202dc - expand DNS config validation for profile-less vnet.
Expand Down
4 changes: 4 additions & 0 deletions docs/content/api-overview/resources/vnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ The Virtual Network module contains four builders
| link_to_nat_gateway | Specify an existing NAT gateway for the subnet. |
| network_security_group | Specify the network security group from the same deployment. |
| link_to_network_security_group | Specify an existing network security group for this subnet. |
| route_table | Specify the route table from the same deployment. |
| link_to_route_table | Specify an existing route table for this subnet. |
| link_to_vnet | Link a standalone subnet to a vnet in the same template. |
| link_to_unmanaged_vnet | Link a standalone subnet to an existing vnet that is already deployed. |
| add_delegations | Adds one or more delegations to this subnet. |
Expand Down Expand Up @@ -72,6 +74,8 @@ The Virtual Network module contains four builders
| link_to_nat_gateway | Specify an existing NAT gateway for the subnet. |
| network_security_group | Specify the network security group from the same deployment. |
| link_to_network_security_group | Specify an existing network security group for the subnet. |
| route_table | Specify the route table from the same deployment. |
| link_to_route_table | Specify an existing route table for the subnet. |
| add_delegations | Adds service delegations for the subnet. |
| add_service_endpoints | Adds service endpoints for the subnet. |
| add_service_endpoint_policies | Associates the service endpoint policies with the subnet. |
Expand Down
9 changes: 9 additions & 0 deletions src/Farmer/Arm/Network.fs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ type Subnet = {
Name: ResourceName
Prefixes: string list
VirtualNetwork: LinkedResource option
RouteTable: LinkedResource option
NetworkSecurityGroup: LinkedResource option
Delegations: SubnetDelegation list
NatGateway: LinkedResource option
Expand All @@ -351,6 +352,10 @@ type Subnet = {
this.NatGateway
|> Option.map LinkedResource.AsIdObject
|> Option.defaultValue Unchecked.defaultof<_>
routeTable =
this.RouteTable
|> Option.map (fun rt -> {| id = rt.ResourceId.Eval() |})
|> Option.defaultValue Unchecked.defaultof<_>
networkSecurityGroup =
this.NetworkSecurityGroup
|> Option.map (fun nsg -> {|
Expand Down Expand Up @@ -431,6 +436,10 @@ type VirtualNetwork = {
match subnet.NatGateway with
| Some(Managed id) -> id
| _ -> ()

match subnet.RouteTable with
| Some(Managed id) -> id
| _ -> ()
}
|> Set

Expand Down
1 change: 1 addition & 0 deletions src/Farmer/Builders/Builders.NetworkInterface.fs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type NetworkInterfaceConfig = {
Subnet.Name = ResourceName subnetName
Prefixes = [ IPAddressCidr.format subnetPrefix ]
VirtualNetwork = Some(vnetId)
RouteTable = None
NetworkSecurityGroup = None
Delegations = []
NatGateway = None
Expand Down
1 change: 1 addition & 0 deletions src/Farmer/Builders/Builders.RouteServer.fs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ type RouteServerConfig = {
Subnet.Name = ResourceName "RouteServerSubnet"
Prefixes = [ IPAddressCidr.format this.SubnetPrefix ]
VirtualNetwork = Some(vnetId)
RouteTable = None
NetworkSecurityGroup = None
Delegations = []
NatGateway = None
Expand Down
87 changes: 84 additions & 3 deletions src/Farmer/Builders/Builders.VirtualNetwork.fs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SubnetConfig = {
Name: ResourceName
Prefixes: IPAddressCidr list
VirtualNetwork: LinkedResource option
RouteTable: LinkedResource option
NetworkSecurityGroup: LinkedResource option
Delegations: SubnetDelegationService list
NatGateway: LinkedResource option
Expand All @@ -29,6 +30,7 @@ type SubnetConfig = {
Name = this.Name
Prefixes = this.Prefixes |> List.map IPAddressCidr.format
VirtualNetwork = this.VirtualNetwork
RouteTable = this.RouteTable
NetworkSecurityGroup = this.NetworkSecurityGroup
Delegations =
this.Delegations
Expand Down Expand Up @@ -59,6 +61,7 @@ type SubnetBuilder() =
Name = ResourceName.Empty
Prefixes = []
VirtualNetwork = None
RouteTable = None
NetworkSecurityGroup = None
Delegations = []
NatGateway = None
Expand Down Expand Up @@ -164,6 +167,40 @@ type SubnetBuilder() =
NetworkSecurityGroup = Some(Unmanaged (nsg :> IBuilder).ResourceId)
}

/// Sets the route table for subnet
[<CustomOperation "route_table">]
member _.RouteTable(state: SubnetConfig, rt: IArmResource) = {
state with
RouteTable = Some(Managed rt.ResourceId)
}

member _.RouteTable(state: SubnetConfig, rt: ResourceId) = {
state with
RouteTable = Some(Managed rt)
}

member _.RouteTable(state: SubnetConfig, rt: RouteTableConfig) = {
state with
RouteTable = Some(Managed (rt :> IBuilder).ResourceId)
}

/// Links the subnet to an existing route table.
[<CustomOperation "link_to_route_table">]
member _.LinkToRouteTable(state: SubnetConfig, rt: IArmResource) = {
state with
RouteTable = Some(Unmanaged(rt.ResourceId))
}

member _.LinkToRouteTable(state: SubnetConfig, rt: ResourceId) = {
state with
RouteTable = Some(Unmanaged rt)
}

member _.LinkToRouteTable(state: SubnetConfig, rt: RouteTableConfig) = {
state with
RouteTable = Some(Unmanaged (rt :> IBuilder).ResourceId)
}

/// Links the subnet to an managed virtual network.
[<CustomOperation "link_to_vnet">]
member _.LinkToVirtualNetwork(state: SubnetConfig, vnet: IArmResource) = {
Expand Down Expand Up @@ -246,6 +283,7 @@ type SubnetBuildSpec = {
Name: string
Size: int
NetworkSecurityGroup: LinkedResource option
RouteTable: LinkedResource option
Delegations: SubnetDelegationService list
NatGateway: LinkedResource option
ServiceEndpoints: (EndpointServiceType * Location list) list
Expand All @@ -259,6 +297,7 @@ let buildSubnet name size = {
Name = name
Size = size
NetworkSecurityGroup = None
RouteTable = None
Delegations = []
NatGateway = None
ServiceEndpoints = []
Expand All @@ -272,6 +311,7 @@ let buildSubnetDelegations name size delegations = {
Name = name
Size = size
NetworkSecurityGroup = None
RouteTable = None
Delegations = delegations
NatGateway = None
ServiceEndpoints = []
Expand All @@ -284,6 +324,7 @@ let buildSubnetAllowPrivateEndpoints name size = {
Name = name
Size = size
NetworkSecurityGroup = None
RouteTable = None
Delegations = []
NatGateway = None
ServiceEndpoints = []
Expand All @@ -297,6 +338,7 @@ type SubnetSpecBuilder() =
Name = ""
Size = 24
NetworkSecurityGroup = None
RouteTable = None
Delegations = []
NatGateway = None
ServiceEndpoints = []
Expand Down Expand Up @@ -379,6 +421,40 @@ type SubnetSpecBuilder() =
NetworkSecurityGroup = Some(Unmanaged (nsg :> IBuilder).ResourceId)
}

/// Sets the route table for subnet
[<CustomOperation "route_table">]
member _.RouteTable(state: SubnetBuildSpec, rt: IArmResource) = {
state with
RouteTable = Some(Managed rt.ResourceId)
}

member _.RouteTable(state: SubnetBuildSpec, rt: ResourceId) = {
state with
RouteTable = Some(Managed rt)
}

member _.RouteTable(state: SubnetBuildSpec, rt: RouteTableConfig) = {
state with
RouteTable = Some(Managed (rt :> IBuilder).ResourceId)
}

/// Links the subnet to an existing route table.
[<CustomOperation "link_to_route_table">]
member _.LinkToRouteTable(state: SubnetBuildSpec, rt: IArmResource) = {
state with
RouteTable = Some(Unmanaged(rt.ResourceId))
}

member _.LinkToRouteTable(state: SubnetBuildSpec, rt: ResourceId) = {
state with
RouteTable = Some(Unmanaged(rt))
}

member _.LinkToRouteTable(state: SubnetBuildSpec, rt: RouteTableConfig) = {
state with
RouteTable = Some(Unmanaged (rt :> IBuilder).ResourceId)
}

/// Adds any services to delegate this subnet
[<CustomOperation "add_delegations">]
member _.AddDelegations(state: SubnetBuildSpec, delegations) = {
Expand Down Expand Up @@ -447,12 +523,14 @@ type AddressSpaceBuilder() =
?associatedServiceEndpointPolicies: ResourceId list,
?allowPrivateEndpoints: FeatureFlag,
?privateLinkServiceNetworkPolicies: FeatureFlag,
?nsg: LinkedResource
?nsg: LinkedResource,
?rt: LinkedResource
) =
let subnetBuildSpec = {
Name = name
Size = size
NetworkSecurityGroup = nsg
RouteTable = rt
Delegations = delegations |> Option.defaultValue []
NatGateway = None
ServiceEndpoints = serviceEndpoints |> Option.defaultValue []
Expand Down Expand Up @@ -643,7 +721,8 @@ type VirtualNetworkBuilder() =
s.AllowPrivateEndpoints,
s.PrivateLinkServiceNetworkPolicies,
s.NatGateway,
s.NetworkSecurityGroup)
s.NetworkSecurityGroup,
s.RouteTable)
)
|> List.map
(fun
Expand All @@ -654,12 +733,14 @@ type VirtualNetworkBuilder() =
allowPrivateEndpoints,
privateLinkServiceNetworkPolicies,
natGateway,
nsg),
nsg,
rt),
cidr) -> {
Name = ResourceName name
Prefixes = [ cidr ]
VirtualNetwork = Some(Managed(virtualNetworks.resourceId state.Name))
NetworkSecurityGroup = nsg
RouteTable = rt
Delegations = delegations
NatGateway = natGateway
ServiceEndpoints = serviceEndpoints
Expand Down
1 change: 1 addition & 0 deletions src/Farmer/Builders/Builders.Vm.fs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type VmConfig = {
Name = subnetId.Name
Prefixes = [ this.SubnetPrefix ]
VirtualNetwork = Some(Managed vnet)
RouteTable = None
NetworkSecurityGroup = nsgId |> Option.map Managed
Delegations = []
NatGateway = None
Expand Down
2 changes: 1 addition & 1 deletion src/Farmer/Farmer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
<Compile Include="Builders/Builders.Bastion.fs" />
<Compile Include="Builders\Builders.NatGateway.fs" />
<Compile Include="Builders\Builders.NetworkSecurityGroup.fs" />
<Compile Include="Builders\Builders.RouteTable.fs" />
<Compile Include="Builders/Builders.VirtualNetwork.fs" />
<Compile Include="Builders\Builders.LoadBalancer.fs" />
<Compile Include="Builders/Builders.Vm.fs" />
Expand Down Expand Up @@ -187,7 +188,6 @@
<Compile Include="Builders/Builders.OperationsManagement.fs" />
<Compile Include="Builders\Builders.PrivateLink.fs" />
<Compile Include="Builders\Builders.PrivateEndpoint.fs" />
<Compile Include="Builders\Builders.RouteTable.fs" />
<Compile Include="Builders\Builders.HostGroup.fs" />
<Compile Include="Builders\Builders.NetworkInterface.fs" />
<Compile Include="Builders\Builders.RouteServer.fs" />
Expand Down
Loading

0 comments on commit c8c0892

Please sign in to comment.