Skip to content

Commit

Permalink
chore(deps): migrate to hcloud-go v2
Browse files Browse the repository at this point in the history
  • Loading branch information
apricote authored and lbajolet-hashicorp committed Aug 28, 2023
1 parent 4d6fdf2 commit e449750
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 358 deletions.
6 changes: 3 additions & 3 deletions builder/hcloud/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
"log"
"strconv"

"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type Artifact struct {
// The name of the snapshot
snapshotName string

// The ID of the image
snapshotId int
snapshotId int64

// The hcloudClient for making API calls
hcloudClient *hcloud.Client
Expand All @@ -36,7 +36,7 @@ func (*Artifact) Files() []string {
}

func (a *Artifact) Id() string {
return strconv.Itoa(a.snapshotId)
return strconv.FormatInt(a.snapshotId, 10)
}

func (a *Artifact) String() string {
Expand Down
4 changes: 2 additions & 2 deletions builder/hcloud/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"

"github.com/hashicorp/packer-plugin-hcloud/version"
)
Expand Down Expand Up @@ -96,7 +96,7 @@ func (b *Builder) Run(ctx context.Context, ui packersdk.Ui, hook packersdk.Hook)

artifact := &Artifact{
snapshotName: state.Get("snapshot_name").(string),
snapshotId: state.Get("snapshot_id").(int),
snapshotId: state.Get("snapshot_id").(int64),
hcloudClient: b.hcloudClient,
StateData: map[string]interface{}{"generated_data": state.Get("generated_data")},
}
Expand Down
2 changes: 1 addition & 1 deletion builder/hcloud/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/hashicorp/packer-plugin-sdk/uuid"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/mitchellh/mapstructure"
)

Expand Down
6 changes: 3 additions & 3 deletions builder/hcloud/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type stepCreateServer struct {
serverId int
serverId int64
}

func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("hcloudClient").(*hcloud.Client)
ui := state.Get("ui").(packersdk.Ui)
c := state.Get("config").(*Config)
sshKeyId := state.Get("ssh_key_id").(int)
sshKeyId := state.Get("ssh_key_id").(int64)

// Create the server based on configuration
ui.Say("Creating server...")
Expand Down
6 changes: 3 additions & 3 deletions builder/hcloud/step_create_snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

const OldSnapshotID = "old_snapshot_id"
Expand All @@ -21,7 +21,7 @@ func (s *stepCreateSnapshot) Run(ctx context.Context, state multistep.StateBag)
client := state.Get("hcloudClient").(*hcloud.Client)
ui := state.Get("ui").(packersdk.Ui)
c := state.Get("config").(*Config)
serverID := state.Get("server_id").(int)
serverID := state.Get("server_id").(int64)

ui.Say("Creating snapshot ...")
ui.Say("This can take some time")
Expand Down Expand Up @@ -52,7 +52,7 @@ func (s *stepCreateSnapshot) Run(ctx context.Context, state multistep.StateBag)
if !found {
return multistep.ActionContinue
}
oldSnapID := oldSnap.(int)
oldSnapID := oldSnap.(int64)

// The pre validate step has been invoked with -force AND found an existing
// snapshot with the same name.
Expand Down
8 changes: 4 additions & 4 deletions builder/hcloud/step_create_snapshot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/hcloud/schema"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

type FailCause int
Expand All @@ -28,12 +28,12 @@ const (
)

func TestStepCreateSnapshot(t *testing.T) {
const serverID = 42
const serverID = int64(42)
const snapName = "dummy-snap"

testCases := []struct {
name string
oldSnapID int // zero value: no old snap will be injected
oldSnapID int64 // zero value: no old snap will be injected
failCause FailCause // zero value: pass
wantAction multistep.StepAction
}{
Expand Down
4 changes: 2 additions & 2 deletions builder/hcloud/step_create_sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import (
"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/uuid"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type stepCreateSSHKey struct {
keyId int
keyId int64
}

func (s *stepCreateSSHKey) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
Expand Down
2 changes: 1 addition & 1 deletion builder/hcloud/step_pre_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

// StepPreValidate provides an opportunity to pre-validate any configuration for
Expand Down
10 changes: 5 additions & 5 deletions builder/hcloud/step_pre_validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/hcloud/schema"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud/schema"
)

func TestStepPreValidate(t *testing.T) {
Expand All @@ -26,7 +26,7 @@ func TestStepPreValidate(t *testing.T) {
name string
// zero value: assert that state OldSnapshotID is NOT present
// non-zero value: assert that state OldSnapshotID is present AND has this value
wantOldSnapID int
wantOldSnapID int64
step stepPreValidate
wantAction multistep.StepAction
}{
Expand Down Expand Up @@ -66,7 +66,7 @@ func TestStepPreValidate(t *testing.T) {

oldSnap, found := state.GetOk(OldSnapshotID)
if found {
oldSnapID := oldSnap.(int)
oldSnapID := oldSnap.(int64)
if tc.wantOldSnapID == 0 {
t.Errorf("OldSnapshotID: got: present with value %d; want: not present", oldSnapID)
} else if oldSnapID != tc.wantOldSnapID {
Expand Down Expand Up @@ -113,7 +113,7 @@ func setupStepPreValidate(errors chan<- error, fakeSnapNames []string) (*multist
images := make([]schema.Image, 0, len(fakeSnapNames))
for i, fakeDesc := range fakeSnapNames {
img := schema.Image{
ID: 1000 + i,
ID: int64(1000 + i),
Type: string(hcloud.ImageTypeSnapshot),
Description: fakeDesc,
}
Expand Down
4 changes: 2 additions & 2 deletions builder/hcloud/step_shutdown_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

"github.com/hashicorp/packer-plugin-sdk/multistep"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hetznercloud/hcloud-go/hcloud"
"github.com/hetznercloud/hcloud-go/v2/hcloud"
)

type stepShutdownServer struct{}
Expand All @@ -18,7 +18,7 @@ type stepShutdownServer struct{}
func (s *stepShutdownServer) Run(ctx context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("hcloudClient").(*hcloud.Client)
ui := state.Get("ui").(packersdk.Ui)
serverID := state.Get("server_id").(int)
serverID := state.Get("server_id").(int64)

ui.Say("Shutting down server...")

Expand Down
33 changes: 17 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ go 1.19
require (
github.com/hashicorp/hcl/v2 v2.16.2
github.com/hashicorp/packer-plugin-sdk v0.5.1
github.com/hetznercloud/hcloud-go v1.42.0
github.com/hetznercloud/hcloud-go/v2 v2.0.0
github.com/mitchellh/mapstructure v1.4.1
github.com/zclconf/go-cty v1.12.1
)

require (
cloud.google.com/go v0.105.0 // indirect
cloud.google.com/go/compute v1.12.1 // indirect
cloud.google.com/go/compute/metadata v0.1.1 // indirect
cloud.google.com/go/compute/metadata v0.2.0 // indirect
cloud.google.com/go/iam v0.6.0 // indirect
cloud.google.com/go/storage v1.27.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
Expand All @@ -25,14 +24,15 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dylanmei/iso8601 v0.1.0 // indirect
github.com/fatih/color v1.12.0 // indirect
github.com/gofrs/flock v0.8.1 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/btree v1.0.0 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
Expand Down Expand Up @@ -65,7 +65,7 @@ require (
github.com/masterzen/winrm v0.0.0-20210623064412-3b76017826b0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mitchellh/go-fs v0.0.0-20180402235330-b7b9ca407fff // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect
Expand All @@ -76,27 +76,28 @@ require (
github.com/packer-community/winrmcp v0.0.0-20180921211025-c76d91c1e7db // indirect
github.com/pierrec/lz4 v2.6.1+incompatible // indirect
github.com/pkg/sftp v1.13.2 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
github.com/prometheus/client_golang v1.16.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/ryanuber/go-glob v1.0.0 // indirect
github.com/stretchr/objx v0.5.0 // indirect
github.com/ugorji/go/codec v1.2.6 // indirect
github.com/ulikunitz/xz v0.5.10 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20220517005047-85d78b3ac167 // indirect
golang.org/x/net v0.9.0 // indirect
golang.org/x/oauth2 v0.1.0 // indirect
golang.org/x/sys v0.7.0 // indirect
golang.org/x/term v0.7.0 // indirect
golang.org/x/text v0.9.0 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
google.golang.org/api v0.101.0 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
google.golang.org/grpc v1.50.1 // indirect
google.golang.org/protobuf v1.28.1 // indirect
google.golang.org/protobuf v1.30.0 // indirect
gopkg.in/square/go-jose.v2 v2.6.0 // indirect
)

Expand Down
Loading

0 comments on commit e449750

Please sign in to comment.