-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 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
1 parent
6f2a1bc
commit 9a28aaa
Showing
10 changed files
with
290 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |} | ||
|}:> _ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" "" | ||
} | ||
] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
] | ||
} |