F5Networks / terraform-provider-bigip

Terraform resources that can configure F5 BIG-IP products
https://registry.terraform.io/providers/F5Networks/bigip/latest/docs
Mozilla Public License 2.0
105 stars 119 forks source link

VCMP Guest deleteVirtualDisk only checks first disk name #1014

Closed ThomasBartnicki closed 1 month ago

ThomasBartnicki commented 1 month ago

Environment

Summary

When performing a terraform destroy on a vcmp guest, an error is thrown if the first virtual disk result doesn't match the one being deleted.

When looping through the virtual disks, we should move to the next one if the current one isn't the one we're trying to delete, not throw an error.

func deleteVirtualDisk(d *schema.ResourceData, meta interface{}) error {
    diskName, _ := d.Get("virtual_disk").(string)
    client := meta.(*bigip.BigIP)
    virtualDisks, err := client.GetVcmpDisks()
    if err != nil {
        return fmt.Errorf("error retrieving vCMP virtual disks: %v", err)
    }

    for _, disk := range virtualDisks.Disks {
        if strings.HasPrefix(disk.Name, diskName) {
            name := strings.Replace(disk.Name, "/", "~", 1)
            err := client.DeleteVcmpDisk(name)
            if err != nil {
                return fmt.Errorf("error deleting vCMP virtual disk: %v %v", diskName, err)
            }
        } else {
            return fmt.Errorf("cannot find vCMP virtual disk: %v ", diskName)
        }

    }
    return nil
}

Steps To Reproduce

Steps to reproduce the behavior:

Run a terraform destroy after having created a VCMP guest on a BigIP host with multiple virtual-disks on it.

  1. Provide terraform resource config which you are facing trouble along with the output of it. N/A
  2. To get to know more about the issue, provide terraform debug logs N/A
  3. To capture debug logs, export TF_LOG variable with debug ( export TF_LOG= DEBUG ) before runnning terraform apply/plan N/A
  4. As3/DO json along with the resource config( for AS3/DO resource issues ) N/A

Expected Behavior

Delete the virtual disk belonging to the current VCMP guest.

Actual Behavior

Throws an error if the first virtual disk in the list isn't the one belonging to the current VCMP guest.

Error thrown: Couldn't find disk: %s", disk.Name

pgouband commented 1 month ago

Hi @ThomasBartnicki,

In order to review and accept your commit, you need to sign a Customer License Agreement and send it to ecosystems_cla@f5.com

https://clouddocs.f5.com/products/orchestration/ansible/devel/_downloads/b35c2904c64e94ec52f5e300bfbebfc4/F5-Contributor-License-Agreement.pdf

pgouband commented 1 month ago

Hi,

Thanks for reporting. Added to the backlog and internal tracking ID for this request is: INFRAANO-1671.