Skip to content

Commit

Permalink
feat: Update Network Edge BGP Acceptance Tests to use fabric resource…
Browse files Browse the repository at this point in the history
…s(fabric connection and service profile) (#710)

feat: Update Network Edge BGP Acceptance Tests to use fabric
resources(fabric connection and service profile)
  • Loading branch information
kpdhulipala committed Jun 26, 2024
1 parent 5890d74 commit 3072853
Show file tree
Hide file tree
Showing 2 changed files with 214 additions and 39 deletions.
246 changes: 208 additions & 38 deletions equinix/resource_network_bgp_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,44 +13,52 @@ import (
"github.com/hashicorp/terraform-plugin-testing/terraform"
)

const (
awsSpUuid = "TF_ACC_NETWORK_FABRIC_SERVICE_UUID"
)

func TestAccNetworkBGP_CSR1000V_Single_AWS(t *testing.T) {
metro, _ := schema.EnvDefaultFunc(networkDeviceMetroEnvVar, "SV")()
metro, _ := schema.EnvDefaultFunc(networkDeviceMetroEnvVar, "SY")()
spName, _ := schema.EnvDefaultFunc(awsSpEnvVar, "AWS Direct Connect")()
spUuid, _ := schema.EnvDefaultFunc(awsSpUuid, "")()
authKey, _ := schema.EnvDefaultFunc(awsAuthKeyEnvVar, "123456789012")()
accountName, _ := schema.EnvDefaultFunc(networkDeviceAccountNameEnvVar, "")()
projectId, _ := schema.EnvDefaultFunc(networkDeviceProjectId, "")()
context := map[string]interface{}{
"device-resourceName": "test",
"device-account_name": accountName.(string),
"device-self_managed": false,
"device-byol": false,
"device-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"device-throughput": 500,
"device-throughput_unit": "Mbps",
"device-metro_code": metro.(string),
"device-type_code": "CSR1000V",
"device-package_code": "SEC",
"device-notifications": []string{"marry@equinix.com", "john@equinix.com"},
"device-hostname": fmt.Sprintf("tf-%s", acctest.RandString(6)),
"device-term_length": 1,
"device-version": "16.09.05",
"device-core_count": 2,
"user-resourceName": "test",
"user-username": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"user-password": acctest.RandString(10),
"connection-resourceName": "test",
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-profile_name": spName.(string),
"connection-speed": 50,
"connection-speed_unit": "MB",
"connection-notifications": []string{"marry@equinix.com", "john@equinix.com"},
"connection-seller_metro_code": "SV",
"connection-seller_region": "us-west-1",
"connection-authorization_key": authKey.(string),
"bgp-resourceName": "test",
"bgp-local_ip_address": "1.1.1.1/30",
"bgp-local_asn": 12345,
"bgp-remote_ip_address": "1.1.1.2",
"bgp-remote_asn": 22211,
"device-resourceName": "test",
"device-account_name": accountName.(string),
"device-self_managed": false,
"device-byol": false,
"device-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"device-throughput": 500,
"device-throughput_unit": "Mbps",
"device-metro_code": metro.(string),
"device-project_id": projectId.(string),
"device-type_code": "CSR1000V",
"device-package_code": "SEC",
"device-notifications": []string{"marry@equinix.com", "john@equinix.com"},
"device-hostname": fmt.Sprintf("tf-%s", acctest.RandString(6)),
"device-term_length": 1,
"device-version": "16.09.05",
"device-core_count": 2,
"user-resourceName": "test",
"user-username": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"user-password": acctest.RandString(10),
"fabric-service-profile-uuid": spUuid.(string),
"connection-resourceName": "test",
"connection-name": fmt.Sprintf("%s-%s", tstResourcePrefix, acctest.RandString(6)),
"connection-profile_name": spName.(string),
"connection-bandwidth": 50,
"connection-notifications_type": "ALL",
"connection-seller_metro_code": "SV",
"connection-type": "EVPL_VC",
"connection-seller_region": "us-west-1",
"connection-authorization_key": authKey.(string),
"bgp-resourceName": "test",
"bgp-local_ip_address": "1.1.1.1/30",
"bgp-local_asn": 12345,
"bgp-remote_ip_address": "1.1.1.2",
"bgp-remote_asn": 22211,
}
contextWithChanges := copyMap(context)
contextWithChanges["bgp-authentication_key"] = acctest.RandString(10)
Expand All @@ -61,7 +69,7 @@ func TestAccNetworkBGP_CSR1000V_Single_AWS(t *testing.T) {
Providers: testAccProviders,
Steps: []resource.TestStep{
{
Config: newTestAccConfig(context).withDevice().withSSHUser().withConnection().withBGP().build(),
Config: newTestAccConfig(context).withDevice().withSSHUser().withVDConnection().withBGP().build(),
Check: resource.ComposeTestCheckFunc(
testAccNeBGPExists(resourceName, &bgpConfig),
testAccNeBGPAttributes(&bgpConfig, context),
Expand All @@ -75,7 +83,7 @@ func TestAccNetworkBGP_CSR1000V_Single_AWS(t *testing.T) {
ImportStateVerify: true,
},
{
Config: newTestAccConfig(contextWithChanges).withDevice().withSSHUser().withConnection().withBGP().build(),
Config: newTestAccConfig(contextWithChanges).withDevice().withSSHUser().withVDConnection().withBGP().build(),
Check: resource.ComposeTestCheckFunc(
testAccNeBGPExists(resourceName, &bgpConfig),
testAccNeBGPAttributes(&bgpConfig, contextWithChanges),
Expand All @@ -96,7 +104,7 @@ func testAccNetworkBGP(ctx map[string]interface{}) string {
var config string
config += nprintf(`
resource "equinix_network_bgp" "%{bgp-resourceName}" {
connection_id = equinix_ecx_l2_connection.%{connection-resourceName}.id
connection_id = equinix_fabric_connection.%{connection-resourceName}.id
local_ip_address = "%{bgp-local_ip_address}"
local_asn = %{bgp-local_asn}
remote_ip_address = "%{bgp-remote_ip_address}"
Expand All @@ -110,7 +118,7 @@ resource "equinix_network_bgp" "%{bgp-resourceName}" {
if _, ok := ctx["connection-secondary_name"]; ok {
config += nprintf(`
resource "equinix_network_bgp" "%{bgp-secondary_resourceName}" {
connection_id = equinix_ecx_l2_connection.%{connection-resourceName}.id
connection_id = equinix_fabric_connection.%{connection-resourceName}.id
local_ip_address = "%{bgp-secondary_local_ip_address}"
local_asn = %{bgp-secondary_local_asn}
remote_ip_address = "%{bgp-secondary_remote_ip_address}"
Expand Down Expand Up @@ -162,7 +170,7 @@ func testAccNeBGPAttributes(bgpConfig *ne.BGPConfiguration, ctx map[string]inter
return fmt.Errorf("authentication_key does not match %v - %v", ne.StringValue(bgpConfig.AuthenticationKey), v)
}
if v, ok := ctx["connection-resourceName"]; ok {
connResourceName := "equinix_ecx_l2_connection." + v.(string)
connResourceName := "equinix_fabric_connection." + v.(string)
rs, ok := s.RootModule().Resources[connResourceName]
if !ok {
return fmt.Errorf("related connection resource not found: %s", connResourceName)
Expand All @@ -184,3 +192,165 @@ func testAccNeBGPAttributes(bgpConfig *ne.BGPConfiguration, ctx map[string]inter
return nil
}
}

func testAccVDFabricL2Connection(ctx map[string]interface{}) string {
var config string
if _, ok := ctx["zside-service_token"]; !ok {
if _, ok := ctx["connection-profile_uuid"]; !ok {
config += nprintf(`
data "equinix_fabric_service_profile" "pri" {
uuid = "%{fabric-service-profile-uuid}"
}`, ctx)
}
}
if _, ok := ctx["connection-secondary_profile_name"]; ok {
config += nprintf(`
data "equinix_fabric_service_profile" "sec" {
uuid = "%{fabric-service-profile-uuid}"
}`, ctx)
}

config += nprintf(`
resource "equinix_fabric_connection" "%{connection-resourceName}" {
name = "%{connection-name}"
type = "EVPL_VC"
bandwidth = %{connection-bandwidth}
notifications {
type = "ALL"
emails = %{device-notifications}
}
a_side {
access_point {
type = "VD"
virtual_device {
type = "EDGE"
uuid = equinix_network_device.%{device-resourceName}.id
}
interface {
type = "CLOUD"
id = 7
}
}
}
z_side {
access_point {
type = "SP"
authentication_key = "%{connection-authorization_key}"
seller_region = "%{connection-seller_region}"
profile {
type = "L2_PROFILE"
uuid = "%{fabric-service-profile-uuid}"
}
location {
metro_code = "%{connection-seller_metro_code}"
}
}
}`, ctx)

if _, ok := ctx["service_token"]; ok {
config += nprintf(`
service_token = "%{service_token}"`, ctx)
}
if _, ok := ctx["zside-service_token"]; ok {
config += nprintf(`
zside_service_token = "%{zside-service_token}"`, ctx)
}
if _, ok := ctx["zside-port_uuid"]; ok {
config += nprintf(`
zside_port_uuid = "%{zside-port_uuid}"`, ctx)
}
if _, ok := ctx["connection-purchase_order_number"]; ok {
config += nprintf(`
purchase_order_number = "%{connection-purchase_order_number}"`, ctx)
}

if _, ok := ctx["port-uuid"]; ok {
config += nprintf(`
port_uuid = "%{port-uuid}"`, ctx)
} else if _, ok := ctx["port-resourceName"]; ok {
config += nprintf(`
port_uuid = data.equinix_ecx_port.%{port-resourceName}.id`, ctx)
}
if _, ok := ctx["connection-vlan_stag"]; ok {
config += nprintf(`
vlan_stag = %{connection-vlan_stag}`, ctx)
}
if _, ok := ctx["connection-vlan_ctag"]; ok {
config += nprintf(`
vlan_ctag = %{connection-vlan_ctag}`, ctx)
}
if _, ok := ctx["connection-named_tag"]; ok {
config += nprintf(`
named_tag = "%{connection-named_tag}"`, ctx)
}
if _, ok := ctx["connection-device_interface_id"]; ok {
config += nprintf(`
device_interface_id = %{connection-device_interface_id}`, ctx)
}
if _, ok := ctx["connection-secondary_name"]; ok {
config += nprintf(`
secondary_connection {
name = "%{connection-secondary_name}"`, ctx)
if _, ok := ctx["connection-secondary_profile_name"]; ok {
config += nprintf(`
profile_uuid = data.equinix_fabric_sellerprofile.sec.id`, ctx)
}
if _, ok := ctx["secondary-port_uuid"]; ok {
config += nprintf(`
port_uuid = "%{secondary-port_uuid}"`, ctx)
} else if _, ok := ctx["port-secondary_resourceName"]; ok {
config += nprintf(`
port_uuid = data.equinix_ecx_port.%{port-secondary_resourceName}.id`, ctx)
}
if _, ok := ctx["device-secondary_name"]; ok {
config += nprintf(`
device_uuid = equinix_network_device.%{device-resourceName}.redundant_id`, ctx)
}
if _, ok := ctx["connection-secondary_vlan_stag"]; ok {
config += nprintf(`
vlan_stag = %{connection-secondary_vlan_stag}`, ctx)
}
if _, ok := ctx["connection-secondary_vlan_ctag"]; ok {
config += nprintf(`
vlan_ctag = %{connection-secondary_vlan_ctag}`, ctx)
}
if _, ok := ctx["connection-secondary_device_interface_id"]; ok {
config += nprintf(`
device_interface_id = %{connection-secondary_device_interface_id}`, ctx)
}
if _, ok := ctx["connection-secondary_speed"]; ok {
config += nprintf(`
speed = %{connection-secondary_speed}`, ctx)
}
if _, ok := ctx["connection-secondary_speed_unit"]; ok {
config += nprintf(`
speed_unit = "%{connection-secondary_speed_unit}"`, ctx)
}
if _, ok := ctx["connection-secondary_seller_metro_code"]; ok {
config += nprintf(`
seller_metro_code = "%{connection-secondary_seller_metro_code}"`, ctx)
}
if _, ok := ctx["connection-secondary_seller_region"]; ok {
config += nprintf(`
seller_region = "%{connection-secondary_seller_region}"`, ctx)
}
if _, ok := ctx["connection-secondary_authorization_key"]; ok {
config += nprintf(`
authorization_key = "%{connection-secondary_authorization_key}"`, ctx)
}
if _, ok := ctx["secondary-service_token"]; ok {
config += nprintf(`
service_token = "%{secondary-service_token}"`, ctx)
}
config += `
}`
}
config += `
}`
return config
}

func (t *testAccConfig) withVDConnection() *testAccConfig {
t.config += testAccVDFabricL2Connection(t.ctx)
return t
}
7 changes: 6 additions & 1 deletion equinix/resource_network_device_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

const (
networkDeviceProjectId = "TF_ACC_NETWORK_DEVICE_PROJECT_ID"
networkDeviceAccountNameEnvVar = "TF_ACC_NETWORK_DEVICE_BILLING_ACCOUNT_NAME"
networkDeviceSecondaryAccountNameEnvVar = "TF_ACC_NETWORK_DEVICE_SECONDARY_BILLING_ACCOUNT_NAME"
networkDeviceMetroEnvVar = "TF_ACC_NETWORK_DEVICE_METRO"
Expand Down Expand Up @@ -86,6 +87,7 @@ func testSweepNetworkDevice(region string) error {
func TestAccNetworkDevice_CSR1000V_HA_Managed_Sub(t *testing.T) {
metro, _ := schema.EnvDefaultFunc(networkDeviceMetroEnvVar, "SV")()
accountName, _ := schema.EnvDefaultFunc(networkDeviceAccountNameEnvVar, "")()
projectId, _ := schema.EnvDefaultFunc(networkDeviceProjectId, "")()
context := map[string]interface{}{
"device-resourceName": "test",
"device-account_name": accountName.(string),
Expand All @@ -96,6 +98,7 @@ func TestAccNetworkDevice_CSR1000V_HA_Managed_Sub(t *testing.T) {
"device-throughput_unit": "Mbps",
"device-metro_code": metro.(string),
"device-type_code": "CSR1000V",
"device-project_id": projectId.(string),
"device-package_code": "SEC",
"device-notifications": []string{"marry@equinix.com", "john@equinix.com"},
"device-hostname": fmt.Sprintf("tf-%s", acctest.RandString(41)),
Expand Down Expand Up @@ -1241,7 +1244,8 @@ func testAccNetworkDevice(ctx map[string]interface{}) string {
config += nprintf(`
data "equinix_network_account" "test" {
metro_code = "%{device-metro_code}"
status = "Active"`, ctx)
status = "Active"
project_id = "%{device-project_id}"`, ctx)
if v, ok := ctx["device-account_name"]; ok && !isEmpty(v) {
config += nprintf(`
name = "%{device-account_name}"`, ctx)
Expand All @@ -1267,6 +1271,7 @@ resource "equinix_network_device" "%{device-resourceName}" {
name = "%{device-name}"
metro_code = "%{device-metro_code}"
type_code = "%{device-type_code}"
project_id = "%{device-project_id}"
package_code = "%{device-package_code}"
notifications = %{device-notifications}
term_length = %{device-term_length}
Expand Down

0 comments on commit 3072853

Please sign in to comment.