Skip to content

Commit

Permalink
Update govultr from 3.9.1 to 3.11.2 (#324)
Browse files Browse the repository at this point in the history
* Update govultr from v3.9.1 to 3.11.2

* Replace/remove deprecated server options

* Update hcl2 config spec
  • Loading branch information
optik-aper authored Oct 31, 2024
1 parent 78beabe commit 2e4cdb9
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 37 deletions.
45 changes: 39 additions & 6 deletions builder/vultr/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
}
}

func TestBuilderPrepare_EnablePrivateNetwork(t *testing.T) {
func TestBuilderPrepare_EnableVPC(t *testing.T) {
var b Builder
config := testConfig()

Expand All @@ -245,12 +245,12 @@ func TestBuilderPrepare_EnablePrivateNetwork(t *testing.T) {
t.Fatalf("should not have error: %s", err)
}

if b.config.EnablePrivateNetwork != false {
t.Errorf("invalid: %t", b.config.EnablePrivateNetwork)
if b.config.EnableVPC != false {
t.Errorf("invalid: %t", b.config.EnableVPC)
}

// Test set
config["enable_private_network"] = true
config["enable_vpc"] = true
b = Builder{}
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
Expand All @@ -260,8 +260,41 @@ func TestBuilderPrepare_EnablePrivateNetwork(t *testing.T) {
t.Fatalf("should not have error: %s", err)
}

if b.config.EnablePrivateNetwork != true {
t.Errorf("invalid: %t", b.config.EnablePrivateNetwork)
if b.config.EnableVPC != true {
t.Errorf("invalid: %t", b.config.EnableVPC)
}
}

func TestBuilderPrepare_EnableVPC2(t *testing.T) {
var b Builder
config := testConfig()

// Test default
_, warnings, err := b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}

if b.config.EnableVPC2 != false {
t.Errorf("invalid: %t", b.config.EnableVPC2)
}

// Test set
config["enable_vpc2"] = true
b = Builder{}
_, warnings, err = b.Prepare(config)
if len(warnings) > 0 {
t.Fatalf("bad: %#v", warnings)
}
if err != nil {
t.Fatalf("should not have error: %s", err)
}

if b.config.EnableVPC2 != true {
t.Errorf("invalid: %t", b.config.EnableVPC2)
}
}

Expand Down
17 changes: 9 additions & 8 deletions builder/vultr/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,15 @@ type Config struct {
AppID int `mapstructure:"app_id"`
ImageID string `mapstructure:"image_id"`

EnableIPV6 bool `mapstructure:"enable_ipv6"`
EnablePrivateNetwork bool `mapstructure:"enable_private_network"`
ScriptID string `mapstructure:"script_id"`
SSHKeyIDs []string `mapstructure:"ssh_key_ids"`
Label string `mapstructure:"instance_label"`
UserData string `mapstructure:"userdata"`
Hostname string `mapstructure:"hostname"`
Tag string `mapstructure:"tag"`
EnableIPV6 bool `mapstructure:"enable_ipv6"`
EnableVPC bool `mapstructure:"enable_vpc"`
EnableVPC2 bool `mapstructure:"enable_vpc2"`
ScriptID string `mapstructure:"script_id"`
SSHKeyIDs []string `mapstructure:"ssh_key_ids"`
Label string `mapstructure:"instance_label"`
UserData string `mapstructure:"userdata"`
Hostname string `mapstructure:"hostname"`
Tags []string `mapstructure:"tags"`

RawStateTimeout string `mapstructure:"state_timeout"`

Expand Down
10 changes: 6 additions & 4 deletions builder/vultr/config.hcl2spec.go

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

33 changes: 17 additions & 16 deletions builder/vultr/step_create_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,23 @@ func (s *stepCreateServer) Run(ctx context.Context, state multistep.StateBag) mu
}

instanceReq := &govultr.InstanceCreateReq{
ISOID: isoID,
SnapshotID: c.SnapshotID,
OsID: c.OSID,
Region: c.RegionID,
Plan: c.PlanID,
AppID: c.AppID,
ScriptID: c.ScriptID,
ImageID: c.ImageID,
EnableIPv6: govultr.BoolToBoolPtr(c.EnableIPV6),
EnablePrivateNetwork: govultr.BoolToBoolPtr(c.EnablePrivateNetwork),
Label: c.Label,
SSHKeys: sshKeys,
UserData: c.UserData,
ActivationEmail: govultr.BoolToBoolPtr(false),
Hostname: c.Hostname,
Tag: c.Tag,
ISOID: isoID,
SnapshotID: c.SnapshotID,
OsID: c.OSID,
Region: c.RegionID,
Plan: c.PlanID,
AppID: c.AppID,
ScriptID: c.ScriptID,
ImageID: c.ImageID,
EnableIPv6: govultr.BoolToBoolPtr(c.EnableIPV6),
EnableVPC: govultr.BoolToBoolPtr(c.EnableVPC),
EnableVPC2: govultr.BoolToBoolPtr(c.EnableVPC2),
Label: c.Label,
SSHKeys: sshKeys,
UserData: c.UserData,
ActivationEmail: govultr.BoolToBoolPtr(false),
Hostname: c.Hostname,
Tags: c.Tags,
}

instance, _, err := s.client.Instance.Create(ctx, instanceReq)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.23
require (
github.com/hashicorp/hcl/v2 v2.16.2
github.com/hashicorp/packer-plugin-sdk v0.5.1
github.com/vultr/govultr/v3 v3.9.1
github.com/vultr/govultr/v3 v3.11.2
github.com/zclconf/go-cty v1.13.3
golang.org/x/crypto v0.27.0
golang.org/x/oauth2 v0.23.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/vmihailenco/msgpack/v4 v4.3.12/go.mod h1:gborTTJjAo/GWTqqRjrLCn9pgNN+NXzzngzBKDPIqw4=
github.com/vmihailenco/tagparser v0.1.1/go.mod h1:OeAg3pn3UbLjkWt+rN9oFYB6u/cQgqMEUPoW2WPyhdI=
github.com/vultr/govultr/v3 v3.9.1 h1:uxSIb8Miel7tqTs3ee+z3t+JelZikwqBBsZzCOPBy/8=
github.com/vultr/govultr/v3 v3.9.1/go.mod h1:Rd8ebpXm7jxH3MDmhnEs+zrlYW212ouhx+HeUMfHm2o=
github.com/vultr/govultr/v3 v3.11.2 h1:F3QBuWb9mz3ZOecmVKm31dRAJ5f8fe279+dxZDpS64c=
github.com/vultr/govultr/v3 v3.11.2/go.mod h1:q34Wd76upKmf+vxFMgaNMH3A8BbsPBmSYZUGC8oZa5w=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
Expand Down

0 comments on commit 2e4cdb9

Please sign in to comment.