Skip to content

Commit 81673a2

Browse files
dkallegstack72
authored andcommitted
Graceful read miss (hashicorp#7220)
For both the file and virtual_disk resource, Stat is used during read, but if Stat returns an error, read() will return that error. In doing so, if a resource is deleted manually, the TF user would then not be able to destroy the resource because the read would block the Delete() call. With this patch, read() will only return an error if that error is NOT a DatastoreNoSuchFileError.
1 parent 004cec6 commit 81673a2

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

builtin/providers/vsphere/resource_vsphere_file.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,13 @@ func resourceVSphereFileRead(d *schema.ResourceData, meta interface{}) error {
164164

165165
_, err = ds.Stat(context.TODO(), f.destinationFile)
166166
if err != nil {
167+
log.Printf("[DEBUG] resourceVSphereFileRead - stat failed on: %v", f.destinationFile)
167168
d.SetId("")
168-
return err
169+
170+
_, ok := err.(object.DatastoreNoSuchFileError)
171+
if !ok {
172+
return err
173+
}
169174
}
170175

171176
return nil

builtin/providers/vsphere/resource_vsphere_virtual_disk.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,12 @@ func resourceVSphereVirtualDiskRead(d *schema.ResourceData, meta interface{}) er
173173
if err != nil {
174174
log.Printf("[DEBUG] resourceVSphereVirtualDiskRead - stat failed on: %v", vDisk.vmdkPath)
175175
d.SetId("")
176-
return err
176+
177+
_, ok := err.(object.DatastoreNoSuchFileError)
178+
if !ok {
179+
return err
180+
}
181+
return nil
177182
}
178183
fileInfo = fileInfo.GetFileInfo()
179184
log.Printf("[DEBUG] resourceVSphereVirtualDiskRead - fileinfo: %#v", fileInfo)

0 commit comments

Comments
 (0)