From 2b402dc99949e1e6c590a316c61cc23dcba2849c Mon Sep 17 00:00:00 2001 From: Michael Riley Date: Thu, 31 Oct 2024 09:52:45 -0400 Subject: [PATCH] Replace/remove deprecated server options --- builder/vultr/builder_test.go | 45 +++++++++++++++++++++++++---- builder/vultr/config.go | 17 ++++++----- builder/vultr/step_create_server.go | 33 +++++++++++---------- 3 files changed, 65 insertions(+), 30 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/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)