Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_virtual_hub - feat: add hub_routing_preference to virtual hub resource #21028

Merged
merged 1 commit into from Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion internal/services/network/virtual_hub_resource.go
Expand Up @@ -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,
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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
Expand Down
34 changes: 34 additions & 0 deletions internal/services/network/virtual_hub_resource_test.go
Expand Up @@ -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{}
Expand Down Expand Up @@ -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)
}
2 changes: 2 additions & 0 deletions website/docs/r/virtual_hub.html.markdown
Expand Up @@ -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.
Expand Down