parent
e9a918f83d
commit
337895b51e
|
@ -27,20 +27,29 @@ func Provider() terraform.ResourceProvider {
|
|||
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
||||
"GOOGLE_CREDENTIALS",
|
||||
"GOOGLE_CLOUD_KEYFILE_JSON",
|
||||
"GCLOUD_KEYFILE_JSON",
|
||||
}, nil),
|
||||
ValidateFunc: validateCredentials,
|
||||
},
|
||||
|
||||
"project": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_PROJECT", ""),
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
||||
"GOOGLE_PROJECT",
|
||||
"GCLOUD_PROJECT",
|
||||
"CLOUDSDK_CORE_PROJECT",
|
||||
}, nil),
|
||||
},
|
||||
|
||||
"region": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_REGION", nil),
|
||||
Type: schema.TypeString,
|
||||
Required: true,
|
||||
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
||||
"GOOGLE_REGION",
|
||||
"GCLOUD_REGION",
|
||||
"CLOUDSDK_COMPUTE_REGION",
|
||||
}, nil),
|
||||
},
|
||||
},
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package google
|
|||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/schema"
|
||||
|
@ -38,18 +39,40 @@ func testAccPreCheck(t *testing.T) {
|
|||
os.Setenv("GOOGLE_CREDENTIALS", string(creds))
|
||||
}
|
||||
|
||||
if v := os.Getenv("GOOGLE_CREDENTIALS"); v == "" {
|
||||
if w := os.Getenv("GOOGLE_CLOUD_KEYFILE_JSON"); w == "" {
|
||||
t.Fatal("GOOGLE_CREDENTIALS or GOOGLE_CLOUD_KEYFILE_JSON must be set for acceptance tests")
|
||||
multiEnvSearch := func(ks []string) string {
|
||||
for _, k := range ks {
|
||||
if v := os.Getenv(k); v != "" {
|
||||
return v
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
if v := os.Getenv("GOOGLE_PROJECT"); v == "" {
|
||||
t.Fatal("GOOGLE_PROJECT must be set for acceptance tests")
|
||||
creds := []string{
|
||||
"GOOGLE_CREDENTIALS",
|
||||
"GOOGLE_CLOUD_KEYFILE_JSON",
|
||||
"GCLOUD_KEYFILE_JSON",
|
||||
}
|
||||
if v := multiEnvSearch(creds); v == "" {
|
||||
t.Fatalf("One of %s must be set for acceptance tests", strings.Join(creds, ", "))
|
||||
}
|
||||
|
||||
if v := os.Getenv("GOOGLE_REGION"); v != "us-central1" {
|
||||
t.Fatal("GOOGLE_REGION must be set to us-central1 for acceptance tests")
|
||||
projs := []string{
|
||||
"GOOGLE_PROJECT",
|
||||
"GCLOUD_PROJECT",
|
||||
"CLOUDSDK_CORE_PROJECT",
|
||||
}
|
||||
if v := multiEnvSearch(projs); v == "" {
|
||||
t.Fatalf("One of %s must be set for acceptance tests", strings.Join(creds, ", "))
|
||||
}
|
||||
|
||||
regs := []string{
|
||||
"GOOGLE_REGION",
|
||||
"GCLOUD_REGION",
|
||||
"CLOUDSDK_COMPUTE_REGION",
|
||||
}
|
||||
if v := multiEnvSearch(regs); v != "us-central-1" {
|
||||
t.Fatalf("One of %s must be set to us-central-1 for acceptance tests", strings.Join(creds, ", "))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -39,17 +39,28 @@ 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` or `GOOGLE_CLOUD_KEYFILE_JSON`
|
||||
shell environment variable, containing the contents of the credentials file.
|
||||
can also be specified using any of the following environment variables
|
||||
(listed in order of precedence):
|
||||
|
||||
* `GOOGLE_CREDENTIALS`
|
||||
* `GOOGLE_CLOUD_KEYFILE_JSON`
|
||||
* `GCLOUD_KEYFILE_JSON`
|
||||
|
||||
* `project` - (Required) The ID of the project to apply any resources to. This
|
||||
can be specified using any of the following environment variables (listed in
|
||||
order of precedence):
|
||||
|
||||
* `GOOGLE_PROJECT`
|
||||
* `GCLOUD_PROJECT`
|
||||
* `CLOUDSDK_CORE_PROJECT`
|
||||
|
||||
* `region` - (Required) The region to operate under. This can also be specified
|
||||
with the `GOOGLE_REGION` shell environment variable.
|
||||
using any of the following environment variables (listed in order of
|
||||
precedence):
|
||||
|
||||
* `project` - (Optional) The ID of the project to apply resources in. This
|
||||
can also be specified with the `GOOGLE_PROJECT` shell environment variable.
|
||||
If unspecified, users will need to specify the `project` attribute for
|
||||
all resources. If specified, resources which do not depend on a project will
|
||||
ignore this value.
|
||||
* `GOOGLE_REGION`
|
||||
* `GCLOUD_REGION`
|
||||
* `CLOUDSDK_COMPUTE_REGION`
|
||||
|
||||
The following keys are supported for backwards compatibility, and may be
|
||||
removed in a future version:
|
||||
|
|
Loading…
Reference in New Issue