Review by @paddyforan: Add a resourceComputeSnapshotExists function

This commit is contained in:
Thomas Poindessous 2017-03-22 15:01:45 +01:00
parent af5c00a612
commit 300d0b7432

View File

@ -14,6 +14,7 @@ func resourceComputeSnapshot() *schema.Resource {
Create: resourceComputeSnapshotCreate,
Read: resourceComputeSnapshotRead,
Delete: resourceComputeSnapshotDelete,
Exists: resourceComputeSnapshotExists,
Schema: map[string]*schema.Schema{
"name": &schema.Schema{
@ -182,3 +183,26 @@ func resourceComputeSnapshotDelete(d *schema.ResourceData, meta interface{}) err
d.SetId("")
return nil
}
func resourceComputeSnapshotExists(d *schema.ResourceData, meta interface{}) (bool, error) {
config := meta.(*Config)
project, err := getProject(d, config)
if err != nil {
return false, err
}
_, err = config.clientCompute.Snapshots.Get(
project, d.Id()).Do()
if err != nil {
if gerr, ok := err.(*googleapi.Error); ok && gerr.Code == 404 {
log.Printf("[WARN] Removing Snapshot %q because it's gone", d.Get("name").(string))
// The resource doesn't exist anymore
d.SetId("")
return false, err
}
return true, err
}
return true, nil
}