Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

r/virtual_disk: Ignore error when creating dir #639

Merged
merged 1 commit into from
Oct 11, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion vsphere/resource_vsphere_virtual_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ func resourceVSphereVirtualDiskCreate(d *schema.ResourceData, meta interface{})
path := vDisk.vmdkPath[0:directoryPathIndex]
log.Printf("[DEBUG] Creating parent directories: %v", ds.Path(path))
err = fm.MakeDirectory(context.TODO(), ds.Path(path), dc, true)
if err != nil {
if err != nil && !isAlreadyExists(err) {
log.Printf("[DEBUG] Failed to create parent directories: %v", err)
return err
}
Expand Down Expand Up @@ -341,6 +341,11 @@ func resourceVSphereVirtualDiskDelete(d *schema.ResourceData, meta interface{})
return nil
}

func isAlreadyExists(err error) bool {
return strings.HasPrefix(err.Error(), "Cannot complete the operation because the file or folder") &&
strings.HasSuffix(err.Error(), "already exists")
}

// createHardDisk creates a new Hard Disk.
func createHardDisk(client *govmomi.Client, size int, diskPath string, diskType string, adapterType string, dc string) error {
var vDiskType string
Expand Down