@@ -299,6 +299,10 @@ func resourceComputeInstanceGroupManager() *schema.Resource {
299299 },
300300 },
301301 },
302+ "operation" : {
303+ Type : schema .TypeString ,
304+ Computed : true ,
305+ },
302306 },
303307 }
304308}
@@ -376,6 +380,18 @@ func resourceComputeInstanceGroupManagerCreate(d *schema.ResourceData, meta inte
376380 // Wait for the operation to complete
377381 err = computeOperationWaitTime (config , op , project , "Creating InstanceGroupManager" , d .Timeout (schema .TimeoutCreate ))
378382 if err != nil {
383+ // Check if the create operation failed because Terraform was prematurely terminated. If it was we can persist the
384+ // operation id to state so that a subsequent refresh of this resource will wait until the operation has terminated
385+ // before attempting to Read the state of the manager. This allows a graceful resumption of a Create that was killed
386+ // by the upstream Terraform process exiting early such as a sigterm.
387+ select {
388+ case <- config .context .Done ():
389+ log .Printf ("[DEBUG] Persisting %s so this operation can be resumed \n " , op .Name )
390+ d .Set ("operation" , op .Name )
391+ return nil
392+ default :
393+ // leaving default case to ensure this is non blocking
394+ }
379395 return err
380396 }
381397
@@ -453,6 +469,24 @@ func resourceComputeInstanceGroupManagerRead(d *schema.ResourceData, meta interf
453469 return err
454470 }
455471
472+ operation := d .Get ("operation" ).(string )
473+ if operation != "" {
474+ log .Printf ("[DEBUG] in progress operation detected at %v, attempting to resume" , operation )
475+ zone , _ := getZone (d , config )
476+ op := & computeBeta.Operation {
477+ Name : operation ,
478+ Zone : zone ,
479+ }
480+ d .Set ("operation" , "" )
481+ err = computeOperationWaitTime (config , op , project , "Creating InstanceGroupManager" , d .Timeout (schema .TimeoutCreate ))
482+ if err != nil {
483+ // remove from state to allow refresh to finish
484+ log .Printf ("[DEBUG] Resumed operation returned an error, removing from state: %s" , err )
485+ d .SetId ("" )
486+ return nil
487+ }
488+ }
489+
456490 manager , err := getManager (d , meta )
457491 if err != nil {
458492 return err
0 commit comments