Add UserDataFile
This commit is contained in:
parent
da78ebbf83
commit
2152ad7609
|
@ -22,7 +22,7 @@ type Config struct {
|
|||
ServerImageName string `mapstructure:"server_image_name"`
|
||||
ServerImageDescription string `mapstructure:"server_image_description"`
|
||||
UserData string `mapstructure:"user_data"`
|
||||
UserDataFile string `mapstructure:"user_data_file"`
|
||||
UserDataFile string `mapstructure:"user_data_file"`
|
||||
BlockStorageSize int `mapstructure:"block_storage_size"`
|
||||
Region string `mapstructure:"region"`
|
||||
AccessControlGroupConfigurationNo string `mapstructure:"access_control_group_configuration_no"`
|
||||
|
@ -92,6 +92,14 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|||
}
|
||||
}
|
||||
|
||||
if c.UserData != "" && c.UserDataFile != "" {
|
||||
errs = append(errs, fmt.Errorf("Only one of user_data or user_data_file can be specified."))
|
||||
} else if c.UserDataFile != "" {
|
||||
if _, err := os.Stat(c.UserDataFile); err != nil {
|
||||
errs = append(errs, fmt.Errorf("user_data_file not found: %s", c.UserDataFile))
|
||||
}
|
||||
}
|
||||
|
||||
if c.UserData != "" && len(c.UserData) > 21847 {
|
||||
errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847"))
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package ncloud
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"time"
|
||||
|
||||
|
@ -49,6 +50,15 @@ func (s *StepCreateServerInstance) createServerInstance(loginKeyName string, zon
|
|||
reqParams.UserData = s.Config.UserData
|
||||
}
|
||||
|
||||
if s.Config.UserDataFile != "" {
|
||||
contents, err := ioutil.ReadFile(s.Config.UserDataFile)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("Problem reading user data file: %s", err)
|
||||
}
|
||||
|
||||
reqParams.UserData = string(contents)
|
||||
}
|
||||
|
||||
if s.Config.AccessControlGroupConfigurationNo != "" {
|
||||
reqParams.AccessControlGroupConfigurationNoList = []string{s.Config.AccessControlGroupConfigurationNo}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue