From 1e1af353416ccbee6fd26f8ffda4e92a0589bbbe Mon Sep 17 00:00:00 2001 From: Pratyush singhal Date: Thu, 6 Jun 2019 16:14:57 +0530 Subject: [PATCH] refactor: replace userdata_files with generic metadata_files map Signed-off-by: Pratyush singhal --- builder/googlecompute/config.go | 2 +- builder/googlecompute/step_create_instance.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index 41444d757..7c78a93cd 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -62,7 +62,7 @@ type Config struct { Subnetwork string `mapstructure:"subnetwork"` Tags []string `mapstructure:"tags"` UseInternalIP bool `mapstructure:"use_internal_ip"` - UserdataFile string `mapstructure:"userdata_file"` + MetadataFiles map[string]string `mapstructure:"metadata_files"` Zone string `mapstructure:"zone"` Account AccountFile diff --git a/builder/googlecompute/step_create_instance.go b/builder/googlecompute/step_create_instance.go index 5fd0de5ce..0688d6280 100644 --- a/builder/googlecompute/step_create_instance.go +++ b/builder/googlecompute/step_create_instance.go @@ -45,10 +45,11 @@ func (c *Config) createInstanceMetadata(sourceImage *Image, sshPublicKey string) instanceMetadata[StartupWrappedScriptKey] = wrappedStartupScript } - if c.UserdataFile != "" { + // Read metadata from files specified with metadata_files + for key, value := range c.MetadataFiles { var content []byte - content, err = ioutil.ReadFile(c.UserdataFile) - instanceMetadata["user-data"] = string(content) + content, err = ioutil.ReadFile(value) + instanceMetadata[key] = string(content) } if sourceImage.IsWindows() {