Review by @paddyforan: Add a resourceComputeSnapshotExists function
This commit is contained in:
parent
84dc163089
commit
00c3553f11
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue