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_vpn_gateway - support new property bgp_route_translation_for_nat_enabled #16817

Merged
merged 1 commit into from
May 23, 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
18 changes: 17 additions & 1 deletion internal/services/network/vpn_gateway_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ func resourceVPNGateway() *pluginsdk.Resource {
}, false),
},

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

"bgp_settings": {
Type: pluginsdk.TypeList,
Optional: true,
Expand Down Expand Up @@ -221,7 +227,8 @@ func resourceVPNGatewayCreate(d *pluginsdk.ResourceData, meta interface{}) error
parameters := network.VpnGateway{
Location: utils.String(location),
VpnGatewayProperties: &network.VpnGatewayProperties{
BgpSettings: bgpSettings,
EnableBgpRouteTranslationForNat: utils.Bool(d.Get("bgp_route_translation_for_nat_enabled").(bool)),
BgpSettings: bgpSettings,
VirtualHub: &network.SubResource{
ID: utils.String(virtualHubId),
},
Expand Down Expand Up @@ -307,6 +314,9 @@ func resourceVPNGatewayUpdate(d *pluginsdk.ResourceData, meta interface{}) error
if d.HasChange("tags") {
existing.Tags = tags.Expand(d.Get("tags").(map[string]interface{}))
}
if d.HasChange("bgp_route_translation_for_nat_enabled") {
existing.EnableBgpRouteTranslationForNat = utils.Bool(d.Get("bgp_route_translation_for_nat_enabled").(bool))
}

bgpSettingsRaw := d.Get("bgp_settings").([]interface{})
if len(bgpSettingsRaw) > 0 {
Expand Down Expand Up @@ -373,6 +383,12 @@ func resourceVPNGatewayRead(d *pluginsdk.ResourceData, meta interface{}) error {
return fmt.Errorf("setting `bgp_settings`: %+v", err)
}

bgpRouteTranslationForNatEnabled := false
if props.EnableBgpRouteTranslationForNat != nil {
bgpRouteTranslationForNatEnabled = *props.EnableBgpRouteTranslationForNat
}
d.Set("bgp_route_translation_for_nat_enabled", bgpRouteTranslationForNatEnabled)

scaleUnit := 0
if props.VpnGatewayScaleUnit != nil {
scaleUnit = int(*props.VpnGatewayScaleUnit)
Expand Down
36 changes: 36 additions & 0 deletions internal/services/network/vpn_gateway_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,28 @@ func TestAccVPNGateway_routingPreferenceInternet(t *testing.T) {
})
}

func TestAccVPNGateway_bgpRouteTranslationForNatEnabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_vpn_gateway", "test")
r := VPNGatewayResource{}

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

func (t VPNGatewayResource) Exists(ctx context.Context, clients *clients.Client, state *pluginsdk.InstanceState) (*bool, error) {
id, err := parse.VpnGatewayID(state.ID)
if err != nil {
Expand Down Expand Up @@ -273,6 +295,20 @@ resource "azurerm_vpn_gateway" "test" {
`, r.template(data), data.RandomInteger)
}

func (r VPNGatewayResource) bgpRouteTranslationForNatEnabled(data acceptance.TestData, bgpRouteTranslationForNatEnabled bool) string {
return fmt.Sprintf(`
%s

resource "azurerm_vpn_gateway" "test" {
name = "acctestVPNG-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
virtual_hub_id = azurerm_virtual_hub.test.id
bgp_route_translation_for_nat_enabled = %t
}
`, r.template(data), data.RandomInteger, bgpRouteTranslationForNatEnabled)
}

func (VPNGatewayResource) template(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
2 changes: 2 additions & 0 deletions website/docs/r/vpn_gateway.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ The following arguments are supported:

---

* `bgp_route_translation_for_nat_enabled` - (Optional) Is BGP route translation for NAT on this VPN Gateway enabled? Defaults to `false`.

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

* `routing_preference` - (Optional) Azure routing preference lets you to choose how your traffic routes between Azure and the internet. You can choose to route traffic either via the Microsoft network (default value, `Microsoft Network`), or via the ISP network (public internet, set to `Internet`). More context of the configuration can be found in the
Expand Down