Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cannot create boot storage when ssh password is not set #39

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading