Skip to content

Commit 71e21f7

Browse files
committed
fix: add wait to image creation
1 parent 019eba0 commit 71e21f7

4 files changed

Lines changed: 14 additions & 2 deletions

File tree

builder/openstack/builder.hcl2spec.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/openstack/run_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ type RunConfig struct {
177177
OpenstackProvider string `mapstructure:"openstack_provider"`
178178
// *Deprecated* use `floating_ip` or `floating_ip_pool` instead.
179179
UseFloatingIp bool `mapstructure:"use_floating_ip" required:"false"`
180+
// Delay to apply once image has been marked as `active` to ensure Openstack has had time
181+
// to finish creating the image.
182+
ImageCreationWait int `mapstructure:"image_creation_wait" required:"false"`
180183

181184
sourceImageOpts images.ListOpts
182185
}

builder/openstack/step_create_image.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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,10 @@ 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+
time.Sleep(time.Duration(imageCreationWait) * time.Second)
152+
}
149153
return nil
150154
}
151155

docs-partials/builder/openstack/RunConfig-not-required.mdx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,7 @@
9696

9797
- `use_floating_ip` (bool) - *Deprecated* use `floating_ip` or `floating_ip_pool` instead.
9898

99+
- `image_creation_wait` (int) - Delay to apply once image has been marked as `active` to ensure Openstack has had time
100+
to finish creating the image.
101+
99102
<!-- End of code generated from the comments of the RunConfig struct in builder/openstack/run_config.go; -->

0 commit comments

Comments
 (0)