googlecompute-export: use application default credential as same as googlecompute builder

This commit is contained in:
YAMADA Tsuyoshi 2016-11-10 18:50:31 +09:00
parent 6be3860412
commit 5dc6b18365
1 changed files with 5 additions and 7 deletions

View File

@ -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