Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

resource/ovirt_disk_attachment: Correct checking if a disk attachment has been destroyed #162

Merged
merged 1 commit into from
Jul 11, 2019
Merged
Show file tree
Hide file tree
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
10 changes: 5 additions & 5 deletions ovirt/resource_ovirt_disk_attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func resourceOvirtDiskAttachmentCreate(d *schema.ResourceData, meta interface{})
func resourceOvirtDiskAttachmentUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*ovirtsdk4.Connection)

vmID, diskID, err := getVMIDAndDiskID(d, meta)
vmID, diskID, err := getVMIDAndDiskID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -173,7 +173,7 @@ func resourceOvirtDiskAttachmentRead(d *schema.ResourceData, meta interface{}) e
conn := meta.(*ovirtsdk4.Connection)
// Disk ID is equals to its relevant Disk Attachment ID
// Sess: https://github.com/oVirt/ovirt-engine/blob/68753f46f09419ddcdbb632453501273697d1a20/backend/manager/modules/restapi/types/src/main/java/org/ovirt/engine/api/restapi/types/DiskAttachmentMapper.java
vmID, diskID, err := getVMIDAndDiskID(d, meta)
vmID, diskID, err := getVMIDAndDiskID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -211,7 +211,7 @@ func resourceOvirtDiskAttachmentRead(d *schema.ResourceData, meta interface{}) e
func resourceOvirtDiskAttachmentDelete(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*ovirtsdk4.Connection)

vmID, diskID, err := getVMIDAndDiskID(d, meta)
vmID, diskID, err := getVMIDAndDiskID(d.Id())
if err != nil {
return err
}
Expand Down Expand Up @@ -267,8 +267,8 @@ func resourceOvirtDiskAttachmentDelete(d *schema.ResourceData, meta interface{})
return nil
}

func getVMIDAndDiskID(d *schema.ResourceData, meta interface{}) (string, string, error) {
parts := strings.Split(d.Id(), ":")
func getVMIDAndDiskID(rsID string) (string, string, error) {
parts := strings.Split(rsID, ":")
if len(parts) != 2 {
return "", "", fmt.Errorf("Invalid resource id")
}
Expand Down
23 changes: 18 additions & 5 deletions ovirt/resource_ovirt_disk_attachment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,16 @@ func testAccCheckDiskAttachmentDestroy(s *terraform.State) error {
if rs.Type != "ovirt_disk_attachment" {
continue
}
getResp, err := conn.SystemService().DisksService().
DiskService(rs.Primary.ID).

vmID, diskID, err := getVMIDAndDiskID(rs.Primary.ID)
if err != nil {
return err
}

getResp, err := conn.SystemService().VmsService().
VmService(vmID).
DiskAttachmentsService().
AttachmentService(diskID).
Get().
Send()
if err != nil {
Expand All @@ -64,7 +72,7 @@ func testAccCheckDiskAttachmentDestroy(s *terraform.State) error {
}
return err
}
if _, ok := getResp.Disk(); ok {
if _, ok := getResp.Attachment(); ok {
return fmt.Errorf("Disk attachment %s still exist", rs.Primary.ID)
}
}
Expand All @@ -81,11 +89,16 @@ func testAccCheckOvirtDiskAttachmentExists(n string, diskAttachment *ovirtsdk4.D
return fmt.Errorf("No Disk attachment ID is set")
}

vmID, diskID, err := getVMIDAndDiskID(rs.Primary.ID)
if err != nil {
return err
}

conn := testAccProvider.Meta().(*ovirtsdk4.Connection)
getResp, err := conn.SystemService().VmsService().
VmService(rs.Primary.Attributes["vm_id"]).
VmService(vmID).
DiskAttachmentsService().
AttachmentService(rs.Primary.Attributes["disk_id"]).
AttachmentService(diskID).
Get().
Send()
if err != nil {
Expand Down