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_point_to_site_vpn_gateway - support for the routing_preference_internet_enabled, inbound_route_map_id and outbound_route_map_id properties #19672

Merged
merged 1 commit into from
Dec 15, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@ func resourcePointToSiteVPNGateway() *pluginsdk.Resource {
ValidateFunc: networkValidate.HubRouteTableID,
},

"inbound_route_map_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: networkValidate.RouteMapID,
},

"outbound_route_map_id": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: networkValidate.RouteMapID,
},

"propagated_route_table": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -154,6 +166,13 @@ func resourcePointToSiteVPNGateway() *pluginsdk.Resource {
ValidateFunc: validation.IntAtLeast(0),
},

"routing_preference_internet_enabled": {
Type: pluginsdk.TypeBool,
Optional: true,
ForceNew: true,
Default: false,
},

"dns_servers": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -201,6 +220,7 @@ func resourcePointToSiteVPNGatewayCreateUpdate(d *pluginsdk.ResourceData, meta i
parameters := network.P2SVpnGateway{
Location: utils.String(location),
P2SVpnGatewayProperties: &network.P2SVpnGatewayProperties{
IsRoutingPreferenceInternet: utils.Bool(d.Get("routing_preference_internet_enabled").(bool)),
P2SConnectionConfigurations: connectionConfigurations,
VpnServerConfiguration: &network.SubResource{
ID: utils.String(vpnServerConfigurationId),
Expand Down Expand Up @@ -283,6 +303,12 @@ func resourcePointToSiteVPNGatewayRead(d *pluginsdk.ResourceData, meta interface
vpnServerConfigurationId = *props.VpnServerConfiguration.ID
}
d.Set("vpn_server_configuration_id", vpnServerConfigurationId)

routingPreferenceInternetEnabled := false
if props.IsRoutingPreferenceInternet != nil {
routingPreferenceInternetEnabled = *props.IsRoutingPreferenceInternet
}
d.Set("routing_preference_internet_enabled", routingPreferenceInternetEnabled)
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -348,13 +374,29 @@ func expandPointToSiteVPNGatewayConnectionRouteConfiguration(input []interface{}
if len(input) == 0 {
return nil
}

v := input[0].(map[string]interface{})
return &network.RoutingConfiguration{

routingConfiguration := &network.RoutingConfiguration{
AssociatedRouteTable: &network.SubResource{
ID: utils.String(v["associated_route_table_id"].(string)),
},
PropagatedRouteTables: expandPointToSiteVPNGatewayConnectionRouteConfigurationPropagatedRouteTable(v["propagated_route_table"].([]interface{})),
}

if inboundRouteMapId := v["inbound_route_map_id"].(string); inboundRouteMapId != "" {
routingConfiguration.InboundRouteMap = &network.SubResource{
ID: utils.String(inboundRouteMapId),
}
}

if outboundRouteMapId := v["outbound_route_map_id"].(string); outboundRouteMapId != "" {
routingConfiguration.OutboundRouteMap = &network.SubResource{
ID: utils.String(outboundRouteMapId),
}
}

return routingConfiguration
}

func expandPointToSiteVPNGatewayConnectionRouteConfigurationPropagatedRouteTable(input []interface{}) *network.PropagatedRouteTable {
Expand Down Expand Up @@ -425,13 +467,27 @@ func flattenPointToSiteVPNGatewayConnectionRouteConfiguration(input *network.Rou
if input == nil {
return []interface{}{}
}

var associatedRouteTableId string
if input.AssociatedRouteTable != nil && input.AssociatedRouteTable.ID != nil {
associatedRouteTableId = *input.AssociatedRouteTable.ID
}

var inboundRouteMapId string
if input.InboundRouteMap != nil && input.InboundRouteMap.ID != nil {
inboundRouteMapId = *input.InboundRouteMap.ID
}

var outboundRouteMapId string
if input.OutboundRouteMap != nil && input.OutboundRouteMap.ID != nil {
outboundRouteMapId = *input.OutboundRouteMap.ID
}

return []interface{}{
map[string]interface{}{
"associated_route_table_id": associatedRouteTableId,
"inbound_route_map_id": inboundRouteMapId,
"outbound_route_map_id": outboundRouteMapId,
"propagated_route_table": flattenPointToSiteVPNGatewayConnectionRouteConfigurationPropagatedRouteTable(input.PropagatedRouteTables),
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ func TestAccPointToSiteVPNGateway_tags(t *testing.T) {
})
}

func TestAccPointToSiteVPNGateway_routing(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_point_to_site_vpn_gateway", "test")
r := PointToSiteVPNGatewayResource{}
nameSuffix := randString()

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.routing(data, nameSuffix),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (PointToSiteVPNGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.PointToSiteVpnGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -300,3 +316,84 @@ EOF
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}

func (r PointToSiteVPNGatewayResource) routing(data acceptance.TestData, nameSuffix string) string {
return fmt.Sprintf(`
%s

resource "azurerm_route_map" "test" {
name = "acctestrm-%s"
virtual_hub_id = azurerm_virtual_hub.test.id

rule {
name = "rule1"
next_step_if_matched = "Continue"

action {
type = "Add"

parameter {
as_path = ["22334"]
}
}

match_criterion {
match_condition = "Contains"
route_prefix = ["10.0.0.0/8"]
}
}
}

resource "azurerm_route_map" "test2" {
name = "acctestrmn-%s"
virtual_hub_id = azurerm_virtual_hub.test.id

rule {
name = "rule1"
next_step_if_matched = "Continue"

action {
type = "Add"

parameter {
as_path = ["22334"]
}
}

match_criterion {
match_condition = "Contains"
route_prefix = ["10.0.0.0/8"]
}
}
}

resource "azurerm_point_to_site_vpn_gateway" "test" {
name = "acctestp2sVPNG-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
virtual_hub_id = azurerm_virtual_hub.test.id
vpn_server_configuration_id = azurerm_vpn_server_configuration.test.id
scale_unit = 1
routing_preference_internet_enabled = true

connection_configuration {
name = "first"

vpn_client_address_pool {
address_prefixes = ["172.100.0.0/14"]
}

route {
associated_route_table_id = azurerm_virtual_hub.test.default_route_table_id
inbound_route_map_id = azurerm_route_map.test.id
outbound_route_map_id = azurerm_route_map.test2.id

propagated_route_table {
ids = [azurerm_virtual_hub.test.default_route_table_id]
labels = ["label1"]
}
}
}
}
`, r.template(data), nameSuffix, nameSuffix, data.RandomInteger)
}
6 changes: 6 additions & 0 deletions website/docs/r/point_to_site_vpn_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ The following arguments are supported:

* `dns_servers` - (Optional) A list of IP Addresses of DNS Servers for the Point-to-Site VPN Gateway.

* `routing_preference_internet_enabled` - (Optional) Is the Routing Preference for the Public IP Interface of the VPN Gateway enabled? Defaults to `false`. Changing this forces a new resource to be created.

* `tags` - (Optional) A mapping of tags to assign to the Point-to-Site VPN Gateway.

---
Expand All @@ -131,6 +133,10 @@ A `route` block supports the following:

* `associated_route_table_id` - (Required) The Virtual Hub Route Table resource id associated with this Routing Configuration.

* `inbound_route_map_id` - (Optional) The resource ID of the Route Map associated with this Routing Configuration for inbound learned routes.

* `outbound_route_map_id` - (Optional) The resource ID of the Route Map associated with this Routing Configuration for outbound advertised routes.

* `propagated_route_table` - (Optional) A `propagated_route_table` block as defined below.

---
Expand Down