diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index 6c373fea1..5127ad6db 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -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. diff --git a/docs/content/api-overview/resources/virtual-wan.md b/docs/content/api-overview/resources/virtual-wan.md new file mode 100644 index 000000000..b36380b0c --- /dev/null +++ b/docs/content/api-overview/resources/virtual-wan.md @@ -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 +} +``` \ No newline at end of file diff --git a/src/Farmer/Arm/VirtualWan.fs b/src/Farmer/Arm/VirtualWan.fs new file mode 100644 index 000000000..64fb82898 --- /dev/null +++ b/src/Farmer/Arm/VirtualWan.fs @@ -0,0 +1,47 @@ +[] +module Farmer.Arm.VirtualWan + +open Farmer + +let virtualWans = ResourceType ("Microsoft.Network/virtualWans", "2020-07-01") + +[] +type Office365LocalBreakoutCategory = + | Optimize + | OptimizeAndAllow + | All + | None + member this.ArmValue = + match this with + | Optimize -> "Optimize" + | OptimizeAndAllow -> "OptimizeAndAllow" + | All -> "All" + | None -> "None" + +[] +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 |} + |}:> _ \ No newline at end of file diff --git a/src/Farmer/Builders/Builders.VirtualWan.fs b/src/Farmer/Builders/Builders.VirtualWan.fs new file mode 100644 index 000000000..14044f199 --- /dev/null +++ b/src/Farmer/Builders/Builders.VirtualWan.fs @@ -0,0 +1,50 @@ +[] +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. + [] + member _.Name(state:VirtualWanConfig, name) = { state with Name = ResourceName name } + /// Sets the VWAN type to "standard" instead of the default "basic". + [] + member _.StandardVwanType(state:VirtualWanConfig) = { state with VwanType = VwanType.Standard } + /// Allow branch to branch traffic. + [] + member _.AllowBranchToBranchTraffic(state:VirtualWanConfig) = { state with AllowBranchToBranchTraffic = Some true } + /// Disable vpn encryption + [] + member _.DisableVpnEncryption(state:VirtualWanConfig) = { state with DisableVpnEncryption = Some true } + /// Sets the office 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() diff --git a/src/Farmer/Farmer.fsproj b/src/Farmer/Farmer.fsproj index 71ba8f6fd..9e77b9a81 100644 --- a/src/Farmer/Farmer.fsproj +++ b/src/Farmer/Farmer.fsproj @@ -88,6 +88,7 @@ + @@ -128,5 +129,6 @@ + \ No newline at end of file diff --git a/src/Tests/AllTests.fs b/src/Tests/AllTests.fs index 10e03d69b..66c6e0ec3 100644 --- a/src/Tests/AllTests.fs +++ b/src/Tests/AllTests.fs @@ -45,6 +45,7 @@ let allTests = Types.tests VirtualMachine.tests VirtualNetworkGateway.tests + VirtualWan.tests WebApp.tests ] testList "Control" [ diff --git a/src/Tests/JsonRegression.fs b/src/Tests/JsonRegression.fs index 7965db24b..b743e895f 100644 --- a/src/Tests/JsonRegression.fs +++ b/src/Tests/JsonRegression.fs @@ -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" + } ] diff --git a/src/Tests/Tests.fsproj b/src/Tests/Tests.fsproj index c6e0229ea..ec1e3864e 100644 --- a/src/Tests/Tests.fsproj +++ b/src/Tests/Tests.fsproj @@ -45,6 +45,7 @@ + diff --git a/src/Tests/VirtualWan.fs b/src/Tests/VirtualWan.fs new file mode 100644 index 000000000..5b1dbe5e7 --- /dev/null +++ b/src/Tests/VirtualWan.fs @@ -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 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" "" + } +] + diff --git a/src/Tests/test-data/virtual-wan.json b/src/Tests/test-data/virtual-wan.json new file mode 100644 index 000000000..54d4df8db --- /dev/null +++ b/src/Tests/test-data/virtual-wan.json @@ -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" + } + ] +} \ No newline at end of file