Skip to content

Commit 8be200c

Browse files
author
Alex Karpenko
committed
brownfield gateway test added
1 parent b149afe commit 8be200c

1 file changed

Lines changed: 40 additions & 34 deletions

File tree

internal/services/network/virtual_network_gateway_resource_test.go

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package network_test
66
import (
77
"context"
88
"fmt"
9+
"os"
910
"testing"
1011

1112
"github.com/hashicorp/go-azure-helpers/lang/pointer"
@@ -358,10 +359,29 @@ func TestAccVirtualNetworkGateway_expressRoute(t *testing.T) {
358359
func TestAccVirtualNetworkGateway_expressRouteWithPublicIPAddressId(t *testing.T) {
359360
data := acceptance.BuildTestData(t, "azurerm_virtual_network_gateway", "test")
360361
r := VirtualNetworkGatewayResource{}
362+
legacyGatewayID := os.Getenv("ARM_TEST_LEGACY_EXPRESSROUTE_GATEWAY_ID")
363+
364+
if legacyGatewayID == "" {
365+
t.Skip("Skipping as `ARM_TEST_LEGACY_EXPRESSROUTE_GATEWAY_ID` was not specified")
366+
}
361367

362368
data.ResourceTest(t, r, []acceptance.TestStep{
363369
{
364-
Config: r.expressRouteWithPublicIPAddressId(data),
370+
Config: r.expressRouteWithPublicIPAddressIdBrownfield(legacyGatewayID),
371+
ResourceName: data.ResourceName,
372+
ImportState: true,
373+
ImportStateId: legacyGatewayID,
374+
ImportStateVerify: true,
375+
},
376+
{
377+
Config: r.expressRouteWithPublicIPAddressIdBrownfield(legacyGatewayID),
378+
Check: acceptance.ComposeTestCheckFunc(
379+
check.That(data.ResourceName).Key("type").HasValue("ExpressRoute"),
380+
check.That(data.ResourceName).Key("ip_configuration.0.public_ip_address_id").Exists(),
381+
),
382+
},
383+
{
384+
Config: r.expressRouteWithPublicIPAddressIdBrownfield(legacyGatewayID),
365385
PlanOnly: true,
366386
},
367387
})
@@ -1432,55 +1452,41 @@ resource "azurerm_virtual_network_gateway" "test" {
14321452
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
14331453
}
14341454

1435-
func (VirtualNetworkGatewayResource) expressRouteWithPublicIPAddressId(data acceptance.TestData) string {
1455+
func (VirtualNetworkGatewayResource) expressRouteWithPublicIPAddressIdBrownfield(existingGatewayID string) string {
14361456
return fmt.Sprintf(`
14371457
provider "azurerm" {
14381458
features {}
14391459
}
14401460
1441-
resource "azurerm_resource_group" "test" {
1442-
name = "acctestRG-%d"
1443-
location = "%s"
1461+
locals {
1462+
gateway_id = "%s"
1463+
gateway_name = split("/", local.gateway_id)[8]
1464+
resource_group_name = split("/", local.gateway_id)[4]
14441465
}
14451466
1446-
resource "azurerm_virtual_network" "test" {
1447-
name = "acctestvn-%d"
1448-
location = azurerm_resource_group.test.location
1449-
resource_group_name = azurerm_resource_group.test.name
1450-
address_space = ["10.0.0.0/16"]
1451-
}
1452-
1453-
resource "azurerm_subnet" "test" {
1454-
name = "GatewaySubnet"
1455-
resource_group_name = azurerm_resource_group.test.name
1456-
virtual_network_name = azurerm_virtual_network.test.name
1457-
address_prefixes = ["10.0.1.0/24"]
1458-
}
1459-
1460-
resource "azurerm_public_ip" "test" {
1461-
name = "acctestpip1-%d"
1462-
location = azurerm_resource_group.test.location
1463-
resource_group_name = azurerm_resource_group.test.name
1464-
allocation_method = "Static"
1465-
sku = "Standard"
1467+
data "azurerm_virtual_network_gateway" "existing" {
1468+
name = local.gateway_name
1469+
resource_group_name = local.resource_group_name
14661470
}
14671471
14681472
resource "azurerm_virtual_network_gateway" "test" {
1469-
name = "acctestvng-%d"
1470-
location = azurerm_resource_group.test.location
1471-
resource_group_name = azurerm_resource_group.test.name
1473+
name = local.gateway_name
1474+
location = data.azurerm_virtual_network_gateway.existing.location
1475+
resource_group_name = local.resource_group_name
14721476
14731477
type = "ExpressRoute"
1474-
vpn_type = "PolicyBased"
1475-
sku = "Standard"
1478+
vpn_type = data.azurerm_virtual_network_gateway.existing.vpn_type
1479+
sku = data.azurerm_virtual_network_gateway.existing.sku
1480+
generation = data.azurerm_virtual_network_gateway.existing.generation
14761481
14771482
ip_configuration {
1478-
public_ip_address_id = azurerm_public_ip.test.id
1479-
private_ip_address_allocation = "Dynamic"
1480-
subnet_id = azurerm_subnet.test.id
1483+
name = data.azurerm_virtual_network_gateway.existing.ip_configuration[0].name
1484+
public_ip_address_id = data.azurerm_virtual_network_gateway.existing.ip_configuration[0].public_ip_address_id
1485+
private_ip_address_allocation = data.azurerm_virtual_network_gateway.existing.ip_configuration[0].private_ip_address_allocation
1486+
subnet_id = data.azurerm_virtual_network_gateway.existing.ip_configuration[0].subnet_id
14811487
}
14821488
}
1483-
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
1489+
`, existingGatewayID)
14841490
}
14851491

14861492
func (VirtualNetworkGatewayResource) expressRouteErGwScale(data acceptance.TestData) string {

0 commit comments

Comments
 (0)