diff --git a/builder/googlecompute/config.go b/builder/googlecompute/config.go index e5bc0eb70..40d0094c8 100644 --- a/builder/googlecompute/config.go +++ b/builder/googlecompute/config.go @@ -3,6 +3,7 @@ package googlecompute import ( "errors" "fmt" + "os" "regexp" "time" @@ -231,6 +232,13 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) { errs = packer.MultiErrorAppend(fmt.Errorf("you may not specify a 'service_account_email' when 'disable_default_service_account' is true")) } + if c.StartupScriptFile != "" { + if _, err := os.Stat(c.StartupScriptFile); err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("startup_script_file: %v", err)) + } + } + // Check for any errors. if errs != nil && len(errs.Errors) > 0 { return nil, nil, errs diff --git a/builder/googlecompute/config_test.go b/builder/googlecompute/config_test.go index 2da3faa59..0d3422a6e 100644 --- a/builder/googlecompute/config_test.go +++ b/builder/googlecompute/config_test.go @@ -329,6 +329,22 @@ func TestConfigPrepareServiceAccount(t *testing.T) { } } +func TestConfigPrepareStartupScriptFile(t *testing.T) { + config := map[string]interface{}{ + "project_id": "project", + "source_image": "foo", + "ssh_username": "packer", + "startup_script_file": "no-such-file", + "zone": "us-central1-a", + } + + _, _, errs := NewConfig(config) + + if errs == nil || !strings.Contains(errs.Error(), "startup_script_file") { + t.Fatalf("should error: startup_script_file") + } +} + func TestConfigDefaults(t *testing.T) { cases := []struct { Read func(c *Config) interface{}