backend/remote-state/gcs: Read credentials with ioutil.ReadFile().

We never expect the raw JSON to appear in the config, so pathorcontents is
not the right package here.
This commit is contained in:
Florian Forster 2017-09-12 10:48:09 +02:00 committed by James Bardin
parent c00e929ee5
commit 816c98f387
1 changed files with 5 additions and 4 deletions

View File

@ -4,11 +4,11 @@ package gcs
import (
"context"
"fmt"
"io/ioutil"
"strings"
"cloud.google.com/go/storage"
"github.com/hashicorp/terraform/backend"
"github.com/hashicorp/terraform/helper/pathorcontents"
"github.com/hashicorp/terraform/helper/schema"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
@ -86,12 +86,13 @@ func (b *gcsBackend) configure(ctx context.Context) error {
var tokenSource oauth2.TokenSource
if credentials := data.Get("credentials").(string); credentials != "" {
credentialsJson, _, err := pathorcontents.Read(data.Get("credentials").(string))
path := data.Get("credentials").(string)
json, err := ioutil.ReadFile(path)
if err != nil {
return fmt.Errorf("Error loading credentials: %v", err)
return fmt.Errorf("reading %q: %v", path, err)
}
jwtConfig, err := google.JWTConfigFromJSON([]byte(credentialsJson), storage.ScopeReadWrite)
jwtConfig, err := google.JWTConfigFromJSON([]byte(json), storage.ScopeReadWrite)
if err != nil {
return fmt.Errorf("Failed to get Google OAuth2 token: %v", err)
}