Skip to content

Commit

Permalink
Merge pull request #39 from gridscale/bug/cannot-create-boot-storage-…
Browse files Browse the repository at this point in the history
…if-missing-ssh-password

Fix cannot create boot storage when ssh password is not set
  • Loading branch information
nvthongswansea authored Jan 14, 2025
2 parents 4628093 + 446ccbc commit 18d329a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions builder/gridscale/step_create_boot_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"

"github.com/gridscale/gsclient-go/v3"
"github.com/hashicorp/packer-plugin-sdk/multistep"
"github.com/hashicorp/packer-plugin-sdk/packer"
Expand Down Expand Up @@ -38,18 +39,23 @@ func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBa
state.Put("error", err)
return multistep.ActionHalt
}
if sshKeyUUID == "" {
ui.Error("No SSH key UUID detected.")
state.Put("error", "No SSH key UUID detected.")
if sshKeyUUID == "" && c.Comm.SSHPassword == "" {
ui.Error("No SSH key UUID and no SSH password are provided.")
state.Put("error", "No SSH key UUID and no SSH password are provided.")
return multistep.ActionHalt
}
storageCreateReq.Template = &gsclient.StorageTemplate{
Password: c.Comm.SSHPassword,
PasswordType: gsclient.PlainPasswordType,
storage_template := gsclient.StorageTemplate{
Hostname: c.Hostname,
Sshkeys: []string{sshKeyUUID},
TemplateUUID: c.BaseTemplateUUID,
}
if sshKeyUUID != "" {
storage_template.Sshkeys = []string{sshKeyUUID}
}
if c.Comm.SSHPassword != "" {
storage_template.Password = c.Comm.SSHPassword
storage_template.PasswordType = gsclient.PlainPasswordType
}
storageCreateReq.Template = &storage_template
}
storage, err := client.CreateStorage(context.Background(), storageCreateReq)

Expand Down

0 comments on commit 18d329a

Please sign in to comment.