Skip to content

Commit

Permalink
fix function references, package names, etc. after move
Browse files Browse the repository at this point in the history
  • Loading branch information
ctreatma committed Jun 28, 2024
1 parent 0a573cd commit 08ad710
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 59 deletions.
5 changes: 3 additions & 2 deletions equinix/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/equinix/terraform-provider-equinix/internal/config"
fabric_connection "github.com/equinix/terraform-provider-equinix/internal/resources/fabric/connection"
fabric_network "github.com/equinix/terraform-provider-equinix/internal/resources/fabric/network"
metal_port "github.com/equinix/terraform-provider-equinix/internal/resources/metal/port"
"github.com/equinix/terraform-provider-equinix/internal/resources/metal/virtual_circuit"
"github.com/equinix/terraform-provider-equinix/internal/resources/metal/vrf"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
Expand Down Expand Up @@ -105,7 +106,7 @@ func Provider() *schema.Provider {
"equinix_metal_devices": dataSourceMetalDevices(),
"equinix_metal_device_bgp_neighbors": dataSourceMetalDeviceBGPNeighbors(),
"equinix_metal_plans": dataSourceMetalPlans(),
"equinix_metal_port": dataSourceMetalPort(),
"equinix_metal_port": metal_port.DataSource(),
"equinix_metal_reserved_ip_block": dataSourceMetalReservedIPBlock(),
"equinix_metal_spot_market_request": dataSourceMetalSpotMarketRequest(),
"equinix_metal_virtual_circuit": virtual_circuit.DataSource(),
Expand All @@ -128,7 +129,7 @@ func Provider() *schema.Provider {
"equinix_metal_project_api_key": resourceMetalProjectAPIKey(),
"equinix_metal_device": resourceMetalDevice(),
"equinix_metal_device_network_type": resourceMetalDeviceNetworkType(),
"equinix_metal_port": resourceMetalPort(),
"equinix_metal_port": metal_port.Resource(),
"equinix_metal_reserved_ip_block": resourceMetalReservedIPBlock(),
"equinix_metal_ip_attachment": resourceMetalIPAttachment(),
"equinix_metal_spot_market_request": resourceMetalSpotMarketRequest(),
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/metal/port/datasource.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package equinix
package port

import (
"github.com/equinix/terraform-provider-equinix/internal/network"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

func dataSourceMetalPort() *schema.Resource {
func DataSource() *schema.Resource {
return &schema.Resource{
ReadWithoutTimeout: resourceMetalPortRead,

Expand Down
19 changes: 10 additions & 9 deletions internal/resources/metal/port/datasource_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package equinix
package port_test

import (
"fmt"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
)
Expand All @@ -12,9 +13,9 @@ func TestAccDataSourceMetalPort_byName(t *testing.T) {
rs := acctest.RandString(10)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMetalPortConfig_byName(rs),
Expand Down Expand Up @@ -50,16 +51,16 @@ data "equinix_metal_port" "test" {
name = "eth0"
}
`, confAccMetalDevice_base(preferable_plans, preferable_metros, preferable_os), name, testDeviceTerminationTime())
`, acceptance.ConfAccMetalDevice_base(acceptance.Preferable_plans, acceptance.Preferable_metros, acceptance.Preferable_os), name, acceptance.TestDeviceTerminationTime())
}

func TestAccDataSourceMetalPort_byId(t *testing.T) {
rs := acctest.RandString(10)

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
Steps: []resource.TestStep{
{
Config: testAccDataSourceMetalPortConfig_byId(rs),
Expand Down Expand Up @@ -93,5 +94,5 @@ resource "equinix_metal_device" "test" {
data "equinix_metal_port" "test" {
port_id = equinix_metal_device.test.ports[0].id
}
`, confAccMetalDevice_base(preferable_plans, preferable_metros, preferable_os), name, testDeviceTerminationTime())
`, acceptance.ConfAccMetalDevice_base(acceptance.Preferable_plans, acceptance.Preferable_metros, acceptance.Preferable_os), name, acceptance.TestDeviceTerminationTime())
}
23 changes: 1 addition & 22 deletions internal/resources/metal/port/helpers.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package equinix
package port

import (
"context"
Expand Down Expand Up @@ -340,24 +340,3 @@ func portSanityChecks(cpr *ClientPortResource) error {

return nil
}

func portProperlyDestroyed(port *packngo.Port) error {
var errs []string
if !port.Data.Bonded {
errs = append(errs, fmt.Sprintf("port %s wasn't bonded after equinix_metal_port destroy;", port.ID))
}
if port.Type == "NetworkBondPort" && port.NetworkType != "layer3" {
errs = append(errs, "bond port should be in layer3 type after destroy;")
}
if port.NativeVirtualNetwork != nil {
errs = append(errs, "port should not have native VLAN assigned after destroy;")
}
if len(port.AttachedVirtualNetworks) != 0 {
errs = append(errs, "port should not have VLANs attached after destroy")
}
if len(errs) > 0 {
return fmt.Errorf("%s", errs)
}

return nil
}
31 changes: 27 additions & 4 deletions internal/resources/metal/port/resource.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package equinix
package port

import (
"context"
"fmt"
"log"
"time"

"slices"

equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
equinix_schema "github.com/equinix/terraform-provider-equinix/internal/schema"
"github.com/packethost/packngo"

"github.com/equinix/terraform-provider-equinix/internal/config"

Expand All @@ -27,7 +29,7 @@ var (
l3Types = []string{"layer3", "hybrid", "hybrid-bonded"}
)

func resourceMetalPort() *schema.Resource {
func Resource() *schema.Resource {
return &schema.Resource{
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Expand Down Expand Up @@ -217,7 +219,7 @@ func resourceMetalPortDelete(ctx context.Context, d *schema.ResourceData, meta i
// to reset the port to defaults we iterate through helpers (used in
// create/update), some of which rely on resource state. reuse those helpers by
// setting ephemeral state.
port := resourceMetalPort()
port := Resource()
copy := port.Data(d.State())
cpr.Resource = copy
if err = equinix_schema.SetMap(cpr.Resource, map[string]interface{}{
Expand All @@ -239,9 +241,30 @@ func resourceMetalPortDelete(ctx context.Context, d *schema.ResourceData, meta i
}
}
// TODO(displague) error or warn?
if warn := portProperlyDestroyed(cpr.Port); warn != nil {
if warn := ProperlyDestroyed(cpr.Port); warn != nil {
log.Printf("[WARN] %s\n", warn)
}
}
return nil
}

func ProperlyDestroyed(port *packngo.Port) error {
var errs []string
if !port.Data.Bonded {
errs = append(errs, fmt.Sprintf("port %s wasn't bonded after equinix_metal_port destroy;", port.ID))
}
if port.Type == "NetworkBondPort" && port.NetworkType != "layer3" {
errs = append(errs, "bond port should be in layer3 type after destroy;")
}
if port.NativeVirtualNetwork != nil {
errs = append(errs, "port should not have native VLAN assigned after destroy;")
}
if len(port.AttachedVirtualNetworks) != 0 {
errs = append(errs, "port should not have VLANs attached after destroy")
}
if len(errs) > 0 {
return fmt.Errorf("%s", errs)
}

return nil
}
42 changes: 22 additions & 20 deletions internal/resources/metal/port/resource_test.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package equinix
package port_test

import (
"fmt"
"regexp"
"testing"

"github.com/equinix/terraform-provider-equinix/internal/acceptance"
"github.com/equinix/terraform-provider-equinix/internal/config"
"github.com/equinix/terraform-provider-equinix/internal/resources/metal/port"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-plugin-testing/helper/acctest"
Expand Down Expand Up @@ -42,7 +44,7 @@ locals {
eth0_id = [for p in equinix_metal_device.test.ports: p.id if p.name == "eth0"][0]
}
`, confAccMetalDevice_base(preferable_plans, preferable_metros, preferable_os), name, testDeviceTerminationTime())
`, acceptance.ConfAccMetalDevice_base(acceptance.Preferable_plans, acceptance.Preferable_metros, acceptance.Preferable_os), name, acceptance.TestDeviceTerminationTime())
}

func confAccMetalPort_L3(name string) string {
Expand Down Expand Up @@ -237,9 +239,9 @@ resource "equinix_metal_vlan" "test" {
func TestAccMetalPort_hybridBondedVxlan(t *testing.T) {
rs := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: testAccMetalPortDestroyed,
Steps: []resource.TestStep{
{
Expand All @@ -266,9 +268,9 @@ func TestAccMetalPort_hybridBondedVxlan(t *testing.T) {
func TestAccMetalPort_L2IndividualNativeVlan(t *testing.T) {
rs := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: testAccMetalPortDestroyed,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -299,9 +301,9 @@ func TestAccMetalPort_L2IndividualNativeVlan(t *testing.T) {
func testAccMetalPortTemplate(t *testing.T, conf func(string) string, expectedType string) {
rs := acctest.RandString(10)
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: testAccMetalPortDestroyed,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -356,7 +358,7 @@ func TestAccMetalPort_hybridBonded(t *testing.T) {
}

func testAccMetalPortDestroyed(s *terraform.State) error {
client := testAccProvider.Meta().(*config.Config).Metal
client := acceptance.TestAccProvider.Meta().(*config.Config).Metal

port_ids := []string{}

Expand All @@ -373,7 +375,7 @@ func testAccMetalPortDestroyed(s *terraform.State) error {
if err != nil {
return fmt.Errorf("Error getting port %s during destroy check", pid)
}
err = portProperlyDestroyed(p)
err = port.ProperlyDestroyed(p)
if err != nil {
return err
}
Expand All @@ -391,7 +393,7 @@ func testAccWaitForPortActive(deviceName, portName string) resource.ImportStateI
return "", fmt.Errorf("No Record ID is set")
}

meta := testAccProvider.Meta()
meta := acceptance.TestAccProvider.Meta()
rd := new(schema.ResourceData)
meta.(*config.Config).AddModuleToMetalUserAgent(rd)
client := meta.(*config.Config).Metal
Expand Down Expand Up @@ -422,9 +424,9 @@ func TestAccMetalPortCreate_hybridBonded_timeout(t *testing.T) {
deviceName := "equinix_metal_device.test"

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: testAccMetalPortDestroyed,
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -463,9 +465,9 @@ func TestAccMetalPortUpdate_hybridBonded_timeout(t *testing.T) {
rInt := acctest.RandInt()

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ExternalProviders: testExternalProviders,
ProtoV5ProviderFactories: testAccProtoV5ProviderFactories,
PreCheck: func() { acceptance.TestAccPreCheck(t) },
ExternalProviders: acceptance.TestExternalProviders,
ProtoV5ProviderFactories: acceptance.ProtoV5ProviderFactories,
CheckDestroy: testAccMetalPortDestroyed,
Steps: []resource.TestStep{
{
Expand Down

0 comments on commit 08ad710

Please sign in to comment.