From ca8dd81b6cdabeaa01e89fd20486ef20dd48869d Mon Sep 17 00:00:00 2001 From: thogarty <139183873+thogarty@users.noreply.github.com> Date: Mon, 21 Oct 2024 10:49:28 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20Update=20Fabric=20Terraform=20Resources?= =?UTF-8?q?=20and=20Data=20sources=20for=20latest=20Fabric=20=E2=80=A6=20(?= =?UTF-8?q?#799)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- equinix/data_source_fabric_port_acc_test.go | 14 +++-- equinix/resource_fabric_port.go | 6 +- go.mod | 2 +- go.sum | 4 +- .../schema/fabric_common_mapping_helpers.go | 55 ++++++------------- internal/fabric/testing_helpers/env_data.go | 2 +- .../fabric/connection/resource_test.go | 9 +-- .../resources/fabric/marketplace/models.go | 2 +- 8 files changed, 38 insertions(+), 56 deletions(-) diff --git a/equinix/data_source_fabric_port_acc_test.go b/equinix/data_source_fabric_port_acc_test.go index b23bcb7d5..f7a815355 100644 --- a/equinix/data_source_fabric_port_acc_test.go +++ b/equinix/data_source_fabric_port_acc_test.go @@ -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] @@ -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] @@ -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] @@ -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] diff --git a/equinix/resource_fabric_port.go b/equinix/resource_fabric_port.go index 588b72687..85146f93f 100644 --- a/equinix/resource_fabric_port.go +++ b/equinix/resource_fabric_port.go @@ -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() @@ -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 { diff --git a/go.mod b/go.mod index 6763c9fa5..45f5af140 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index ba24b2df6..384ca31c6 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/fabric/schema/fabric_common_mapping_helpers.go b/internal/fabric/schema/fabric_common_mapping_helpers.go index 387248bd1..986b93cb9 100644 --- a/internal/fabric/schema/fabric_common_mapping_helpers.go +++ b/internal/fabric/schema/fabric_common_mapping_helpers.go @@ -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 @@ -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( @@ -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)) @@ -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{} } @@ -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{} } @@ -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 @@ -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)) diff --git a/internal/fabric/testing_helpers/env_data.go b/internal/fabric/testing_helpers/env_data.go index b0c02ed87..07cd5db86 100644 --- a/internal/fabric/testing_helpers/env_data.go +++ b/internal/fabric/testing_helpers/env_data.go @@ -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 diff --git a/internal/resources/fabric/connection/resource_test.go b/internal/resources/fabric/connection/resource_test.go index f728fa2ee..93193f11e 100644 --- a/internal/resources/fabric/connection/resource_test.go +++ b/internal/resources/fabric/connection/resource_test.go @@ -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" ) @@ -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" } diff --git a/internal/resources/fabric/marketplace/models.go b/internal/resources/fabric/marketplace/models.go index 5e8c328d9..6eda1574e 100644 --- a/internal/resources/fabric/marketplace/models.go +++ b/internal/resources/fabric/marketplace/models.go @@ -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()