From 5dc6b183655d4eabfe4c9fb6dc22a2e9522e2ac4 Mon Sep 17 00:00:00 2001 From: YAMADA Tsuyoshi Date: Thu, 10 Nov 2016 18:50:31 +0900 Subject: [PATCH] googlecompute-export: use application default credential as same as googlecompute builder --- .../googlecompute-export/post-processor.go | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/post-processor/googlecompute-export/post-processor.go b/post-processor/googlecompute-export/post-processor.go index f198ab7c8..51a61c9a3 100644 --- a/post-processor/googlecompute-export/post-processor.go +++ b/post-processor/googlecompute-export/post-processor.go @@ -2,7 +2,6 @@ package googlecomputeexport import ( "fmt" - "io/ioutil" "strings" "github.com/mitchellh/multistep" @@ -83,13 +82,12 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac exporterConfig.CalcTimeout() // Set up credentials and GCE driver. - b, err := ioutil.ReadFile(accountKeyFilePath) - if err != nil { - err = fmt.Errorf("Error fetching account credentials: %s", err) - return nil, p.config.KeepOriginalImage, err + if accountKeyFilePath != "" { + err := googlecompute.ProcessAccountFile(&exporterConfig.Account, accountKeyFilePath) + if err != nil { + return nil, p.config.KeepOriginalImage, err + } } - accountKeyContents := string(b) - googlecompute.ProcessAccountFile(&exporterConfig.Account, accountKeyContents) driver, err := googlecompute.NewDriverGCE(ui, projectId, &exporterConfig.Account) if err != nil { return nil, p.config.KeepOriginalImage, err