Skip to content

Commit

Permalink
refactor: fabric connection equinix sdk go migration (#606)
Browse files Browse the repository at this point in the history
* Removed all references to `fabric-go` and replaced with feature parity
of `equinix-sdk-go/fabricv4`
* Using reference to branch `equinix-sdk-go-migration` in code review on
equinix-sdk-go/fabricv4 repo
* Patches in this branch are necessary to resolve issues where the
Fabric APIs are not adhering to API specs
* Tickets have been cut for Fabric Teams to resolve; just using patching
as short term fix
* Use Getters+Setters for all setting and retrieval of
`equinix-sdk-go/fabricv4` structs
* Improve request creation by only setting attributes on Go structs when
they are given in the Terraform. Removes zero valued entries in API
requests causing unintended side effects
* Updated acceptance tests to account for SDK update. 
* Updated config to create `equinix-sdk-go/fabricv4` using correct auth
method
* Instantiated `equinix-sdk-go/fabricv4` with the correct user agent for
Terraform to be used in metrics
* Handling error type assertions properly to avoid chaining errors
during runtime
  • Loading branch information
thogarty committed Apr 19, 2024
1 parent bf9dac7 commit 67e172f
Show file tree
Hide file tree
Showing 21 changed files with 1,924 additions and 1,946 deletions.
7 changes: 5 additions & 2 deletions docs/resources/equinix_fabric_cloud_router.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ resource "equinix_fabric_cloud_router" "new_cloud_router"{
- `location` (Block Set, Min: 1, Max: 1) Fabric Cloud Router location (see [below for nested schema](#nestedblock--location))
- `name` (String) Fabric Cloud Router name. An alpha-numeric 24 characters string which can include only hyphens and underscores
- `notifications` (Block List, Min: 1) Preferences for notifications on Fabric Cloud Router configuration or status changes (see [below for nested schema](#nestedblock--notifications))
- `order` (Block Set, Min: 1, Max: 1) Order information related to this Fabric Cloud Router (see [below for nested schema](#nestedblock--order))
- `package` (Block Set, Min: 1, Max: 1) Fabric Cloud Router Package Type (see [below for nested schema](#nestedblock--package))
- `project` (Block Set, Min: 1, Max: 1) Customer resource hierarchy project information. Applicable to customers onboarded to Equinix Identity and Access Management. For more information see Identity and Access Management: Projects (see [below for nested schema](#nestedblock--project))
- `type` (String) Defines the FCR type like; XF_ROUTER
Expand All @@ -60,6 +59,7 @@ resource "equinix_fabric_cloud_router" "new_cloud_router"{

- `description` (String) Customer-provided Fabric Cloud Router description
- `href` (String) Fabric Cloud Router URI information
- `order` (Block Set, Min: 1, Max: 1) Order information related to this Fabric Cloud Router (see [below for nested schema](#nestedblock--order))
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
- `uuid` (String) Equinix-assigned Fabric Cloud Router identifier

Expand Down Expand Up @@ -112,10 +112,13 @@ Optional:

Optional:

- `purchase_order_number` (String) Purchase order number

Read-Only:

- `billing_tier` (String) Billing tier for connection bandwidth
- `order_id` (String) Order Identification
- `order_number` (String) Order Reference Number
- `purchase_order_number` (String) Purchase order number


<a id="nestedblock--package"></a>
Expand Down
7 changes: 5 additions & 2 deletions docs/resources/equinix_fabric_connection.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,14 @@ Port to IBM Connections could be modified from IBM Service Provider Side by usin
- `bandwidth` (Number) Connection bandwidth in Mbps
- `name` (String) Connection name. An alpha-numeric 24 characters string which can include only hyphens and underscores
- `notifications` (Block List, Min: 1) Preferences for notifications on connection configuration or status changes (see [below for nested schema](#nestedblock--notifications))
- `order` (Block Set, Min: 1, Max: 1) Order details (see [below for nested schema](#nestedblock--order))
- `type` (String) Defines the connection type like EVPL_VC, EPL_VC, IPWAN_VC, IP_VC, ACCESS_EPL_VC, EVPLAN_VC, EPLAN_VC, EIA_VC, EC_VC
- `z_side` (Block Set, Min: 1, Max: 1) Destination or Provider side connection configuration object of the multi-segment connection (see [below for nested schema](#nestedblock--z_side))

### Optional

- `additional_info` (List of Map of String) Connection additional information
- `description` (String) Customer-provided connection description
- `order` (Block Set, Min: 1, Max: 1) Order details (see [below for nested schema](#nestedblock--order))
- `project` (Block Set, Max: 1) Project information (see [below for nested schema](#nestedblock--project))
- `redundancy` (Block Set, Max: 1) Connection Redundancy Configuration (see [below for nested schema](#nestedblock--redundancy))
- `timeouts` (Block, Optional) (see [below for nested schema](#nestedblock--timeouts))
Expand Down Expand Up @@ -909,10 +909,13 @@ Optional:

Optional:

- `purchase_order_number` (String) Purchase order number

Read-Only:

- `billing_tier` (String) Billing tier for connection bandwidth
- `order_id` (String) Order Identification
- `order_number` (String) Order Reference Number
- `purchase_order_number` (String) Purchase order number


<a id="nestedblock--z_side"></a>
Expand Down
2 changes: 1 addition & 1 deletion equinix/data_source_fabric_cloud_router_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
func TestAccDataSourceFabricCloudRouter_PFCR(t *testing.T) {

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
Expand Down
6 changes: 3 additions & 3 deletions equinix/data_source_fabric_connection_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ func TestAccFabricDataSourceConnection_PFCR(t *testing.T) {
ports := GetFabricEnvPorts(t)
var aSidePortUuid, zSidePortUuid string
if len(ports) > 0 {
aSidePortUuid = ports["pfcr"]["dot1q"][0].Uuid
zSidePortUuid = ports["pfcr"]["dot1q"][1].Uuid
aSidePortUuid = ports["pfcr"]["dot1q"][0].GetUuid()
zSidePortUuid = ports["pfcr"]["dot1q"][1].GetUuid()
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: CheckConnectionDelete,
Steps: []resource.TestStep{
Expand Down
2 changes: 1 addition & 1 deletion equinix/data_source_fabric_network_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

func TestAccDataSourceFabricNetwork_PFCR(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
Expand Down
44 changes: 24 additions & 20 deletions equinix/data_source_fabric_port_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package equinix_test
import (
"encoding/json"
"fmt"
v4 "github.com/equinix-labs/fabric-go/fabric/v4"
"github.com/equinix/equinix-sdk-go/services/fabricv4"
"os"
"testing"

Expand All @@ -15,7 +15,7 @@ const (
FabricDedicatedPortEnvVar = "TF_ACC_FABRIC_DEDICATED_PORTS"
)

type EnvPorts map[string]map[string][]v4.Port
type EnvPorts map[string]map[string][]fabricv4.PortResponse

func GetFabricEnvPorts(t *testing.T) EnvPorts {
var ports EnvPorts
Expand All @@ -28,27 +28,29 @@ func GetFabricEnvPorts(t *testing.T) EnvPorts {

func TestAccDataSourceFabricPort_PNFV(t *testing.T) {
ports := GetFabricEnvPorts(t)
var port v4.Port
var port fabricv4.PortResponse
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["pnfv"]["dot1q"][0]
portType = string(*port.Type_)
portState = string(*port.State)
portEncapsulationType = port.Encapsulation.Type_
portRedundancyPriority = string(*port.Redundancy.Priority)
portType = string(port.GetType())
portState = string(port.GetState())
portEncapsulation := port.GetEncapsulation()
portEncapsulationType = string(portEncapsulation.GetType())
portRedundancy := port.GetRedundancy()
portRedundancyPriority = string(portRedundancy.GetPriority())
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPort(port.Uuid),
Config: testDataSourceFabricPort(port.GetUuid()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "id", port.Uuid),
"data.equinix_fabric_port.test", "id", port.GetUuid()),
resource.TestCheckResourceAttr(
"data.equinix_fabric_port.test", "name", port.Name),
"data.equinix_fabric_port.test", "name", port.GetName()),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_port.test", "bandwidth"),
resource.TestCheckResourceAttrSet(
Expand Down Expand Up @@ -79,27 +81,29 @@ func testDataSourceFabricPort(port_uuid string) string {

func TestAccDataSourceFabricPorts_PNFV(t *testing.T) {
ports := GetFabricEnvPorts(t)
var port v4.Port
var port fabricv4.PortResponse
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["pnfv"]["dot1q"][0]
portType = string(*port.Type_)
portState = string(*port.State)
portEncapsulationType = port.Encapsulation.Type_
portRedundancyPriority = string(*port.Redundancy.Priority)
portType = string(port.GetType())
portState = string(port.GetState())
portEncapsulation := port.GetEncapsulation()
portEncapsulationType = string(portEncapsulation.GetType())
portRedundancy := port.GetRedundancy()
portRedundancyPriority = string(portRedundancy.GetPriority())
}
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
ExternalProviders: acceptance.TestExternalProviders,
Providers: acceptance.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testDataSourceFabricPorts(port.Name),
Config: testDataSourceFabricPorts(port.GetName()),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "id", port.Uuid),
"data.equinix_fabric_ports.test", "id", port.GetUuid()),
resource.TestCheckResourceAttr(
"data.equinix_fabric_ports.test", "data.0.name", port.Name),
"data.equinix_fabric_ports.test", "data.0.name", port.GetName()),
resource.TestCheckResourceAttrSet(
"data.equinix_fabric_ports.test", "data.0.bandwidth"),
resource.TestCheckResourceAttrSet(
Expand Down
9 changes: 5 additions & 4 deletions equinix/data_source_fabric_service_profile_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,14 @@ func TestAccFabricReadServiceProfileByUuid_PFCR(t *testing.T) {
var portUuid, portMetroCode, portType string
if len(ports) > 0 {
port := ports["pfcr"]["dot1q"][0]
portUuid = port.Uuid
portMetroCode = port.Location.MetroCode
portType = string(*port.Type_)
portUuid = port.GetUuid()
portMetroCodeLocation := port.GetLocation()
portMetroCode = portMetroCodeLocation.GetMetroCode()
portType = string(port.GetType())
}

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.TestAccPreCheck(t) },
PreCheck: func() { acceptance.TestAccPreCheck(t); acceptance.TestAccPreCheckProviderConfigured(t) },
Providers: acceptance.TestAccProviders,
CheckDestroy: checkServiceProfileDelete,
Steps: []resource.TestStep{
Expand Down
Loading

0 comments on commit 67e172f

Please sign in to comment.