Skip to content

Commit

Permalink
TEMP use equinix/equinix-sdk-go@moar-spec-fixes to 'complete' the mig…
Browse files Browse the repository at this point in the history
…ration
  • Loading branch information
ctreatma committed Jan 25, 2024
1 parent 0e511f2 commit ffacb40
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/antihax/optional v1.0.0
github.com/equinix-labs/fabric-go v0.7.1
github.com/equinix/ecx-go/v2 v2.3.1
github.com/equinix/equinix-sdk-go v0.31.0
github.com/equinix/equinix-sdk-go v0.32.1-0.20240125200831-02238d07a989
github.com/equinix/ne-go v1.13.0
github.com/equinix/oauth2-go v1.0.0
github.com/equinix/rest-go v1.3.0
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,10 @@ github.com/equinix-labs/fabric-go v0.7.1 h1:4yk0IKXMcc72rkRVbcYHokAEc1uUB06t6NXK
github.com/equinix-labs/fabric-go v0.7.1/go.mod h1:oqgGS3GOI8hHGPJKsAwDOEX0qRHl52sJGvwA/zMSd90=
github.com/equinix/ecx-go/v2 v2.3.1 h1:gFcAIeyaEUw7S8ebqApmT7E/S7pC7Ac3wgScp89fkPU=
github.com/equinix/ecx-go/v2 v2.3.1/go.mod h1:FvCdZ3jXU8Z4CPKig2DT+4J2HdwgRK17pIcznM7RXyk=
github.com/equinix/equinix-sdk-go v0.31.0 h1:BVD67nmpPEutsCGkYDuy0rykGNeQ5H3FIX+Dz5DpP7w=
github.com/equinix/equinix-sdk-go v0.31.0/go.mod h1:qnpdRzVftHFNaJFk1VSIrAOTLrIoeDrxzUr3l8ARyvQ=
github.com/equinix/equinix-sdk-go v0.32.1-0.20240125194110-4088361fa6b7 h1:ipZkrpVU3xPEJp6uKkrDlDeEKGNkUNExtsAuHeakK4Q=
github.com/equinix/equinix-sdk-go v0.32.1-0.20240125194110-4088361fa6b7/go.mod h1:qnpdRzVftHFNaJFk1VSIrAOTLrIoeDrxzUr3l8ARyvQ=
github.com/equinix/equinix-sdk-go v0.32.1-0.20240125200831-02238d07a989 h1:tP2wIfYuDq6u/4rWf8uj8fYQTzRjmt9RCXki2S7aoaA=
github.com/equinix/equinix-sdk-go v0.32.1-0.20240125200831-02238d07a989/go.mod h1:qnpdRzVftHFNaJFk1VSIrAOTLrIoeDrxzUr3l8ARyvQ=
github.com/equinix/ne-go v1.13.0 h1:7mcEGnASjPVc2la/Q2WRCn2PcFVO3syXAd6YOU1lETw=
github.com/equinix/ne-go v1.13.0/go.mod h1:eHkkxM4nbTB7DZ9X9zGnwfYnxIJWIsU3aHA+FAoZ1EI=
github.com/equinix/oauth2-go v1.0.0 h1:fHtAPGq82PdgtK5vEThs8Vwz6f7D/8SX4tE3NJu+KcU=
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/metal/vlan/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func dataSourceMetalVlanRead(ctx context.Context, d *schema.ResourceData, meta i
"vlan_id": vlan.GetId(),
"project_id": vlan.AssignedTo.GetId(), // vlan assigned_to is an href; should be project?
"vxlan": vlan.GetVxlan(),
"facility": vlan.FacilityCode, // facility is deprecated, vlan is metro-scoped; remove this attr?
"facility": nil, //vlan.FacilityCode, // facility is deprecated, vlan is metro-scoped; remove this attr?
"metro": vlan.MetroCode,
"description": vlan.Description,
}))
Expand Down
15 changes: 3 additions & 12 deletions internal/resources/metal/vlan/datasource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,6 @@ func TestMetalVlan_MatchingVlan(t *testing.T) {
want: &metalv1.VirtualNetwork{Vxlan: metalv1.PtrInt32(123)},
wantErr: false,
},
{
name: "MatchingFac",
args: args{
vlans: []metalv1.VirtualNetwork{{FacilityCode: "fac"}},
facility: "fac",
},
want: &metalv1.VirtualNetwork{FacilityCode: "fac"},
wantErr: false,
},
{
name: "MatchingMet",
args: args{
Expand All @@ -272,7 +263,7 @@ func TestMetalVlan_MatchingVlan(t *testing.T) {
{
name: "SecondMatch",
args: args{
vlans: []metalv1.VirtualNetwork{{FacilityCode: "fac"}, {MetroCode: metalv1.PtrString("met")}},
vlans: []metalv1.VirtualNetwork{{MetroCode: metalv1.PtrString("fac")}, {MetroCode: metalv1.PtrString("met")}},
metro: "met",
},
want: &metalv1.VirtualNetwork{MetroCode: metalv1.PtrString("met")},
Expand All @@ -290,10 +281,10 @@ func TestMetalVlan_MatchingVlan(t *testing.T) {
{
name: "ComplexMatch",
args: args{
vlans: []metalv1.VirtualNetwork{{Vxlan: metalv1.PtrInt32(987), FacilityCode: "fac", MetroCode: metalv1.PtrString("skip")}, {VXLAN: metalv1.PtrInt32(123), FacilityCode: "fac", MetroCode: metalv1.PtrString("met")}, {Vxlan: metalv1.PtrInt32(456), FacilityCode: "fac", MetroCode: metalv1.PtrString("nope")}},
vlans: []metalv1.VirtualNetwork{{Vxlan: metalv1.PtrInt32(987), MetroCode: metalv1.PtrString("skip")}, {Vxlan: metalv1.PtrInt32(123), MetroCode: metalv1.PtrString("met")}, {Vxlan: metalv1.PtrInt32(456), MetroCode: metalv1.PtrString("nope")}},
metro: "met",
},
want: &metalv1.VirtualNetwork{Vxlan: metalv1.PtrInt32(123), FacilityCode: "fac", MetroCode: metalv1.PtrString("met")},
want: &metalv1.VirtualNetwork{Vxlan: metalv1.PtrInt32(123), MetroCode: metalv1.PtrString("met")},
wantErr: false,
},
{
Expand Down
9 changes: 4 additions & 5 deletions internal/resources/metal/vlan/matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

"github.com/equinix/equinix-sdk-go/services/metalv1"
equinix_errors "github.com/equinix/terraform-provider-equinix/internal/errors"
)

func MatchingVlan(vlans []metalv1.VirtualNetwork, vxlan int, projectID, facility, metro string) (*metalv1.VirtualNetwork, error) {
Expand All @@ -13,20 +12,20 @@ func MatchingVlan(vlans []metalv1.VirtualNetwork, vxlan int, projectID, facility
if vxlan != 0 && int(v.GetVxlan()) != vxlan {
continue
}
if facility != "" && v.FacilityCode != facility {
/*if facility != "" && v.FacilityCode != facility {
continue
}
}*/
if metro != "" && v.GetMetroCode() != metro {
continue
}
matches = append(matches, v)
}
if len(matches) > 1 {
return nil, equinix_errors.FriendlyError(fmt.Errorf("Project %s has more than one matching VLAN", projectID))
return nil, fmt.Errorf("Project %s has more than one matching VLAN", projectID)
}

if len(matches) == 0 {
return nil, equinix_errors.FriendlyError(fmt.Errorf("Project %s does not have matching VLANs", projectID))
return nil, fmt.Errorf("Project %s does not have matching VLANs", projectID)
}
return &matches[0], nil
}
20 changes: 10 additions & 10 deletions internal/resources/metal/vlan/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ func resourceMetalVlanCreate(ctx context.Context, d *schema.ResourceData, meta i
meta.(*config.Config).AddModuleToMetalGoUserAgent(d)
client := meta.(*config.Config).Metalgo

facRaw, facOk := d.GetOk("facility")
//facRaw, facOk := d.GetOk("facility")
metroRaw, metroOk := d.GetOk("metro")
vxlanRaw, vxlanOk := d.GetOk("vxlan")
vxlanRaw, _ := d.GetOk("vxlan")

if !facOk && !metroOk {
if /*!facOk &&*/ !metroOk {
return diag.Errorf("one of facility or metro must be configured")
}
if facOk && vxlanOk {
/*if facOk && vxlanOk {
return diag.Errorf("you can set vxlan only for metro vlans")
}
}*/

createRequest := metalv1.VirtualNetworkCreateInput{
Description: metalv1.PtrString(d.Get("description").(string)),
Expand All @@ -104,9 +104,9 @@ func resourceMetalVlanCreate(ctx context.Context, d *schema.ResourceData, meta i
createRequest.Metro = metalv1.PtrString(metroRaw.(string))
createRequest.Vxlan = metalv1.PtrInt32(int32(vxlanRaw.(int)))
}
if facOk {
/*if facOk {
createRequest.Facility = facRaw.(string)
}
}*/
vlan, _, err := client.VLANsApi.CreateVirtualNetwork(ctx, d.Get("project_id").(string)).VirtualNetworkCreateInput(createRequest).Execute()
if err != nil {
return diag.FromErr(equinix_errors.FriendlyError(err))
Expand All @@ -133,7 +133,7 @@ func resourceMetalVlanRead(ctx context.Context, d *schema.ResourceData, meta int
d.Set("description", vlan.Description)
d.Set("project_id", vlan.AssignedTo.GetId()) // assigned_to is a project but specced as an href
d.Set("vxlan", vlan.GetVxlan())
d.Set("facility", vlan.FacilityCode) // vlan spec does not include facility_code; should we remove it?
//d.Set("facility", vlan.FacilityCode) // vlan spec does not include facility_code; should we remove it?
d.Set("metro", vlan.MetroCode)
return nil
}
Expand All @@ -154,10 +154,10 @@ func resourceMetalVlanDelete(ctx context.Context, d *schema.ResourceData, meta i
// all device ports must be unassigned before delete
for _, i := range vlan.Instances {
for _, p := range i.NetworkPorts { // instances is specced as a list of href; should be devices?
for _, a := range p.AttachedVirtualNetworks {
for _, a := range p.VirtualNetworks { // ...aaaand device virtual_network is also an href
// a.ID is not set despite including instaces.network_ports.virtual_networks
// TODO(displague) packngo should offer GetID() that uses ID or Href
aID := path.Base(a.Href)
aID := path.Base(a.GetHref())

if aID == id {
portInput := metalv1.PortAssignInput{
Expand Down

0 comments on commit ffacb40

Please sign in to comment.