@@ -105,7 +105,7 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
105105
106106 // Wait for the image to become ready
107107 ui .Say (fmt .Sprintf ("Waiting for image %s (image id: %s) to become ready..." , config .ImageName , imageId ))
108- if err := WaitForImage (ctx , imageClient , imageId ); err != nil {
108+ if err := WaitForImage (ctx , imageClient , imageId , config . ImageCreationWait ); err != nil {
109109 err := fmt .Errorf ("Error waiting for image: %s" , err )
110110 state .Put ("error" , err )
111111 ui .Error (err .Error ())
@@ -120,7 +120,7 @@ func (s *stepCreateImage) Cleanup(multistep.StateBag) {
120120}
121121
122122// WaitForImage waits for the given Image ID to become ready.
123- func WaitForImage (ctx context.Context , client * gophercloud.ServiceClient , imageId string ) error {
123+ func WaitForImage (ctx context.Context , client * gophercloud.ServiceClient , imageId string , imageCreationWait int ) error {
124124 maxNumErrors := 10
125125 numErrors := 0
126126
@@ -146,6 +146,16 @@ func WaitForImage(ctx context.Context, client *gophercloud.ServiceClient, imageI
146146 }
147147
148148 if image .Status == "active" {
149+ if imageCreationWait > 0 {
150+ log .Printf ("Additional wait (%d seconds) after image status has changed to active..." , imageCreationWait )
151+ select {
152+ case <- time .After (time .Duration (imageCreationWait ) * time .Second ):
153+ // Timer finished, safe to continue
154+ case <- ctx .Done ():
155+ // User cancelled during the wait, abort immediately
156+ return ctx .Err ()
157+ }
158+ }
149159 return nil
150160 }
151161
0 commit comments