From 2e4cdb945098b0a1b24ba588e0d7b74d9707e6fd Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Thu, 31 Oct 2024 12:32:05 -0400 Subject: [PATCH] Update govultr from 3.9.1 to 3.11.2 (#324) * Update govultr from v3.9.1 to 3.11.2 * Replace/remove deprecated server options * Update hcl2 config spec --- builder/vultr/builder_test.go | 45 +++++++++++++++++++++++++---- builder/vultr/config.go | 17 ++++++----- builder/vultr/config.hcl2spec.go | 10 ++++--- builder/vultr/step_create_server.go | 33 +++++++++++---------- go.mod | 2 +- go.sum | 4 +-- 6 files changed, 74 insertions(+), 37 deletions(-) diff --git a/builder/vultr/builder_test.go b/builder/vultr/builder_test.go index ae78f57e..8c749ae9 100644 --- a/builder/vultr/builder_test.go +++ b/builder/vultr/builder_test.go @@ -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() @@ -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 { @@ -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) } } diff --git a/builder/vultr/config.go b/builder/vultr/config.go index adcf5312..a534174d 100644 --- a/builder/vultr/config.go +++ b/builder/vultr/config.go @@ -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"` diff --git a/builder/vultr/config.hcl2spec.go b/builder/vultr/config.hcl2spec.go index 3e625bc0..cf3f5bf2 100644 --- a/builder/vultr/config.hcl2spec.go +++ b/builder/vultr/config.hcl2spec.go @@ -78,13 +78,14 @@ type FlatConfig struct { AppID *int `mapstructure:"app_id" cty:"app_id" hcl:"app_id"` ImageID *string `mapstructure:"image_id" cty:"image_id" hcl:"image_id"` EnableIPV6 *bool `mapstructure:"enable_ipv6" cty:"enable_ipv6" hcl:"enable_ipv6"` - EnablePrivateNetwork *bool `mapstructure:"enable_private_network" cty:"enable_private_network" hcl:"enable_private_network"` + EnableVPC *bool `mapstructure:"enable_vpc" cty:"enable_vpc" hcl:"enable_vpc"` + EnableVPC2 *bool `mapstructure:"enable_vpc2" cty:"enable_vpc2" hcl:"enable_vpc2"` ScriptID *string `mapstructure:"script_id" cty:"script_id" hcl:"script_id"` SSHKeyIDs []string `mapstructure:"ssh_key_ids" cty:"ssh_key_ids" hcl:"ssh_key_ids"` Label *string `mapstructure:"instance_label" cty:"instance_label" hcl:"instance_label"` UserData *string `mapstructure:"userdata" cty:"userdata" hcl:"userdata"` Hostname *string `mapstructure:"hostname" cty:"hostname" hcl:"hostname"` - Tag *string `mapstructure:"tag" cty:"tag" hcl:"tag"` + Tags []string `mapstructure:"tags" cty:"tags" hcl:"tags"` RawStateTimeout *string `mapstructure:"state_timeout" cty:"state_timeout" hcl:"state_timeout"` } @@ -168,13 +169,14 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "app_id": &hcldec.AttrSpec{Name: "app_id", Type: cty.Number, Required: false}, "image_id": &hcldec.AttrSpec{Name: "image_id", Type: cty.String, Required: false}, "enable_ipv6": &hcldec.AttrSpec{Name: "enable_ipv6", Type: cty.Bool, Required: false}, - "enable_private_network": &hcldec.AttrSpec{Name: "enable_private_network", Type: cty.Bool, Required: false}, + "enable_vpc": &hcldec.AttrSpec{Name: "enable_vpc", Type: cty.Bool, Required: false}, + "enable_vpc2": &hcldec.AttrSpec{Name: "enable_vpc2", Type: cty.Bool, Required: false}, "script_id": &hcldec.AttrSpec{Name: "script_id", Type: cty.String, Required: false}, "ssh_key_ids": &hcldec.AttrSpec{Name: "ssh_key_ids", Type: cty.List(cty.String), Required: false}, "instance_label": &hcldec.AttrSpec{Name: "instance_label", Type: cty.String, Required: false}, "userdata": &hcldec.AttrSpec{Name: "userdata", Type: cty.String, Required: false}, "hostname": &hcldec.AttrSpec{Name: "hostname", Type: cty.String, Required: false}, - "tag": &hcldec.AttrSpec{Name: "tag", Type: cty.String, Required: false}, + "tags": &hcldec.AttrSpec{Name: "tags", Type: cty.List(cty.String), Required: false}, "state_timeout": &hcldec.AttrSpec{Name: "state_timeout", Type: cty.String, Required: false}, } return s diff --git a/builder/vultr/step_create_server.go b/builder/vultr/step_create_server.go index d5fcecbf..896fbe95 100644 --- a/builder/vultr/step_create_server.go +++ b/builder/vultr/step_create_server.go @@ -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) diff --git a/go.mod b/go.mod index b69ad152..795927d3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 395b44ce..826b41d2 100644 --- a/go.sum +++ b/go.sum @@ -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=