Skip to content

Commit

Permalink
fix: Update Fabric Terraform Resources and Data sources for latest Fa…
Browse files Browse the repository at this point in the history
…bric … (#799)

* Upgrade equinix-sdk-go to v0.46.0
* Update Port models to match changes in new Fabric SDK
* Update SimplifiedAccount to match changes in new Fabric SDK
  • Loading branch information
thogarty authored Oct 21, 2024
1 parent 343c8fc commit ca8dd81
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 56 deletions.
14 changes: 8 additions & 6 deletions equinix/data_source_fabric_port_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package equinix_test

import (
"fmt"
"github.com/equinix/equinix-sdk-go/services/fabricv4"
"github.com/equinix/terraform-provider-equinix/internal/fabric/testing_helpers"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/fabric/testing_helpers"

"github.com/equinix/equinix-sdk-go/services/fabricv4"

"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)

func TestAccDataSourceFabricPort_PNFV(t *testing.T) {
ports := testing_helpers.GetFabricEnvPorts(t)
var port fabricv4.PortResponse
var port fabricv4.Port
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["pnfv"]["dot1q"][0]
Expand Down Expand Up @@ -65,7 +67,7 @@ func testDataSourceFabricPort(port_uuid string) string {

func TestAccDataSourceFabricPorts_PNFV(t *testing.T) {
ports := testing_helpers.GetFabricEnvPorts(t)
var port fabricv4.PortResponse
var port fabricv4.Port
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["pnfv"]["dot1q"][0]
Expand Down Expand Up @@ -120,7 +122,7 @@ func testDataSourceFabricPorts(port_name string) string {

func TestAccDataSourceFabricPort_PPDS(t *testing.T) {
ports := testing_helpers.GetFabricEnvPorts(t)
var port fabricv4.PortResponse
var port fabricv4.Port
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["ppds"]["dot1q"][0]
Expand Down Expand Up @@ -165,7 +167,7 @@ func TestAccDataSourceFabricPort_PPDS(t *testing.T) {

func TestAccDataSourceFabricPorts_PPDS(t *testing.T) {
ports := testing_helpers.GetFabricEnvPorts(t)
var port fabricv4.PortResponse
var port fabricv4.Port
var portType, portState, portEncapsulationType, portRedundancyPriority string
if len(ports) > 0 {
port = ports["ppds"]["dot1q"][0]
Expand Down
6 changes: 3 additions & 3 deletions equinix/resource_fabric_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,11 @@ func resourceFabricPortRead(ctx context.Context, d *schema.ResourceData, meta in
return setFabricPortMap(d, port)
}

func fabricPortMap(port *fabricv4.PortResponse) map[string]interface{} {
func fabricPortMap(port *fabricv4.Port) map[string]interface{} {
operation := port.GetOperation()
redundancy := port.GetRedundancy()
account := port.GetAccount()
changelog := port.GetChangelog()
changelog := port.GetChangeLog()
location := port.GetLocation()
device := port.GetDevice()
encapsulation := port.GetEncapsulation()
Expand All @@ -398,7 +398,7 @@ func fabricPortMap(port *fabricv4.PortResponse) map[string]interface{} {
}
}

func setFabricPortMap(d *schema.ResourceData, port *fabricv4.PortResponse) diag.Diagnostics {
func setFabricPortMap(d *schema.ResourceData, port *fabricv4.Port) diag.Diagnostics {
diags := diag.Diagnostics{}
err := equinix_schema.SetMap(d, fabricPortMap(port))
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/equinix/terraform-provider-equinix
go 1.22

require (
github.com/equinix/equinix-sdk-go v0.45.0
github.com/equinix/equinix-sdk-go v0.46.0
github.com/equinix/ne-go v1.17.0
github.com/equinix/oauth2-go v1.0.0
github.com/equinix/rest-go v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/equinix/equinix-sdk-go v0.45.0 h1:M1moRw4Zt/nkxskDqzslfBc5TgB+QbqBiqBEfPkhl/Y=
github.com/equinix/equinix-sdk-go v0.45.0/go.mod h1:hEb3XLaedz7xhl/dpPIS6eOIiXNPeqNiVoyDrT6paIg=
github.com/equinix/equinix-sdk-go v0.46.0 h1:ldQo4GtXNr+0XsThQJf/pUdx5wcLFe9QpLFtAwonqH8=
github.com/equinix/equinix-sdk-go v0.46.0/go.mod h1:hEb3XLaedz7xhl/dpPIS6eOIiXNPeqNiVoyDrT6paIg=
github.com/equinix/ne-go v1.17.0 h1:+wZq0GNognpiTHTsBXtATOCphTFvnowF046NzQXj0n0=
github.com/equinix/ne-go v1.17.0/go.mod h1:eHkkxM4nbTB7DZ9X9zGnwfYnxIJWIsU3aHA+FAoZ1EI=
github.com/equinix/oauth2-go v1.0.0 h1:fHtAPGq82PdgtK5vEThs8Vwz6f7D/8SX4tE3NJu+KcU=
Expand Down
55 changes: 17 additions & 38 deletions internal/fabric/schema/fabric_common_mapping_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import (
"github.com/equinix/equinix-sdk-go/services/fabricv4"
"github.com/equinix/terraform-provider-equinix/internal/converters"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"strconv"
)

func OrderTerraformToGo(orderTerraform []interface{}) fabricv4.Order {
if orderTerraform == nil || len(orderTerraform) == 0 {
if len(orderTerraform) == 0 {
return fabricv4.Order{}
}
var order fabricv4.Order
Expand Down Expand Up @@ -50,39 +49,19 @@ func OrderGoToTerraform(order *fabricv4.Order) *schema.Set {
return orderSet
}

func AccountGoToTerraform[accountType *fabricv4.SimplifiedAccount | *fabricv4.SimplifiedAccountPortResponse](accountParam accountType) *schema.Set {
if accountParam == nil {
func AccountGoToTerraform(account *fabricv4.SimplifiedAccount) *schema.Set {
if account == nil {
return nil
}

mappedAccount := map[string]interface{}{}

switch account := (interface{})(accountParam).(type) {
case *fabricv4.SimplifiedAccount:
mappedAccount = map[string]interface{}{
"account_number": int(account.GetAccountNumber()),
"account_name": account.GetAccountName(),
"org_id": int(account.GetOrgId()),
"organization_name": account.GetOrganizationName(),
"global_org_id": account.GetGlobalOrgId(),
"global_organization_name": account.GetGlobalOrganizationName(),
"global_cust_id": account.GetGlobalCustId(),
"ucm_id": account.GetUcmId(),
}
case *fabricv4.SimplifiedAccountPortResponse:
accountNumber, _ := strconv.Atoi(account.GetAccountNumber())
orgId, _ := strconv.Atoi(account.GetOrgId())

mappedAccount = map[string]interface{}{
"account_number": accountNumber,
"account_name": account.GetAccountName(),
"org_id": orgId,
"organization_name": account.GetOrganizationName(),
"global_org_id": account.GetGlobalOrgId(),
"global_organization_name": account.GetGlobalOrganizationName(),
"global_cust_id": account.GetGlobalCustId(),
"ucm_id": account.GetUcmId(),
}
mappedAccount := map[string]interface{}{
"account_number": int(account.GetAccountNumber()),
"account_name": account.GetAccountName(),
"org_id": int(account.GetOrgId()),
"organization_name": account.GetOrganizationName(),
"global_org_id": account.GetGlobalOrgId(),
"global_organization_name": account.GetGlobalOrganizationName(),
"global_cust_id": account.GetGlobalCustId(),
"ucm_id": account.GetUcmId(),
}

accountSet := schema.NewSet(
Expand All @@ -94,7 +73,7 @@ func AccountGoToTerraform[accountType *fabricv4.SimplifiedAccount | *fabricv4.Si
}

func NotificationsTerraformToGo(notificationsTerraform []interface{}) []fabricv4.SimplifiedNotification {
if notificationsTerraform == nil || len(notificationsTerraform) == 0 {
if len(notificationsTerraform) == 0 {
return nil
}
notifications := make([]fabricv4.SimplifiedNotification, len(notificationsTerraform))
Expand Down Expand Up @@ -131,7 +110,7 @@ func NotificationsGoToTerraform(notifications []fabricv4.SimplifiedNotification)
}

func LocationTerraformToGo(locationList []interface{}) fabricv4.SimplifiedLocation {
if locationList == nil || len(locationList) == 0 {
if len(locationList) == 0 {
return fabricv4.SimplifiedLocation{}
}

Expand Down Expand Up @@ -175,7 +154,7 @@ func LocationGoToTerraform(location *fabricv4.SimplifiedLocation) *schema.Set {
}

func LocationWithoutIBXTerraformToGo(locationList []interface{}) fabricv4.SimplifiedLocationWithoutIBX {
if locationList == nil || len(locationList) == 0 {
if len(locationList) == 0 {
return fabricv4.SimplifiedLocationWithoutIBX{}
}

Expand All @@ -201,7 +180,7 @@ func LocationWithoutIBXGoToTerraform(location *fabricv4.SimplifiedLocationWithou
}

func ProjectTerraformToGo(projectTerraform []interface{}) fabricv4.Project {
if projectTerraform == nil || len(projectTerraform) == 0 {
if len(projectTerraform) == 0 {
return fabricv4.Project{}
}
var project fabricv4.Project
Expand Down Expand Up @@ -253,7 +232,7 @@ func ChangeLogGoToTerraform(changeLog *fabricv4.Changelog) *schema.Set {
}

func ErrorGoToTerraform(errors []fabricv4.Error) []interface{} {
if errors == nil || len(errors) == 0 {
if len(errors) == 0 {
return nil
}
mappedErrors := make([]interface{}, len(errors))
Expand Down
2 changes: 1 addition & 1 deletion internal/fabric/testing_helpers/env_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
FabricSubscriptionEnvVar = "TF_ACC_FABRIC_MARKET_PLACE_SUBSCRIPTION_ID"
)

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

func GetFabricEnvPorts(t *testing.T) EnvPorts {
var ports EnvPorts
Expand Down
9 changes: 5 additions & 4 deletions internal/resources/fabric/connection/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package connection_test
import (
"context"
"fmt"
"testing"
"time"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/fabric/testing_helpers"
"github.com/equinix/terraform-provider-equinix/internal/resources/fabric/connection"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
)
Expand Down Expand Up @@ -325,7 +326,7 @@ func testAccFabricCreateCloudRouter2PortConnectionConfig(name, portUuid string)
resource "equinix_fabric_cloud_router" "this" {
type = "XF_ROUTER"
name = "Test_PFCR"
name = "Conn_Test_PFCR"
location{
metro_code = "SV"
}
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/fabric/marketplace/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func subscriptionMap(subs *fabricv4.SubscriptionResponse) map[string]interface{}
subscription := make(map[string]interface{})
subscription["href"] = subs.GetHref()
subscription["uuid"] = subs.GetUuid()
subscription["status"] = subs.GetStatus()
subscription["status"] = subs.GetState()
subscription["marketplace"] = subs.GetMarketplace()
subscription["offer_type"] = subs.GetOfferType()
subscription["is_auto_renew"] = subs.GetIsAutoRenew()
Expand Down

0 comments on commit ca8dd81

Please sign in to comment.