Skip to content

Commit b4b4059

Browse files
bubbletroublesstephybunBubbleTroubles
authored andcommitted
azurerm_route_server - Add support for hub_routing_preference property (hashicorp#28363)
* Update route_server_resource.go * Update route_server_resource_test.go * Update route_server.html.markdown * Update route_server.html.markdown * fix tflint * Update internal/services/network/route_server_resource.go Co-authored-by: stephybun <steph@hashicorp.com> * Updated test to validate basic config * Update internal/services/network/route_server_resource.go Co-authored-by: stephybun <steph@hashicorp.com> * Update internal/services/network/route_server_resource.go Co-authored-by: stephybun <steph@hashicorp.com> * Update route_server_resource.go * Update route_server.html.markdown * Removed computed * Fixed update operation * Update website/docs/r/route_server.html.markdown Apply suggestions. Co-authored-by: stephybun <steph@hashicorp.com> --------- Co-authored-by: stephybun <steph@hashicorp.com> Co-authored-by: BubbleTroubles <bubbletroubles@gmail.com>
1 parent d77136b commit b4b4059

3 files changed

Lines changed: 40 additions & 9 deletions

File tree

internal/services/network/route_server_resource.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,17 @@ func resourceRouteServer() *pluginsdk.Resource {
8383
Default: false,
8484
},
8585

86+
"hub_routing_preference": {
87+
Type: pluginsdk.TypeString,
88+
Optional: true,
89+
Default: string(virtualwans.HubRoutingPreferenceExpressRoute),
90+
ValidateFunc: validation.StringInSlice([]string{
91+
string(virtualwans.HubRoutingPreferenceASPath),
92+
string(virtualwans.HubRoutingPreferenceExpressRoute),
93+
string(virtualwans.HubRoutingPreferenceVpnGateway),
94+
}, false),
95+
},
96+
8697
"virtual_router_ips": {
8798
Type: pluginsdk.TypeSet,
8899
Computed: true,
@@ -132,6 +143,7 @@ func resourceRouteServerCreate(d *pluginsdk.ResourceData, meta interface{}) erro
132143
Properties: &virtualwans.VirtualHubProperties{
133144
Sku: pointer.To(d.Get("sku").(string)),
134145
AllowBranchToBranchTraffic: pointer.To(d.Get("branch_to_branch_traffic_enabled").(bool)),
146+
HubRoutingPreference: pointer.To(virtualwans.HubRoutingPreference(d.Get("hub_routing_preference").(string))),
135147
},
136148
Tags: tags.Expand(d.Get("tags").(map[string]interface{})),
137149
}
@@ -209,6 +221,10 @@ func resourceRouteServerUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
209221
payload.Properties.AllowBranchToBranchTraffic = pointer.To(d.Get("branch_to_branch_traffic_enabled").(bool))
210222
}
211223

224+
if d.HasChange("hub_routing_preference") {
225+
payload.Properties.HubRoutingPreference = pointer.To(virtualwans.HubRoutingPreference(d.Get("hub_routing_preference").(string)))
226+
}
227+
212228
if d.HasChange("tags") {
213229
payload.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
214230
}
@@ -272,6 +288,7 @@ func resourceRouteServerRead(d *pluginsdk.ResourceData, meta interface{}) error
272288
if props.AllowBranchToBranchTraffic != nil {
273289
d.Set("branch_to_branch_traffic_enabled", props.AllowBranchToBranchTraffic)
274290
}
291+
d.Set("hub_routing_preference", pointer.From(props.HubRoutingPreference))
275292
if props.VirtualRouterAsn != nil {
276293
d.Set("virtual_router_asn", props.VirtualRouterAsn)
277294
}

internal/services/network/route_server_resource_test.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ func TestAccRouteServer_basic(t *testing.T) {
2626
{
2727
Config: r.basic(data),
2828
Check: acceptance.ComposeTestCheckFunc(
29-
check.That(data.ResourceName).ExistsInAzure(r)),
29+
check.That(data.ResourceName).ExistsInAzure(r),
30+
),
3031
},
3132
data.ImportStep(),
3233
})
@@ -71,13 +72,22 @@ func TestAccRouteServer_update(t *testing.T) {
7172
{
7273
Config: r.basic(data),
7374
Check: acceptance.ComposeTestCheckFunc(
74-
check.That(data.ResourceName).ExistsInAzure(r)),
75+
check.That(data.ResourceName).ExistsInAzure(r),
76+
),
7577
},
7678
data.ImportStep(),
7779
{
7880
Config: r.complete(data),
7981
Check: acceptance.ComposeTestCheckFunc(
80-
check.That(data.ResourceName).ExistsInAzure(r)),
82+
check.That(data.ResourceName).ExistsInAzure(r),
83+
),
84+
},
85+
data.ImportStep(),
86+
{
87+
Config: r.basic(data),
88+
Check: acceptance.ComposeTestCheckFunc(
89+
check.That(data.ResourceName).ExistsInAzure(r),
90+
),
8191
},
8292
data.ImportStep(),
8393
})
@@ -147,6 +157,7 @@ resource "azurerm_route_server" "test" {
147157
public_ip_address_id = azurerm_public_ip.test.id
148158
subnet_id = azurerm_subnet.test.id
149159
branch_to_branch_traffic_enabled = true
160+
hub_routing_preference = "VpnGateway"
150161
}
151162
`, r.template(data), data.RandomInteger)
152163
}

website/docs/r/route_server.html.markdown

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ resource "azurerm_route_server" "example" {
5252
public_ip_address_id = azurerm_public_ip.example.id
5353
subnet_id = azurerm_subnet.example.id
5454
branch_to_branch_traffic_enabled = true
55+
hub_routing_preference = "ASPath"
5556
}
5657
```
5758

@@ -65,23 +66,25 @@ The following arguments are supported:
6566

6667
* `location` - (Required) Specifies the supported Azure location where the Route Server should exist. Changing this forces a new resource to be created.
6768

68-
* `subnet_id` - (Required) The ID of the Subnet that the Route Server will reside. Changing this forces a new resource to be created.
69-
70-
-> **NOTE:** Azure Route Server requires a dedicated subnet named RouteServerSubnet. The subnet size has to be at least /27 or short prefix (such as /26 or /25) and cannot be attached to any security group, otherwise, you'll receive an error message when deploying the Route Server
69+
* `public_ip_address_id` - (Required) The ID of the Public IP Address. This option is required since September 1st 2021. Changing this forces a new resource to be created.
7170

7271
* `sku` - (Required) The SKU of the Route Server. The only possible value is `Standard`. Changing this forces a new resource to be created.
7372

74-
* `public_ip_address_id` - (Required) The ID of the Public IP Address. This option is required since September 1st 2021. Changing this forces a new resource to be created.
73+
* `subnet_id` - (Required) The ID of the Subnet that the Route Server will reside. Changing this forces a new resource to be created.
74+
75+
-> **NOTE:** Azure Route Server requires a dedicated subnet named RouteServerSubnet. The subnet size has to be at least /27 or short prefix (such as /26 or /25) and cannot be attached to any security group, otherwise, you'll receive an error message when deploying the Route Server.
76+
77+
* `branch_to_branch_traffic_enabled` - (Optional) Whether to enable route exchange between Azure Route Server and the gateway(s).
7578

76-
* `branch_to_branch_traffic_enabled` - (Optional) Whether to enable route exchange between Azure Route Server and the gateway(s)
79+
* `hub_routing_preference` - (Optional) The hub routing preference. Valid values are `ASPath`, `ExpressRoute` or `VpnGateway`. Defaults to `ExpressRoute`.
7780

7881
* `tags` - (Optional) A mapping of tags to assign to the resource.
7982

8083
## Attributes Reference
8184

8285
In addition to the Arguments listed above - the following Attributes are exported:
8386

84-
* `id` - The ID of the Route Server .
87+
* `id` - The ID of the Route Server.
8588

8689
## Timeouts
8790

0 commit comments

Comments
 (0)