From 7843a5c6e656acb4d7e86df1e98f5c89fc45f2af Mon Sep 17 00:00:00 2001 From: Joe Topjian Date: Sun, 18 Dec 2016 15:38:55 -0700 Subject: [PATCH] provider/openstack: Handle Volume Creation Errors (#10821) This commit makes the openstack_blockstorage_volume resources better able to handle volume creation errors upon resource creation. The cause of this change is because there could be some storage backend error that happens during storage provisioning that won't manifest in an "err" but will set the volume's status to "error". We now check for a status of "error" and propagate the error up the stack. --- .../resource_openstack_blockstorage_volume_v1.go | 12 +++++++++--- .../resource_openstack_blockstorage_volume_v2.go | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go index 0479fbf55..b4d6b2031 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v1.go @@ -130,9 +130,6 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{} } log.Printf("[INFO] Volume ID: %s", v.ID) - // Store the ID now - d.SetId(v.ID) - // Wait for the volume to become available. log.Printf( "[DEBUG] Waiting for volume (%s) to become available", @@ -154,6 +151,9 @@ func resourceBlockStorageVolumeV1Create(d *schema.ResourceData, meta interface{} v.ID, err) } + // Store the ID now + d.SetId(v.ID) + return resourceBlockStorageVolumeV1Read(d, meta) } @@ -314,6 +314,12 @@ func VolumeV1StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string return nil, "", err } + if v.Status == "error" { + return v, v.Status, fmt.Errorf("There was an error creating the volume. " + + "Please check with your cloud admin or check the Block Storage " + + "API logs to see why this error occurred.") + } + return v, v.Status, nil } } diff --git a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go index 82f96440e..3a889c301 100644 --- a/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go +++ b/builtin/providers/openstack/resource_openstack_blockstorage_volume_v2.go @@ -142,9 +142,6 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{} } log.Printf("[INFO] Volume ID: %s", v.ID) - // Store the ID now - d.SetId(v.ID) - // Wait for the volume to become available. log.Printf( "[DEBUG] Waiting for volume (%s) to become available", @@ -166,6 +163,9 @@ func resourceBlockStorageVolumeV2Create(d *schema.ResourceData, meta interface{} v.ID, err) } + // Store the ID now + d.SetId(v.ID) + return resourceBlockStorageVolumeV2Read(d, meta) } @@ -325,6 +325,12 @@ func VolumeV2StateRefreshFunc(client *gophercloud.ServiceClient, volumeID string return nil, "", err } + if v.Status == "error" { + return v, v.Status, fmt.Errorf("There was an error creating the volume. " + + "Please check with your cloud admin or check the Block Storage " + + "API logs to see why this error occurred.") + } + return v, v.Status, nil } }