Skip to content

Commit

Permalink
Virtual wan builder (#624)
Browse files Browse the repository at this point in the history
* virtual wan builder

* Renamed virtualWAN to virtualWan

* fixed formatting on vwan record types

* removed bad comment

Co-authored-by: solere <[email protected]>
  • Loading branch information
ericsoler1 and solere authored May 5, 2021
1 parent 6f2a1bc commit 9a28aaa
Show file tree
Hide file tree
Showing 10 changed files with 290 additions and 0 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Release Notes
* ServiceBus: Fix an issue with Premium Sku ARM Writer
* ServiceBus: Fix an issue with Rules depends on ARM Writer
* Storage Accounts: Support for CORS.
* Virtual WAN: add builder

## 1.5.0
* Container Groups: Support for init containers.
Expand Down
42 changes: 42 additions & 0 deletions docs/content/api-overview/resources/virtual-wan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
title: "Virtual WAN"
date: 2021-05-03T11:22:17-05:00
chapter: false
weight: 21
---

#### Overview

The Virtual WAN builder (`vwan`) is used to create Azure Virtual WAN instances.

- Virtual WAN (`Microsoft.Network/virtualWans`)

#### Builder Keywords

| Resource | Keyword | Purpose |
| -------------- | -------------------- | -----------------------------------------------------------------------|
| vwan | name | Sets the name of the virtual wan |
| vwan | standard_vwan | Sets the virtual wan type to "standard" instead of the default "basic" |
| vwan | allow_branch_to_branch_traffic | Specifies branch to branch traffic is allowed |
| vwan | disable_vpn_encryption | Specifies Vpn encryption is disabled |
| vwan | office_365_local_breakout_category | Sets the office local breakout category |


### Example

```fsharp
open Farmer
open Farmer.Builders
let myVwan = vwan {
name "my-vwan"
disable_vpn_encryption
allow_branch_to_branch_traffic
office_365_local_breakout_category Office365LocalBreakoutCategory.None
standard_vwan
}
let deployment = arm {
location Location.NorthEurope
add_resource myVwan
}
```
47 changes: 47 additions & 0 deletions src/Farmer/Arm/VirtualWan.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[<AutoOpen>]
module Farmer.Arm.VirtualWan

open Farmer

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

[<RequireQualifiedAccess>]
type Office365LocalBreakoutCategory =
| Optimize
| OptimizeAndAllow
| All
| None
member this.ArmValue =
match this with
| Optimize -> "Optimize"
| OptimizeAndAllow -> "OptimizeAndAllow"
| All -> "All"
| None -> "None"

[<RequireQualifiedAccess>]
type VwanType =
| Standard
| Basic
member this.ArmValue =
match this with
| Standard -> "Standard"
| Basic -> "Basic"

type VirtualWan =
{ Name : ResourceName
Location : Location
AllowBranchToBranchTraffic : bool option
DisableVpnEncryption : bool option
Office365LocalBreakoutCategory : Office365LocalBreakoutCategory option
VwanType : VwanType }
interface IArmResource with
member this.ResourceId = virtualWans.resourceId this.Name
member this.JsonModel =
{| virtualWans.Create(this.Name, this.Location) with
properties =
{|
allowBranchToBranchTraffic = this.AllowBranchToBranchTraffic |> Option.defaultValue false
disableVpnEncryption = this.DisableVpnEncryption |> Option.defaultValue false
office365LocalBreakoutCategory = (this.Office365LocalBreakoutCategory |> Option.defaultValue Office365LocalBreakoutCategory.None).ArmValue
``type`` = this.VwanType.ArmValue |}
|}:> _
50 changes: 50 additions & 0 deletions src/Farmer/Builders/Builders.VirtualWan.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[<AutoOpen>]
module Farmer.Builders.VirtualWan


open Farmer
open Farmer.Arm.VirtualWan

type VirtualWanConfig =
{ Name : ResourceName
AllowBranchToBranchTraffic : bool option
DisableVpnEncryption : bool option
Office365LocalBreakoutCategory : Office365LocalBreakoutCategory option
VwanType : VwanType }
interface IBuilder with
member this.ResourceId = virtualWans.resourceId this.Name
member this.BuildResources location = [
{ Name = this.Name
Location = location
AllowBranchToBranchTraffic = this.AllowBranchToBranchTraffic
DisableVpnEncryption = this.DisableVpnEncryption
Office365LocalBreakoutCategory = this.Office365LocalBreakoutCategory
VwanType = this.VwanType }
]

type VirtualWanBuilder() =
/// Yield sets everything to sane defaults.
member _.Yield _ : VirtualWanConfig =
{ Name = ResourceName.Empty
AllowBranchToBranchTraffic = None
DisableVpnEncryption = None
Office365LocalBreakoutCategory = None
VwanType = VwanType.Basic }
/// Sets the name to a ResourceName from the given string.
[<CustomOperation "name">]
member _.Name(state:VirtualWanConfig, name) = { state with Name = ResourceName name }
/// Sets the VWAN type to "standard" instead of the default "basic".
[<CustomOperation "standard_vwan">]
member _.StandardVwanType(state:VirtualWanConfig) = { state with VwanType = VwanType.Standard }
/// Allow branch to branch traffic.
[<CustomOperation "allow_branch_to_branch_traffic">]
member _.AllowBranchToBranchTraffic(state:VirtualWanConfig) = { state with AllowBranchToBranchTraffic = Some true }
/// Disable vpn encryption
[<CustomOperation "disable_vpn_encryption">]
member _.DisableVpnEncryption(state:VirtualWanConfig) = { state with DisableVpnEncryption = Some true }
/// Sets the office local breakout category
[<CustomOperation "office_365_local_breakout_category">]
member _.Office365LocalBreakoutCategory(state:VirtualWanConfig, category) = { state with Office365LocalBreakoutCategory = Some category }

/// This creates the keyword for a builder, such as `vwan { name "my-vwan" }
let vwan = VirtualWanBuilder()
2 changes: 2 additions & 0 deletions src/Farmer/Farmer.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
<Compile Include="Arm/NetworkSecurityGroup.fs" />
<Compile Include="Arm/DeploymentScript.fs" />
<Compile Include="Arm/Databricks.fs" />
<Compile Include="Arm/VirtualWan.fs" />
<Compile Include="IdentityExtensions.fs" />
<Compile Include="Builders/Builders.LogAnalytics.fs" />
<Compile Include="Builders/Builders.Helpers.fs" />
Expand Down Expand Up @@ -128,5 +129,6 @@
<Compile Include="Builders/Builders.NetworkSecurityGroup.fs" />
<Compile Include="Builders/Builders.Databricks.fs" />
<Compile Include="Builders\Builders.DiagnosticSetting.fs" />
<Compile Include="Builders/Builders.VirtualWan.fs" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Tests/AllTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ let allTests =
Types.tests
VirtualMachine.tests
VirtualNetworkGateway.tests
VirtualWan.tests
WebApp.tests
]
testList "Control" [
Expand Down
11 changes: 11 additions & 0 deletions src/Tests/JsonRegression.fs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,15 @@ let tests =
}
compareResourcesToJson [ svcBus ] "service-bus.json"
}

test "VirtualWan" {
let vwan = vwan {
name "farmer-vwan"
disable_vpn_encryption
allow_branch_to_branch_traffic
office_365_local_breakout_category Office365LocalBreakoutCategory.None
standard_vwan
}
compareResourcesToJson [ vwan ] "virtual-wan.json"
}
]
1 change: 1 addition & 0 deletions src/Tests/Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
<Compile Include="Identity.fs" />
<Compile Include="DeploymentScript.fs" />
<Compile Include="Databricks.fs" />
<Compile Include="VirtualWan.fs" />
<Compile Include="JsonRegression.fs" />
<Compile Include="Types.fs" />
<Compile Include="AllTests.fs" />
Expand Down
115 changes: 115 additions & 0 deletions src/Tests/VirtualWan.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
module VirtualWan

open Expecto
open Farmer
open Farmer.Arm
open Farmer.Builders
open System
open Microsoft.Azure.Management.Network
open Microsoft.Azure.Management.Network.Models
open Microsoft.Rest

/// Client instance so we can get the JSON serialization settings.
let client = new NetworkManagementClient(Uri "http://management.azure.com", TokenCredentials "NotNullOrWhiteSpace")

let getVirtualWanResource = findAzureResources<VirtualWAN> client.SerializationSettings >> List.head

/// Collection of tests for the VirtualWan resource and builders. Needs to be included in AllTests.fs
let tests = testList "VirtualWan" [
test "Can create a basic VirtualWan" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
}
]
} |> getVirtualWanResource
Expect.equal vwan.Name "my-vwan" "Incorrect Resource Name"
Expect.equal vwan.Location "westus" "Incorrect Location"
Expect.equal vwan.VirtualWANType "Basic" "Default should be 'Basic'"
Expect.isFalse vwan.AllowBranchToBranchTraffic.Value "AllowBranchToBranchTraffic should be false"
Expect.isFalse vwan.DisableVpnEncryption.Value "DisableVpnEncryption should not have a value"
Expect.equal vwan.Office365LocalBreakoutCategory "None" "Office365LocalBreakoutCategory should be 'None'"
}
test "Can create a standard VirtualWan" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
standard_vwan
}
]
} |> getVirtualWanResource
Expect.equal vwan.VirtualWANType "Standard" ""
}
test "Can create a VirtualWan with DisableVpnEncryption" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
disable_vpn_encryption
}
]
} |> getVirtualWanResource
Expect.equal vwan.DisableVpnEncryption (Nullable true) ""
}
test "Can create a VirtualWan with AllowBranchToBranchTraffic" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
allow_branch_to_branch_traffic
}
]
} |> getVirtualWanResource
Expect.equal vwan.AllowBranchToBranchTraffic (Nullable true) ""
}
test "Can create a VirtualWan with Office365LocalBreakoutCategory.All" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
office_365_local_breakout_category Office365LocalBreakoutCategory.All
}
]
} |> getVirtualWanResource
Expect.equal vwan.Office365LocalBreakoutCategory "All" ""
}
test "Can create a VirtualWan with Office365LocalBreakoutCategory.Optimize" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
office_365_local_breakout_category Office365LocalBreakoutCategory.Optimize
}
]
} |> getVirtualWanResource
Expect.equal vwan.Office365LocalBreakoutCategory "Optimize" ""
}
test "Can create a VirtualWan with Office365LocalBreakoutCategory.OptimizeAndAllow" {
let vwan =
arm {
location Location.WestUS
add_resources [
vwan {
name "my-vwan"
office_365_local_breakout_category Office365LocalBreakoutCategory.OptimizeAndAllow
}
]
} |> getVirtualWanResource
Expect.equal vwan.Office365LocalBreakoutCategory "OptimizeAndAllow" ""
}
]

20 changes: 20 additions & 0 deletions src/Tests/test-data/virtual-wan.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"resources": [
{
"apiVersion": "2020-07-01",
"location": "northeurope",
"name": "farmer-vwan",
"properties": {
"allowBranchToBranchTraffic": true,
"disableVpnEncryption": true,
"office365LocalBreakoutCategory": "None",
"type": "Standard"
},
"type": "Microsoft.Network/virtualWans"
}
]
}

0 comments on commit 9a28aaa

Please sign in to comment.