From 318c1ed3128e09d606fe0665b9f334ad7cbbac44 Mon Sep 17 00:00:00 2001 From: Josh Barker Date: Mon, 20 Mar 2023 14:58:16 +1100 Subject: [PATCH] feat: add hub_routing_preference to virtual hub resource --- .../services/network/virtual_hub_resource.go | 18 +++++++++- .../network/virtual_hub_resource_test.go | 34 +++++++++++++++++++ website/docs/r/virtual_hub.html.markdown | 2 ++ 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/internal/services/network/virtual_hub_resource.go b/internal/services/network/virtual_hub_resource.go index d232bf8b05b6..a4ddb20ce212 100644 --- a/internal/services/network/virtual_hub_resource.go +++ b/internal/services/network/virtual_hub_resource.go @@ -116,6 +116,17 @@ func resourceVirtualHub() *pluginsdk.Resource { "tags": tags.Schema(), + "hub_routing_preference": { + Type: pluginsdk.TypeString, + Optional: true, + Default: string(network.HubRoutingPreferenceExpressRoute), + ValidateFunc: validation.StringInSlice([]string{ + string(network.HubRoutingPreferenceExpressRoute), + string(network.HubRoutingPreferenceVpnGateway), + string(network.HubRoutingPreferenceASPath), + }, false), + }, + "default_route_table_id": { Type: pluginsdk.TypeString, Computed: true, @@ -155,10 +166,13 @@ func resourceVirtualHubCreateUpdate(d *pluginsdk.ResourceData, meta interface{}) route := d.Get("route").(*pluginsdk.Set).List() t := d.Get("tags").(map[string]interface{}) + hubRoutingPreference := d.Get("hub_routing_preference").(string) + parameters := network.VirtualHub{ Location: utils.String(location), VirtualHubProperties: &network.VirtualHubProperties{ - RouteTable: expandVirtualHubRoute(route), + RouteTable: expandVirtualHubRoute(route), + HubRoutingPreference: network.HubRoutingPreference(hubRoutingPreference), }, Tags: tags.Expand(t), } @@ -243,6 +257,8 @@ func resourceVirtualHubRead(d *pluginsdk.ResourceData, meta interface{}) error { return fmt.Errorf("setting `route`: %+v", err) } + d.Set("hub_routing_preference", props.HubRoutingPreference) + var virtualWanId *string if props.VirtualWan != nil { virtualWanId = props.VirtualWan.ID diff --git a/internal/services/network/virtual_hub_resource_test.go b/internal/services/network/virtual_hub_resource_test.go index feab468f9bd9..e445bf7590a1 100644 --- a/internal/services/network/virtual_hub_resource_test.go +++ b/internal/services/network/virtual_hub_resource_test.go @@ -32,6 +32,24 @@ func TestAccVirtualHub_basic(t *testing.T) { }) } +func TestAccVirtualHub_hubRoutingPreference(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") + r := VirtualHubResource{} + + data.ResourceTest(t, r, []acceptance.TestStep{ + { + Config: r.hubRoutingPreference(data), + Check: acceptance.ComposeTestCheckFunc( + check.That(data.ResourceName).ExistsInAzure(r), + check.That(data.ResourceName).Key("virtual_router_asn").Exists(), + check.That(data.ResourceName).Key("virtual_router_ips.#").Exists(), + check.That(data.ResourceName).Key("hub_routing_preference").HasValue("ASPath"), + ), + }, + data.ImportStep(), + }) +} + func TestAccVirtualHub_requiresImport(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_virtual_hub", "test") r := VirtualHubResource{} @@ -203,3 +221,19 @@ resource "azurerm_virtual_wan" "test" { } `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } + +func (r VirtualHubResource) hubRoutingPreference(data acceptance.TestData) string { + return fmt.Sprintf(` +%s + +resource "azurerm_virtual_hub" "test" { + name = "acctestVHUB-%d" + resource_group_name = azurerm_resource_group.test.name + location = azurerm_resource_group.test.location + virtual_wan_id = azurerm_virtual_wan.test.id + address_prefix = "10.0.1.0/24" + + hub_routing_preference = "ASPath" +} +`, r.template(data), data.RandomInteger) +} diff --git a/website/docs/r/virtual_hub.html.markdown b/website/docs/r/virtual_hub.html.markdown index c1f3413e9273..ca6bfbbd895b 100644 --- a/website/docs/r/virtual_hub.html.markdown +++ b/website/docs/r/virtual_hub.html.markdown @@ -47,6 +47,8 @@ The following arguments are supported: * `address_prefix` - (Optional) The Address Prefix which should be used for this Virtual Hub. Changing this forces a new resource to be created. [The address prefix subnet cannot be smaller than a `/24`. Azure recommends using a `/23`](https://docs.microsoft.com/azure/virtual-wan/virtual-wan-faq#what-is-the-recommended-hub-address-space-during-hub-creation). +* `hub_routing_preference` - (Optional) The hub routing preference. Possible values are `ExpressRoute`, `ASPath` and `VpnGateway`. Defaults to `ExpressRoute`. + * `route` - (Optional) One or more `route` blocks as defined below. * `sku` - (Optional) The SKU of the Virtual Hub. Possible values are `Basic` and `Standard`. Changing this forces a new resource to be created.