Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion builder/linode/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"

registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
)

type Artifact struct {
Expand Down
7 changes: 5 additions & 2 deletions builder/linode/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"log"

"github.com/hashicorp/hcl/v2/hcldec"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"

"github.com/hashicorp/packer-plugin-sdk/communicator"
"github.com/hashicorp/packer-plugin-sdk/multistep"
Expand Down Expand Up @@ -47,7 +47,10 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)
return nil, err
}
} else {
client = helper.NewLinodeClient(b.config.PersonalAccessToken)
client, err = helper.NewLinodeClient(b.config.PersonalAccessToken)
if err != nil {
return nil, err
}
}

state := new(multistep.BasicStateBag)
Expand Down
2 changes: 1 addition & 1 deletion builder/linode/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"time"

packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
)

func testConfig() map[string]any {
Expand Down
16 changes: 10 additions & 6 deletions builder/linode/step_create_disk_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
"github.com/linode/packer-plugin-linode/helper"
)

Expand Down Expand Up @@ -297,8 +297,10 @@ func (s *stepCreateDiskConfig) Run(ctx context.Context, state multistep.StateBag
return handleError(fmt.Sprintf("Failed to create disk %q", diskCfg.Label), err)
}

// Wait for disk to be ready
disk, err = s.client.WaitForInstanceDiskStatus(ctx, instance.ID, disk.ID, linodego.DiskReady, int(c.StateTimeout.Seconds()))
// Wait for disk to be ready.
waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout)
disk, err = s.client.WaitForInstanceDiskStatus(waitCtx, instance.ID, disk.ID, linodego.DiskReady)
cancel()
if err != nil {
return handleError(fmt.Sprintf("Failed to wait for disk %q", diskCfg.Label), err)
}
Expand Down Expand Up @@ -373,13 +375,15 @@ func (s *stepCreateDiskConfig) Run(ctx context.Context, state multistep.StateBag
// Boot the instance with the selected configuration profile
if bootConfigID != 0 {
ui.Say(fmt.Sprintf("Booting Linode with config ID %d...", bootConfigID))
err = s.client.BootInstance(ctx, instance.ID, bootConfigID)
err = s.client.BootInstance(ctx, instance.ID, linodego.InstanceBootOptions{ConfigID: &bootConfigID})
if err != nil {
return handleError("Failed to boot Linode", err)
}

// Wait for instance to be running
instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceRunning, int(c.StateTimeout.Seconds()))
// Wait for instance to be running.
waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout)
instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceRunning)
cancel()
if err != nil {
return handleError("Failed to wait for Linode to be running", err)
}
Expand Down
2 changes: 1 addition & 1 deletion builder/linode/step_create_disk_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"strings"
"testing"

"github.com/linode/linodego"
"github.com/linode/linodego/v2"
)

func TestResolveDiskLabel(t *testing.T) {
Expand Down
7 changes: 5 additions & 2 deletions builder/linode/step_create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
"github.com/linode/packer-plugin-linode/helper"
)

Expand Down Expand Up @@ -41,7 +41,10 @@ func (s *stepCreateImage) Run(ctx context.Context, state multistep.StateBag) mul
return handleError("Failed to create image", err)
}

_, err = creationPoller.WaitForFinished(ctx, int(c.ImageCreateTimeout.Seconds()))
waitCtx, cancel := context.WithTimeout(ctx, c.ImageCreateTimeout)
defer cancel()

_, err = creationPoller.WaitForFinished(waitCtx)
if err != nil {
return handleError("Failed to wait for image creation", err)
}
Expand Down
60 changes: 30 additions & 30 deletions builder/linode/step_create_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
"github.com/linode/packer-plugin-linode/helper"
)

type stepCreateLinode struct {
client *linodego.Client
}

func flattenConfigInterfaceIPv4(i *InterfaceIPv4) *linodego.VPCIPv4 {
func flattenConfigInterfaceIPv4(i *InterfaceIPv4) *linodego.VPCIPv4CreateOptions {
if i == nil {
return nil
}

return &linodego.VPCIPv4{
return &linodego.VPCIPv4CreateOptions{
VPC: i.VPC,
NAT1To1: i.NAT1To1,
}
Expand Down Expand Up @@ -51,7 +51,7 @@ func flattenPublicInterface(public *PublicInterface) *linodego.PublicInterfaceCr
}
}
result.IPv4 = &linodego.PublicInterfaceIPv4CreateOptions{
Addresses: linodego.Pointer(addresses),
Addresses: addresses,
}
}
if public.IPv6 != nil {
Expand All @@ -62,7 +62,7 @@ func flattenPublicInterface(public *PublicInterface) *linodego.PublicInterfaceCr
}
}
result.IPv6 = &linodego.PublicInterfaceIPv6CreateOptions{
Ranges: linodego.Pointer(ranges),
Ranges: ranges,
}
}
return result
Expand Down Expand Up @@ -91,8 +91,8 @@ func flattenVPCInterface(vpc *VPCInterface) *linodego.VPCInterfaceCreateOptions
}
}
result.IPv4 = &linodego.VPCInterfaceIPv4CreateOptions{
Addresses: linodego.Pointer(addresses),
Ranges: linodego.Pointer(ranges),
Addresses: addresses,
Ranges: ranges,
}
}
if vpc.IPv6 != nil {
Expand All @@ -109,44 +109,38 @@ func flattenVPCInterface(vpc *VPCInterface) *linodego.VPCInterfaceCreateOptions
}
}
result.IPv6 = &linodego.VPCInterfaceIPv6CreateOptions{
SLAAC: linodego.Pointer(slaac),
Ranges: linodego.Pointer(ranges),
SLAAC: slaac,
Ranges: ranges,
IsPublic: vpc.IPv6.IsPublic,
}
}
return result
}

func flattenVLANInterface(vlan *VLANInterface) *linodego.VLANInterface {
func flattenVLANInterface(vlan *VLANInterface) *linodego.VLANInterfaceCreateOptions {
if vlan == nil {
return nil
}
result := &linodego.VLANInterface{
VLANLabel: vlan.VLANLabel,
return &linodego.VLANInterfaceCreateOptions{
VLANLabel: vlan.VLANLabel,
IPAMAddress: vlan.IPAMAddress,
}
if vlan.IPAMAddress != nil {
result.IPAMAddress = vlan.IPAMAddress
}
return result
}

func flattenLinodeInterface(li LinodeInterface) (opts linodego.LinodeInterfaceCreateOptions) {
if li.FirewallID != nil {
opts.FirewallID = li.FirewallID
func flattenLinodeInterface(li LinodeInterface) linodego.LinodeInterfaceCreateOptions {
opts := linodego.LinodeInterfaceCreateOptions{
FirewallID: li.FirewallID,
Public: flattenPublicInterface(li.Public),
VPC: flattenVPCInterface(li.VPC),
VLAN: flattenVLANInterface(li.VLAN),
}

if li.DefaultRoute != nil {
opts.DefaultRoute = &linodego.InterfaceDefaultRoute{
opts.DefaultRoute = &linodego.InterfaceDefaultRouteCreateOptions{
IPv4: li.DefaultRoute.IPv4,
IPv6: li.DefaultRoute.IPv6,
}
}

opts.Public = flattenPublicInterface(li.Public)
opts.VPC = flattenVPCInterface(li.VPC)
opts.VLAN = flattenVLANInterface(li.VLAN)

return
return opts
}

func flattenMetadata(m Metadata) *linodego.InstanceMetadataOptions {
Expand Down Expand Up @@ -245,8 +239,11 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu
// When using custom disks, we skip waiting for running state here
// because the instance won't boot until we create disks and configs
if useCustomDisks {
// Wait for instance to be in offline state (resources allocated)
instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceOffline, int(c.StateTimeout.Seconds()))
// Wait for instance resources to be allocated before creating disks/configs.
waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout)
defer cancel()

instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceOffline)
if err != nil {
return handleError("Failed to wait for Linode to be offline", err)
}
Expand All @@ -256,7 +253,10 @@ func (s *stepCreateLinode) Run(ctx context.Context, state multistep.StateBag) mu
}

// wait until instance is running
instance, err = s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceRunning, int(c.StateTimeout.Seconds()))
waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout)
defer cancel()

instance, err = s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceRunning)
if err != nil {
return handleError("Failed to wait for Linode ready", err)
}
Expand Down
34 changes: 17 additions & 17 deletions builder/linode/step_create_linode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package linode
import (
"testing"

"github.com/linode/linodego"
"github.com/linode/linodego/v2"
)

func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) {
Expand Down Expand Up @@ -33,11 +33,11 @@ func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) {
if got.IPv4 == nil {
t.Fatal("flattenVPCInterface().IPv4 returned nil")
}
if got.IPv4.Addresses == nil || len(*got.IPv4.Addresses) != 1 {
if len(got.IPv4.Addresses) != 1 {
t.Fatalf("flattenVPCInterface().IPv4.Addresses = %v, want one address", got.IPv4.Addresses)
}

addr := (*got.IPv4.Addresses)[0]
addr := got.IPv4.Addresses[0]
if addr.Address == nil || *addr.Address != "auto" {
t.Fatalf("address = %v, want auto", addr.Address)
}
Expand All @@ -47,11 +47,11 @@ func TestFlattenVPCInterface_IPv4AddressFields(t *testing.T) {
if addr.NAT1To1Address == nil || *addr.NAT1To1Address != "192.0.2.10" {
t.Fatalf("nat_1_1_address = %v, want 192.0.2.10", addr.NAT1To1Address)
}
if got.IPv4.Ranges == nil || len(*got.IPv4.Ranges) != 1 {
if len(got.IPv4.Ranges) != 1 {
t.Fatalf("ranges = %v, want one range", got.IPv4.Ranges)
}
if (*got.IPv4.Ranges)[0].Range != "10.0.0.0/28" {
t.Fatalf("range = %q, want 10.0.0.0/28", (*got.IPv4.Ranges)[0].Range)
if got.IPv4.Ranges[0].Range != "10.0.0.0/28" {
t.Fatalf("range = %q, want 10.0.0.0/28", got.IPv4.Ranges[0].Range)
}
}

Expand All @@ -76,17 +76,17 @@ func TestFlattenVPCInterface_IPv6Fields(t *testing.T) {
if got.IPv6 == nil {
t.Fatal("flattenVPCInterface().IPv6 returned nil")
}
if got.IPv6.SLAAC == nil || len(*got.IPv6.SLAAC) != 1 {
if len(got.IPv6.SLAAC) != 1 {
t.Fatalf("slaac = %v, want one slaac range", got.IPv6.SLAAC)
}
if (*got.IPv6.SLAAC)[0].Range != "2600:3c03:e000:123::/64" {
t.Fatalf("slaac range = %q, want 2600:3c03:e000:123::/64", (*got.IPv6.SLAAC)[0].Range)
if got.IPv6.SLAAC[0].Range != "2600:3c03:e000:123::/64" {
t.Fatalf("slaac range = %q, want 2600:3c03:e000:123::/64", got.IPv6.SLAAC[0].Range)
}
if got.IPv6.Ranges == nil || len(*got.IPv6.Ranges) != 1 {
if len(got.IPv6.Ranges) != 1 {
t.Fatalf("ranges = %v, want one ipv6 range", got.IPv6.Ranges)
}
if (*got.IPv6.Ranges)[0].Range != "2600:3c03:e000:123:1::/64" {
t.Fatalf("range = %q, want 2600:3c03:e000:123:1::/64", (*got.IPv6.Ranges)[0].Range)
if got.IPv6.Ranges[0].Range != "2600:3c03:e000:123:1::/64" {
t.Fatalf("range = %q, want 2600:3c03:e000:123:1::/64", got.IPv6.Ranges[0].Range)
}
if got.IPv6.IsPublic == nil || !*got.IPv6.IsPublic {
t.Fatalf("is_public = %v, want true", got.IPv6.IsPublic)
Expand Down Expand Up @@ -153,17 +153,17 @@ func TestFlattenPublicInterface_AllFields(t *testing.T) {
if got == nil || got.IPv4 == nil || got.IPv6 == nil {
t.Fatalf("flattenPublicInterface() = %v, want non-nil ipv4 and ipv6", got)
}
if got.IPv4.Addresses == nil || len(*got.IPv4.Addresses) != 1 {
if len(got.IPv4.Addresses) != 1 {
t.Fatalf("ipv4 addresses = %v, want one address", got.IPv4.Addresses)
}
addr := (*got.IPv4.Addresses)[0]
addr := got.IPv4.Addresses[0]
if addr.Address == nil || *addr.Address != "auto" {
t.Fatalf("ipv4 address = %v, want auto", addr.Address)
}
if addr.Primary == nil || !*addr.Primary {
t.Fatalf("ipv4 primary = %v, want true", addr.Primary)
}
if got.IPv6.Ranges == nil || len(*got.IPv6.Ranges) != 1 || (*got.IPv6.Ranges)[0].Range != "/64" {
if len(got.IPv6.Ranges) != 1 || got.IPv6.Ranges[0].Range != "/64" {
t.Fatalf("ipv6 ranges = %v, want [/64]", got.IPv6.Ranges)
}
}
Expand Down Expand Up @@ -201,10 +201,10 @@ func TestFlattenLinodeInterface_AllFields(t *testing.T) {
if got.Public == nil {
t.Fatalf("public = nil, want non-nil")
}
if got.Public.IPv4 == nil || got.Public.IPv4.Addresses == nil || len(*got.Public.IPv4.Addresses) != 1 {
if got.Public.IPv4 == nil || len(got.Public.IPv4.Addresses) != 1 {
t.Fatalf("public ipv4 addresses = %v, want one address", got.Public)
}
if addr := (*got.Public.IPv4.Addresses)[0]; addr.Address == nil || *addr.Address != "auto" {
if addr := got.Public.IPv4.Addresses[0]; addr.Address == nil || *addr.Address != "auto" {
t.Fatalf("public ipv4 address = %v, want auto", addr.Address)
}
if got.Public.IPv6 != nil {
Expand Down
7 changes: 5 additions & 2 deletions builder/linode/step_shutdown_linode.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
"github.com/linode/packer-plugin-linode/helper"
)

Expand All @@ -27,7 +27,10 @@ func (s *stepShutdownLinode) Run(ctx context.Context, state multistep.StateBag)
return handleError("Error shutting down Linode", err)
}

_, err := s.client.WaitForInstanceStatus(ctx, instance.ID, linodego.InstanceOffline, int(c.StateTimeout.Seconds()))
waitCtx, cancel := context.WithTimeout(ctx, c.StateTimeout)
defer cancel()

_, err := s.client.WaitForInstanceStatus(waitCtx, instance.ID, linodego.InstanceOffline)
if err != nil {
return handleError("Error waiting for Linode offline", err)
}
Expand Down
7 changes: 5 additions & 2 deletions datasource/image/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/hcl2helper"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/linode/linodego"
"github.com/linode/linodego/v2"
"github.com/linode/packer-plugin-linode/helper"
"github.com/zclconf/go-cty/cty"
)
Expand Down Expand Up @@ -138,7 +138,10 @@ func (d *Datasource) Execute() (cty.Value, error) {
return cty.NullVal(cty.EmptyObject), err
}
} else {
client = helper.NewLinodeClient(d.config.PersonalAccessToken)
client, err = helper.NewLinodeClient(d.config.PersonalAccessToken)
if err != nil {
return cty.NullVal(cty.EmptyObject), err
}
}

filters := linodego.Filter{}
Expand Down
2 changes: 1 addition & 1 deletion datasource/image/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"regexp"
"sort"

"github.com/linode/linodego"
"github.com/linode/linodego/v2"
)

type ImageFilter func(linodego.Image) bool
Expand Down
Loading