feat: add feature to import user-data from a file

Signed-off-by: Pratyush singhal <psinghal20@gmail.com>
This commit is contained in:
Pratyush singhal 2019-06-06 11:13:17 +05:30
parent 2620e18247
commit 3845186c4c
2 changed files with 8 additions and 1 deletions

View File

@ -62,6 +62,7 @@ type Config struct {
Subnetwork string `mapstructure:"subnetwork"`
Tags []string `mapstructure:"tags"`
UseInternalIP bool `mapstructure:"use_internal_ip"`
UserdataFile string `mapstructure:"userdata_file"`
Zone string `mapstructure:"zone"`
Account AccountFile

View File

@ -19,7 +19,6 @@ type StepCreateInstance struct {
func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) (map[string]string, error) {
instanceMetadata := make(map[string]string)
var err error
// Copy metadata from config.
for k, v := range c.Metadata {
instanceMetadata[k] = v
@ -45,6 +44,13 @@ func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string)
} else if wrappedStartupScript, exists := instanceMetadata[StartupScriptKey]; exists {
instanceMetadata[StartupWrappedScriptKey] = wrappedStartupScript
}
if c.UserdataFile != "" {
var content []byte
content, err = ioutil.ReadFile(c.UserdataFile)
instanceMetadata["user-data"] = string(content)
}
if sourceImage.IsWindows() {
// Windows startup script support is not yet implemented.
// Mark the startup script as done.