|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
| 7 | + |
7 | 8 | "github.com/gridscale/gsclient-go/v3" |
8 | 9 | "github.com/hashicorp/packer-plugin-sdk/multistep" |
9 | 10 | "github.com/hashicorp/packer-plugin-sdk/packer" |
@@ -38,18 +39,23 @@ func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBa |
38 | 39 | state.Put("error", err) |
39 | 40 | return multistep.ActionHalt |
40 | 41 | } |
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.") |
44 | 45 | return multistep.ActionHalt |
45 | 46 | } |
46 | | - storageCreateReq.Template = &gsclient.StorageTemplate{ |
47 | | - Password: c.Comm.SSHPassword, |
48 | | - PasswordType: gsclient.PlainPasswordType, |
| 47 | + storage_template := gsclient.StorageTemplate{ |
49 | 48 | Hostname: c.Hostname, |
50 | | - Sshkeys: []string{sshKeyUUID}, |
51 | 49 | TemplateUUID: c.BaseTemplateUUID, |
52 | 50 | } |
| 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 |
53 | 59 | } |
54 | 60 | storage, err := client.CreateStorage(context.Background(), storageCreateReq) |
55 | 61 |
|
|
0 commit comments