From 986fcd95f9609b5863837cd70892dddf60d773e7 Mon Sep 17 00:00:00 2001 From: Clint Date: Mon, 4 Apr 2016 16:56:35 -0500 Subject: [PATCH] provider/google: Accept GOOGLE_CLOUD_KEYFILE_JSON env var for credentials --- builtin/providers/google/provider.go | 9 ++++++--- builtin/providers/google/provider_test.go | 4 +++- website/source/docs/providers/google/index.html.markdown | 4 ++-- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/builtin/providers/google/provider.go b/builtin/providers/google/provider.go index a2fc6d5fd..e496b4eec 100644 --- a/builtin/providers/google/provider.go +++ b/builtin/providers/google/provider.go @@ -22,9 +22,12 @@ func Provider() terraform.ResourceProvider { }, "credentials": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - DefaultFunc: schema.EnvDefaultFunc("GOOGLE_CREDENTIALS", nil), + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.MultiEnvDefaultFunc([]string{ + "GOOGLE_CREDENTIALS", + "GOOGLE_CLOUD_KEYFILE_JSON", + }, nil), ValidateFunc: validateCredentials, }, diff --git a/builtin/providers/google/provider_test.go b/builtin/providers/google/provider_test.go index 1be008292..9bf5414b7 100644 --- a/builtin/providers/google/provider_test.go +++ b/builtin/providers/google/provider_test.go @@ -39,7 +39,9 @@ func testAccPreCheck(t *testing.T) { } if v := os.Getenv("GOOGLE_CREDENTIALS"); v == "" { - t.Fatal("GOOGLE_CREDENTIALS must be set for acceptance tests") + if w := os.Getenv("GOOGLE_CLOUD_KEYFILE_JSON"); w == "" { + t.Fatal("GOOGLE_CREDENTIALS or GOOGLE_CLOUD_KEYFILE_JSON must be set for acceptance tests") + } } if v := os.Getenv("GOOGLE_PROJECT"); v == "" { diff --git a/website/source/docs/providers/google/index.html.markdown b/website/source/docs/providers/google/index.html.markdown index 2dfc69cfd..c7cf44e98 100644 --- a/website/source/docs/providers/google/index.html.markdown +++ b/website/source/docs/providers/google/index.html.markdown @@ -39,8 +39,8 @@ The following keys can be used to configure the provider. retrieving this file are below. Credentials may be blank if you are running Terraform from a GCE instance with a properly-configured [Compute Engine Service Account](https://cloud.google.com/compute/docs/authentication). This - can also be specified with the `GOOGLE_CREDENTIALS` shell environment - variable. + can also be specified with the `GOOGLE_CREDENTIALS` or `GOOGLE_CLOUD_KEYFILE_JSON` + shell environment variable, containing the contents of the credentials file. * `project` - (Required) The ID of the project to apply any resources to. This can also be specified with the `GOOGLE_PROJECT` shell environment variable.