Skip to content

Commit 7297369

Browse files
author
Adam Mohammed
authored
fix: Properly handle deleting attached Metal VLANs (#967)
Occasionally, we hit some undefined/poorly-defined Metal API behavior when cleaning up VLANs which have active assignments. The VLAN resource delete function relies on making a call to `/metal/v1/virtual-networks/:id?include=instances,virtual_networks,metal_gateway`. Since each item in the comma-separated list is treated as an individual entity, if a previous call fetched `instances` without also including `virutal_networks` partial caching behavior causes the VLAN object that the provider relies on to only contain an `Href`. The delete code relied on the full object being there to compare the ID to the VLAN that is attempting to be deleted. In this PR, I've introduced `isVlanEqual` that is can compare eithe rthe full VLAN object, or the light reference. We'll have to address what the intended behavior is for this partial caching issue on the Metal API, but for now this addresses problems experienced in #902.
2 parents 62eb258 + 9b5826d commit 7297369

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

internal/resources/metal/vlan/resource.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"path"
78
"strings"
89

910
"github.com/equinix/equinix-sdk-go/services/metalv1"
@@ -236,7 +237,7 @@ func (r *Resource) Delete(ctx context.Context, request resource.DeleteRequest, r
236237

237238
vlan, resp, err := client.ProjectVirtualNetworks.Get(
238239
data.ID.ValueString(),
239-
&packngo.GetOptions{Includes: []string{"instances", "virtual_networks", "meta_gateway"}},
240+
&packngo.GetOptions{Includes: []string{"instances", "virtual_networks", "metal_gateway"}},
240241
)
241242
if err != nil {
242243
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
@@ -255,7 +256,7 @@ func (r *Resource) Delete(ctx context.Context, request resource.DeleteRequest, r
255256
for _, instance := range vlan.Instances {
256257
for _, port := range instance.NetworkPorts {
257258
for _, v := range port.AttachedVirtualNetworks {
258-
if v.ID == vlan.ID {
259+
if path.Base(v.Href) == vlan.ID {
259260
_, resp, err = client.Ports.Unassign(port.ID, vlan.ID)
260261
if equinix_errors.IgnoreResponseErrors(equinix_errors.HttpForbidden, equinix_errors.HttpNotFound)(resp, err) != nil {
261262
response.Diagnostics.AddError("Error unassign port with Vlan",

0 commit comments

Comments
 (0)