Skip to content

Commit d9b65cb

Browse files
fix cannot create boot storage when ssh password is not set
add ssh key, ssh password or both to boot storage when one/both are set
1 parent 2a14105 commit d9b65cb

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

builder/gridscale/step_create_boot_storage.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
78
"github.com/gridscale/gsclient-go/v3"
89
"github.com/hashicorp/packer-plugin-sdk/multistep"
910
"github.com/hashicorp/packer-plugin-sdk/packer"
@@ -38,18 +39,23 @@ func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBa
3839
state.Put("error", err)
3940
return multistep.ActionHalt
4041
}
41-
if sshKeyUUID == "" {
42-
ui.Error("No SSH key UUID detected.")
43-
state.Put("error", "No SSH key UUID detected.")
42+
if sshKeyUUID == "" && c.Comm.SSHPassword == "" {
43+
ui.Error("No SSH key UUID and no SSH password are provided.")
44+
state.Put("error", "No SSH key UUID and no SSH password are provided.")
4445
return multistep.ActionHalt
4546
}
46-
storageCreateReq.Template = &gsclient.StorageTemplate{
47-
Password: c.Comm.SSHPassword,
48-
PasswordType: gsclient.PlainPasswordType,
47+
storage_template := gsclient.StorageTemplate{
4948
Hostname: c.Hostname,
50-
Sshkeys: []string{sshKeyUUID},
5149
TemplateUUID: c.BaseTemplateUUID,
5250
}
51+
if sshKeyUUID != "" {
52+
storage_template.Sshkeys = []string{sshKeyUUID}
53+
}
54+
if c.Comm.SSHPassword != "" {
55+
storage_template.Password = c.Comm.SSHPassword
56+
storage_template.PasswordType = gsclient.PlainPasswordType
57+
}
58+
storageCreateReq.Template = &storage_template
5359
}
5460
storage, err := client.CreateStorage(context.Background(), storageCreateReq)
5561

0 commit comments

Comments
 (0)