Merge pull request #4148 from minimum2scp/features/googlecompute-export-application-default-credential

googlecompute-export: use application default credential
This commit is contained in:
Matthew Hooker 2018-02-05 09:51:21 -08:00 committed by GitHub
commit 625201c819
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 7 deletions

View File

@ -2,7 +2,6 @@ package googlecomputeexport
import ( import (
"fmt" "fmt"
"io/ioutil"
"strings" "strings"
"github.com/hashicorp/packer/builder/googlecompute" "github.com/hashicorp/packer/builder/googlecompute"
@ -88,13 +87,12 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
exporterConfig.CalcTimeout() exporterConfig.CalcTimeout()
// Set up credentials and GCE driver. // Set up credentials and GCE driver.
b, err := ioutil.ReadFile(accountKeyFilePath) if accountKeyFilePath != "" {
if err != nil { err := googlecompute.ProcessAccountFile(&exporterConfig.Account, accountKeyFilePath)
err = fmt.Errorf("Error fetching account credentials: %s", err) if err != nil {
return nil, p.config.KeepOriginalImage, err return nil, p.config.KeepOriginalImage, err
}
} }
accountKeyContents := string(b)
googlecompute.ProcessAccountFile(&exporterConfig.Account, accountKeyContents)
driver, err := googlecompute.NewDriverGCE(ui, projectId, &exporterConfig.Account) driver, err := googlecompute.NewDriverGCE(ui, projectId, &exporterConfig.Account)
if err != nil { if err != nil {
return nil, p.config.KeepOriginalImage, err return nil, p.config.KeepOriginalImage, err