@@ -11,9 +11,10 @@ import (
1111)
1212
1313type stepCreateBootStorage struct {
14- client gsclient.StorageOperator
15- config * Config
16- ui packer.Ui
14+ client gsclient.StorageOperator
15+ templateClient gsclient.TemplateOperator
16+ config * Config
17+ ui packer.Ui
1718}
1819
1920func (s * stepCreateBootStorage ) Run (ctx context.Context , state multistep.StateBag ) multistep.StepAction {
@@ -39,21 +40,31 @@ func (s *stepCreateBootStorage) Run(ctx context.Context, state multistep.StateBa
3940 state .Put ("error" , err )
4041 return multistep .ActionHalt
4142 }
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." )
45- return multistep .ActionHalt
46- }
4743 storage_template := gsclient.StorageTemplate {
48- Hostname : c .Hostname ,
4944 TemplateUUID : c .BaseTemplateUUID ,
5045 }
51- if sshKeyUUID != "" {
52- storage_template .Sshkeys = []string {sshKeyUUID }
46+ template , err := s .templateClient .GetTemplate (context .Background (), c .BaseTemplateUUID )
47+ if err != nil {
48+ ui .Error (fmt .Sprintf ("Error getting template: %s" , err ))
49+ state .Put ("error" , err )
50+ return multistep .ActionHalt
5351 }
54- if c .Comm .SSHPassword != "" {
55- storage_template .Password = c .Comm .SSHPassword
56- storage_template .PasswordType = gsclient .PlainPasswordType
52+ // Check if template is public, if so, either ssh key or password and hostname is required.
53+ // If template is private, ssh key or password will be ignored.
54+ if ! template .Properties .Private {
55+ storage_template .Hostname = c .Hostname
56+ if sshKeyUUID == "" && c .Comm .SSHPassword == "" {
57+ ui .Error ("No SSH key UUID and no SSH password are provided." )
58+ state .Put ("error" , "No SSH key UUID and no SSH password are provided." )
59+ return multistep .ActionHalt
60+ }
61+ if sshKeyUUID != "" {
62+ storage_template .Sshkeys = []string {sshKeyUUID }
63+ }
64+ if c .Comm .SSHPassword != "" {
65+ storage_template .Password = c .Comm .SSHPassword
66+ storage_template .PasswordType = gsclient .PlainPasswordType
67+ }
5768 }
5869 storageCreateReq .Template = & storage_template
5970 }
0 commit comments