Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Farmer/Arm/App.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module Farmer.Arm.App
open System
open Farmer.ContainerApp
open Farmer
open Farmer.Arm.ResourceTypes

let containerApps = ResourceType("Microsoft.App/containerApps", "2022-03-01")

Expand Down
2 changes: 1 addition & 1 deletion src/Farmer/Arm/B2cTenant.fs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type B2cTenant =
}

interface IArmResource with
member this.ResourceId = accounts.resourceId this.Name.AsResourceName
member this.ResourceId = b2cTenant.resourceId this.Name.AsResourceName

member this.JsonModel =
{| b2cTenant.Create(this.Name.AsResourceName, this.DataResidency, tags = this.Tags) with
Expand Down
2 changes: 1 addition & 1 deletion src/Farmer/Arm/Bastion.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
module Farmer.Arm.Bastion

open Farmer
open Farmer.Arm.Network
open Farmer.Arm.ResourceTypes.Network
open Farmer.Network

let bastionHosts = ResourceType("Microsoft.Network/bastionHosts", "2023-04-01")
Expand Down
79 changes: 69 additions & 10 deletions src/Farmer/Arm/Compute.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@
module Farmer.Arm.Compute

open Farmer
open Farmer.Arm.ResourceTypes
open Farmer.Arm.ResourceTypes.Storage
open Farmer.DedicatedHosts
open Farmer.Identity
open Farmer.Network
open Farmer.Vm
open System
open System.Text
open Farmer.VmScaleSet

let virtualMachines =
ResourceType("Microsoft.Compute/virtualMachines", "2023-03-01")
let virtualMachines = Compute.virtualMachines

let virtualMachineScaleSets =
ResourceType("Microsoft.Compute/virtualMachineScaleSets", "2023-03-01")
let virtualMachineScaleSets = Compute.virtualMachineScaleSets

let extensions =
ResourceType("Microsoft.Compute/virtualMachines/extensions", "2019-12-01")
let extensions = Compute.extensions

let virtualMachineScaleSetsExtensions =
ResourceType("Microsoft.Compute/virtualMachineScaleSets/extensions", "2023-03-01")
let virtualMachineScaleSetsExtensions = Compute.virtualMachineScaleSetsExtensions

let hostGroups = ResourceType("Microsoft.Compute/hostGroups", "2021-03-01")
let hosts = ResourceType("Microsoft.Compute/hostGroups/hosts", "2021-03-01")
let hostGroups = Compute.hostGroups
let hosts = Compute.hosts

/// Interface to get the properties of a VM extension so it can be added to the
/// extension profile of a VM Scale Set in addition to adding after deployment.
Expand Down Expand Up @@ -180,6 +179,66 @@ type ApplicationHealthExtension =
properties = (this :> IExtension).JsonProperties
|}

/// IP configuration for a network interface.
type IpConfiguration =
{
SubnetName: ResourceName
ApplicationSecurityGroups: LinkedResource list
PublicIpAddress: LinkedResource option
LoadBalancerBackendAddressPools: LinkedResource list
PrivateIpAllocation: AllocationMethod option
PrivateIpAddressVersion: Network.AddressVersion
Primary: bool option
}

/// Serializes to ARM JSON. When serializing for a NetworkInterfaceConfiguration, allocation method is not included.
member ipConfig.ToArmJson(index: int, vnetId: ResourceId, includeAllocationMethod: bool) =
{|
name = $"ipconfig{index + 1}"
properties =
let allocationMethod, ip =
match ipConfig.PrivateIpAllocation with
| Some (StaticPrivateIp ip) -> "Static", string ip
| _ -> "Dynamic", null

{|
applicationSecurityGroups =
match ipConfig.ApplicationSecurityGroups with
| [] -> null
| asgs -> asgs |> List.map LinkedResource.AsIdObject |> Seq.ofList
loadBalancerBackendAddressPools =
match ipConfig.LoadBalancerBackendAddressPools with
| [] -> null // Don't emit the field if there are none set.
| backendPools ->
backendPools
|> List.map (fun lr -> lr.ResourceId |> ResourceId.AsIdObject)
|> box
primary = ipConfig.Primary |> Option.map box |> Option.toObj
privateIPAddressVersion =
match ipConfig.PrivateIpAddressVersion with
| IPv6 -> ipConfig.PrivateIpAddressVersion.ArmValue
| _ -> null // Don't include if IPv4 since this is the default (backwards compatibility)
privateIPAllocationMethod = if includeAllocationMethod then allocationMethod else null
privateIPAddress = ip
publicIPAddress =
ipConfig.PublicIpAddress
|> Option.map (fun pip ->
{|
id = pip.ResourceId.ArmExpression.Eval()
|})
|> Option.defaultValue Unchecked.defaultof<_>
subnet =
{|
id =
{ vnetId with
Type = Network.subnets
Segments = [ ipConfig.SubnetName ]
}
.Eval()
|}
|}
|}

type NetworkInterfaceConfiguration =
{
Name: ResourceName
Expand Down
2 changes: 2 additions & 0 deletions src/Farmer/Arm/ContainerInstance.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ module Farmer.Arm.ContainerInstance

open Farmer
open Farmer.Arm
open Farmer.Arm.ResourceTypes.Network
open Farmer.Arm.ResourceTypes.Storage
open Farmer.ContainerGroup
open Farmer.Identity
open System
Expand Down
1 change: 1 addition & 0 deletions src/Farmer/Arm/ContainerService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
module Farmer.Arm.ContainerService

open Farmer
open Farmer.Arm.ResourceTypes.Network
open Farmer.Identity
open Farmer.Vm

Expand Down
1 change: 0 additions & 1 deletion src/Farmer/Arm/Databricks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module Farmer.Arm.Databricks

open Farmer
open Farmer.Databricks
open Farmer.Arm.Network
open System

let workspaces = ResourceType("Microsoft.Databricks/workspaces", "2018-04-01")
Expand Down
1 change: 1 addition & 0 deletions src/Farmer/Arm/EventHub.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Farmer.Arm.EventHub

open Farmer
open Farmer.EventHub
open Farmer.Arm.ResourceTypes.Storage

let namespaces = ResourceType("Microsoft.EventHub/namespaces", "2017-04-01")

Expand Down
118 changes: 21 additions & 97 deletions src/Farmer/Arm/Network.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,62 +10,48 @@ open Farmer.Route
open Farmer.RouteServer
open Farmer.VirtualNetworkGateway

let connections = ResourceType("Microsoft.Network/connections", "2020-04-01")
let connections = ResourceTypes.Network.connections

let expressRouteCircuits =
ResourceType("Microsoft.Network/expressRouteCircuits", "2019-02-01")
let expressRouteCircuits = ResourceTypes.Network.expressRouteCircuits

let expressRouteCircuitAuthorizations =
ResourceType("Microsoft.Network/expressRouteCircuits/authorizations", "2019-02-01")
ResourceTypes.Network.expressRouteCircuitAuthorizations

let networkInterfaces =
ResourceType("Microsoft.Network/networkInterfaces", "2018-11-01")
let networkInterfaces = ResourceTypes.Network.networkInterfaces

let networkInterfacesIpConfigurations =
ResourceType("Microsoft.Network/networkInterfaces/ipConfigurations", "2023-04-01")
ResourceTypes.Network.networkInterfacesIpConfigurations

let networkProfiles =
ResourceType("Microsoft.Network/networkProfiles", "2020-04-01")
let networkProfiles = ResourceTypes.Network.networkProfiles

let publicIPAddresses =
ResourceType("Microsoft.Network/publicIPAddresses", "2018-11-01")
let publicIPAddresses = ResourceTypes.Network.publicIPAddresses

let publicIPPrefixes =
ResourceType("Microsoft.Network/publicIPPrefixes", "2021-08-01")
let publicIPPrefixes = ResourceTypes.Network.publicIPPrefixes

let serviceEndpointPolicies =
ResourceType("Microsoft.Network/serviceEndpointPolicies", "2020-07-01")
let serviceEndpointPolicies = ResourceTypes.Network.serviceEndpointPolicies

let subnets =
ResourceType("Microsoft.Network/virtualNetworks/subnets", "2020-07-01")
let subnets = ResourceTypes.Network.subnets

let virtualNetworks =
ResourceType("Microsoft.Network/virtualNetworks", "2020-07-01")
let virtualNetworks = ResourceTypes.Network.virtualNetworks

let virtualNetworkGateways =
ResourceType("Microsoft.Network/virtualNetworkGateways", "2020-05-01")
let virtualNetworkGateways = ResourceTypes.Network.virtualNetworkGateways

let localNetworkGateways =
ResourceType("Microsoft.Network/localNetworkGateways", "")
let localNetworkGateways = ResourceTypes.Network.localNetworkGateways

let natGateways = ResourceType("Microsoft.Network/natGateways", "2021-08-01")
let natGateways = ResourceTypes.Network.natGateways

let privateEndpoints =
ResourceType("Microsoft.Network/privateEndpoints", "2021-05-01")
let privateEndpoints = ResourceTypes.Network.privateEndpoints

let virtualNetworkPeering =
ResourceType("Microsoft.Network/virtualNetworks/virtualNetworkPeerings", "2020-05-01")
let virtualNetworkPeering = ResourceTypes.Network.virtualNetworkPeering

let routeTables = ResourceType("Microsoft.Network/routeTables", "2021-01-01")
let routes = ResourceType("Microsoft.Network/routeTables/routes", "2021-01-01")
let routeTables = ResourceTypes.Network.routeTables
let routes = ResourceTypes.Network.routes

let routeServers = ResourceType("Microsoft.Network/virtualHubs", "2022-11-01")
let routeServers = ResourceTypes.Network.routeServers

let routeServerIPConfigs =
ResourceType("Microsoft.Network/virtualHubs/ipConfigurations", "2022-11-01")
let routeServerIPConfigs = ResourceTypes.Network.routeServerIPConfigs

let routeServerBGPConnections =
ResourceType("Microsoft.Network/virtualHubs/bgpConnections", "2022-11-01")
let routeServerBGPConnections = ResourceTypes.Network.routeServerBGPConnections

type SubnetReference =
| ViaManagedVNet of (ResourceId * ResourceName)
Expand Down Expand Up @@ -668,18 +654,6 @@ type Connection =
|}
|}

/// IP configuration for a network interface.
type IpConfiguration =
{
SubnetName: ResourceName
ApplicationSecurityGroups: LinkedResource list
PublicIpAddress: LinkedResource option
LoadBalancerBackendAddressPools: LinkedResource list
PrivateIpAllocation: AllocationMethod option
PrivateIpAddressVersion: AddressVersion
Primary: bool option
}

module NetworkInterface =
open Vm

Expand All @@ -699,56 +673,6 @@ module NetworkInterface =
| Standard_B8ms -> AcceleratedNetworkingUnsupported // failwithf "Accelerated networking unsupported for specified VM size. Using '%s'." state.Size.ArmValue
| _ -> AcceleratedNetworkingSupported

type IpConfiguration with

/// Serializes to ARM JSON. When serializing for a NetworkInterfaceConfiguration, allocation method is not included.
member ipConfig.ToArmJson(index: int, vnetId: ResourceId, includeAllocationMethod: bool) =
{|
name = $"ipconfig{index + 1}"
properties =
let allocationMethod, ip =
match ipConfig.PrivateIpAllocation with
| Some (StaticPrivateIp ip) -> "Static", string ip
| _ -> "Dynamic", null

{|
applicationSecurityGroups =
match ipConfig.ApplicationSecurityGroups with
| [] -> null
| asgs -> asgs |> List.map LinkedResource.AsIdObject |> Seq.ofList
loadBalancerBackendAddressPools =
match ipConfig.LoadBalancerBackendAddressPools with
| [] -> null // Don't emit the field if there are none set.
| backendPools ->
backendPools
|> List.map (fun lr -> lr.ResourceId |> ResourceId.AsIdObject)
|> box
primary = ipConfig.Primary |> Option.map box |> Option.toObj
privateIPAddressVersion =
match ipConfig.PrivateIpAddressVersion with
| IPv6 -> ipConfig.PrivateIpAddressVersion.ArmValue
| _ -> null // Don't include if IPv4 since this is the default (backwards compatibility)
privateIPAllocationMethod = if includeAllocationMethod then allocationMethod else null
privateIPAddress = ip
publicIPAddress =
ipConfig.PublicIpAddress
|> Option.map (fun pip ->
{|
id = pip.ResourceId.ArmExpression.Eval()
|})
|> Option.defaultValue Unchecked.defaultof<_>
subnet =
{|
id =
{ vnetId with
Type = subnets
Segments = [ ipConfig.SubnetName ]
}
.Eval()
|}
|}
|}

type NetworkInterface =
{
Name: ResourceName
Expand Down
18 changes: 18 additions & 0 deletions src/Farmer/Arm/ResourceTypes/Compute.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Farmer.Arm.ResourceTypes.Compute

open Farmer

let virtualMachines =
ResourceType("Microsoft.Compute/virtualMachines", "2023-03-01")

let virtualMachineScaleSets =
ResourceType("Microsoft.Compute/virtualMachineScaleSets", "2023-03-01")

let extensions =
ResourceType("Microsoft.Compute/virtualMachines/extensions", "2019-12-01")

let virtualMachineScaleSetsExtensions =
ResourceType("Microsoft.Compute/virtualMachineScaleSets/extensions", "2023-03-01")

let hostGroups = ResourceType("Microsoft.Compute/hostGroups", "2021-03-01")
let hosts = ResourceType("Microsoft.Compute/hostGroups/hosts", "2021-03-01")
Loading