Skip to content

Commit

Permalink
Add image replicate support (#285)
Browse files Browse the repository at this point in the history
* Add image replicate support

* Update test

* Update a test case
  • Loading branch information
zliang-akamai authored Jan 7, 2025
1 parent 007768c commit 4dbe436
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .web-docs/components/builder/linode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ can also be supplied to override the typical auto-generated key:

- `firewall_id` (int) - The ID of the Firewall to attach this Linode to upon creation.

- `image_regions` ([]string) - The regions where the outcome image will be replicated to.

<!-- End of code generated from the comments of the Config struct in builder/linode/config.go; -->


Expand Down
3 changes: 3 additions & 0 deletions builder/linode/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ type Config struct {

// The ID of the Firewall to attach this Linode to upon creation.
FirewallID int `mapstructure:"firewall_id" required:"false"`

// The regions where the outcome image will be replicated to.
ImageRegions []string `mapstructure:"image_regions" required:"false"`
}

func createRandomRootPassword() (string, error) {
Expand Down
2 changes: 2 additions & 0 deletions builder/linode/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion builder/linode/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ func TestPrepare(t *testing.T) {

Region: "us-ord",
InstanceType: "g6-standard-1",
Image: "linode/debian10",
Image: "linode/debian12",
ImageRegions: []string{"us-ord", "us-mia", "us-lax"},
}

warnings, err := config.Prepare()
Expand Down
16 changes: 16 additions & 0 deletions builder/linode/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return handleError("Failed to wait for image creation", err)
}

if len(c.ImageRegions) > 0 {
image, err = s.client.ReplicateImage(ctx, image.ID, linodego.ImageReplicateOptions{
Regions: c.ImageRegions,
})
if err != nil {
return handleError("Failed to replicate the image", err)
}

for _, r := range c.ImageRegions {
_, err = s.client.WaitForImageRegionStatus(ctx, image.ID, r, linodego.ImageRegionStatusAvailable)
if err != nil {
return handleError("Failed to wait for the image replication", err)
}
}
}

image, err = s.client.GetImage(ctx, image.ID)
if err != nil {
return handleError("Failed to get image", err)
Expand Down

0 comments on commit 4dbe436

Please sign in to comment.