2015-02-10 04:27:39 +01:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2015-02-17 18:48:23 +01:00
|
|
|
"github.com/rackspace/gophercloud"
|
2015-02-10 04:27:39 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so,
|
|
|
|
// sets the resource ID to the empty string instead of throwing an error.
|
2015-02-13 01:25:45 +01:00
|
|
|
func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
|
2015-02-17 18:48:23 +01:00
|
|
|
errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
|
2015-02-10 04:27:39 +01:00
|
|
|
if !ok {
|
2015-02-13 01:25:45 +01:00
|
|
|
return fmt.Errorf("%s: %s", msg, err)
|
2015-02-10 04:27:39 +01:00
|
|
|
}
|
|
|
|
if errCode.Actual == 404 {
|
|
|
|
d.SetId("")
|
|
|
|
return nil
|
|
|
|
}
|
2015-02-13 01:25:45 +01:00
|
|
|
return fmt.Errorf("%s: %s", msg, err)
|
2015-02-10 04:27:39 +01:00
|
|
|
}
|