providers/google: check operations for errors
This commit is contained in:
parent
bf6df9420f
commit
673b62db96
|
@ -56,9 +56,18 @@ func resourceComputeAddressCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for address to create: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
return resourceComputeAddressRead(d, meta)
|
||||
}
|
||||
|
@ -98,9 +107,15 @@ func resourceComputeAddressDelete(d *schema.ResourceData, meta interface{}) erro
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for address to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
|
|
|
@ -85,8 +85,17 @@ func resourceComputeDiskCreate(d *schema.ResourceData, meta interface{}) error {
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
return fmt.Errorf("Error waiting for address to create: %s", err)
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for disk to create: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
return resourceComputeDiskRead(d, meta)
|
||||
|
@ -107,7 +116,7 @@ func resourceComputeDiskRead(d *schema.ResourceData, meta interface{}) error {
|
|||
func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
config := meta.(*Config)
|
||||
|
||||
// Delete the address
|
||||
// Delete the disk
|
||||
op, err := config.clientCompute.Disks.Delete(
|
||||
config.Project, d.Get("zone").(string), d.Id()).Do()
|
||||
if err != nil {
|
||||
|
@ -125,8 +134,14 @@ func resourceComputeDiskDelete(d *schema.ResourceData, meta interface{}) error {
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
return fmt.Errorf("Error waiting for address to delete: %s", err)
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for disk to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
|
|
@ -171,9 +171,18 @@ func resourceComputeFirewallCreate(d *schema.ResourceData, meta interface{}) err
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for firewall to create: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
return resourceComputeFirewallRead(d, meta)
|
||||
}
|
||||
|
@ -210,9 +219,15 @@ func resourceComputeFirewallDelete(d *schema.ResourceData, meta interface{}) err
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for firewall to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
|
|
|
@ -282,9 +282,18 @@ func resourceComputeInstanceCreate(d *schema.ResourceData, meta interface{}) err
|
|||
state.Delay = 10 * time.Second
|
||||
state.Timeout = 10 * time.Minute
|
||||
state.MinTimeout = 2 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for instance to create: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
return resourceComputeInstanceRead(d, meta)
|
||||
}
|
||||
|
@ -329,8 +338,14 @@ func resourceComputeInstanceDelete(d *schema.ResourceData, meta interface{}) err
|
|||
state.Delay = 5 * time.Second
|
||||
state.Timeout = 5 * time.Minute
|
||||
state.MinTimeout = 2 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
return fmt.Errorf("Error waiting for instance to create: %s", err)
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for instance to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
|
|
|
@ -64,9 +64,18 @@ func resourceComputeNetworkCreate(d *schema.ResourceData, meta interface{}) erro
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for network to create: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// The resource didn't actually create
|
||||
d.SetId("")
|
||||
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
return resourceComputeNetworkRead(d, meta)
|
||||
}
|
||||
|
@ -105,9 +114,15 @@ func resourceComputeNetworkDelete(d *schema.ResourceData, meta interface{}) erro
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for network to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
|
|
|
@ -211,9 +211,15 @@ func resourceComputeRouteDelete(d *schema.ResourceData, meta interface{}) error
|
|||
state := w.Conf()
|
||||
state.Timeout = 2 * time.Minute
|
||||
state.MinTimeout = 1 * time.Second
|
||||
if _, err := state.WaitForState(); err != nil {
|
||||
opRaw, err := state.WaitForState()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for route to delete: %s", err)
|
||||
}
|
||||
op = opRaw.(*compute.Operation)
|
||||
if op.Error != nil {
|
||||
// Return the error
|
||||
return OperationError(*op.Error)
|
||||
}
|
||||
|
||||
d.SetId("")
|
||||
return nil
|
||||
|
|
Loading…
Reference in New Issue