Skip to content

Commit

Permalink
r/vmfs_datastore: Fix some error strings, refine retry waiter
Browse files Browse the repository at this point in the history
Some error string cleanup, and also an update to the delete retry
waiter so that it handles the actual ResourceInUse error instead of
doing a string match.
  • Loading branch information
vancluever committed Sep 1, 2017
1 parent 15c9b9a commit c617982
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
14 changes: 7 additions & 7 deletions vsphere/resource_vsphere_vmfs_datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package vsphere
import (
"context"
"fmt"
"regexp"
"time"

"github.com/hashicorp/terraform/helper/resource"
Expand All @@ -26,7 +25,7 @@ const (
// creation where rollback is not possible.
const formatCreateRollbackErrorUpdate = `
WARNING: Dangling resource!
There was an error extending your datastore with disk: %s:
There was an error extending your datastore with disk: %q:
%s
Additionally, there was an error removing the created datastore:
%s
Expand All @@ -49,12 +48,13 @@ You will need to remove this datastore manually before trying again.
// will require repair of the state before TF can continue.
const formatUpdateInconsistentState = `
WARNING: Inconsistent state!
Terraform was able to add disk %s, but could not save the update to the state.
Terraform was able to add disk %q, but could not save the update to the state.
The error was:
%s
This is more than likely a bug. Please report it at:
https://github.com/terraform-providers/terraform-provider-vsphere/issues
You will also need to repair your state before trying again.
Also, please try running "terraform refresh" to try to update the state before
trying again. If this fails, you may need to repair the state manually.
`

func resourceVSphereVmfsDatastore() *schema.Resource {
Expand Down Expand Up @@ -123,7 +123,7 @@ func resourceVSphereVmfsDatastoreCreate(d *schema.ResourceData, meta interface{}
// manually.
return fmt.Errorf(formatCreateRollbackErrorUpdate, disk, err, remErr)
}
return fmt.Errorf("error fetching datastore extend spec for disk %s: %s", disk, err)
return fmt.Errorf("error fetching datastore extend spec for disk %q: %s", disk, err)
}
ctx, cancel := context.WithTimeout(context.Background(), defaultAPITimeout)
defer cancel()
Expand All @@ -134,7 +134,7 @@ func resourceVSphereVmfsDatastoreCreate(d *schema.ResourceData, meta interface{}
// manually.
return fmt.Errorf(formatCreateRollbackErrorUpdate, disk, err, remErr)
}
return fmt.Errorf("error extending datastore with disk %s: %s", disk, err)
return fmt.Errorf("error extending datastore with disk %q: %s", disk, err)
}
}

Expand Down Expand Up @@ -270,7 +270,7 @@ func resourceVSphereVmfsDatastoreDelete(d *schema.ResourceData, meta interface{}
deleteRetryFunc := func() (interface{}, string, error) {
err := removeDatastore(dss, ds)
if err != nil {
if matched, _ := regexp.MatchString("The resource.*is in use", err.Error()); matched {
if isResourceInUseError(err) {
// Pending
return struct{}{}, retryDeletePending, nil
}
Expand Down
11 changes: 11 additions & 0 deletions vsphere/vim_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func isManagedObjectNotFoundError(err error) bool {
return false
}

// isResourceInUseError checks an error to see if it's of the
// ResourceInUse type.
func isResourceInUseError(err error) bool {
if f, ok := vimSoapFault(err); ok {
if _, ok := f.(types.ResourceInUse); ok {
return true
}
}
return false
}

// renameObject renames a MO and tracks the task to make sure it completes.
func renameObject(client *govmomi.Client, ref types.ManagedObjectReference, new string) error {
req := types.Rename_Task{
Expand Down

0 comments on commit c617982

Please sign in to comment.