Skip to content

Commit

Permalink
Replace/remove deprecated server options
Browse files Browse the repository at this point in the history
  • Loading branch information
optik-aper committed Oct 31, 2024
1 parent 4a391d3 commit 2b402dc
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 30 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
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

0 comments on commit 2b402dc

Please sign in to comment.