github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/openstack/util.go (about)

     1  package openstack
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/rackspace/gophercloud"
     8  )
     9  
    10  // CheckDeleted checks the error to see if it's a 404 (Not Found) and, if so,
    11  // sets the resource ID to the empty string instead of throwing an error.
    12  func CheckDeleted(d *schema.ResourceData, err error, msg string) error {
    13  	errCode, ok := err.(*gophercloud.UnexpectedResponseCodeError)
    14  	if !ok {
    15  		return fmt.Errorf("%s: %s", msg, err)
    16  	}
    17  	if errCode.Actual == 404 {
    18  		d.SetId("")
    19  		return nil
    20  	}
    21  	return fmt.Errorf("%s: %s", msg, err)
    22  }