Skip to content

Commit

Permalink
fix cannot create boot storage when ssh password is not set
Browse files Browse the repository at this point in the history
add ssh key, ssh password or both to boot storage when one/both are set
  • Loading branch information
nvthongswansea committed Jan 13, 2025
1 parent 4628093 commit 446ccbc
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 446ccbc

Please sign in to comment.