|
|
|
|
@ -5,7 +5,6 @@ import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/pathorcontents"
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
|
"google.golang.org/api/compute/v1"
|
|
|
|
|
@ -17,11 +16,10 @@ func Provider() terraform.ResourceProvider {
|
|
|
|
|
return &schema.Provider{
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
|
"account_file": &schema.Schema{
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_ACCOUNT_FILE", nil),
|
|
|
|
|
ValidateFunc: validateAccountFile,
|
|
|
|
|
Deprecated: "Use the credentials field instead",
|
|
|
|
|
Type: schema.TypeString,
|
|
|
|
|
Optional: true,
|
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_ACCOUNT_FILE", nil),
|
|
|
|
|
Removed: "Use the credentials field instead",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"credentials": &schema.Schema{
|
|
|
|
|
@ -115,9 +113,6 @@ func Provider() terraform.ResourceProvider {
|
|
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
|
credentials := d.Get("credentials").(string)
|
|
|
|
|
if credentials == "" {
|
|
|
|
|
credentials = d.Get("account_file").(string)
|
|
|
|
|
}
|
|
|
|
|
config := Config{
|
|
|
|
|
Credentials: credentials,
|
|
|
|
|
Project: d.Get("project").(string),
|
|
|
|
|
@ -131,36 +126,6 @@ func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
|
return &config, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func validateAccountFile(v interface{}, k string) (warnings []string, errors []error) {
|
|
|
|
|
if v == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
value := v.(string)
|
|
|
|
|
|
|
|
|
|
if value == "" {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
contents, wasPath, err := pathorcontents.Read(value)
|
|
|
|
|
if err != nil {
|
|
|
|
|
errors = append(errors, fmt.Errorf("Error loading Account File: %s", err))
|
|
|
|
|
}
|
|
|
|
|
if wasPath {
|
|
|
|
|
warnings = append(warnings, `account_file was provided as a path instead of
|
|
|
|
|
as file contents. This support will be removed in the future. Please update
|
|
|
|
|
your configuration to use ${file("filename.json")} instead.`)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var account accountFile
|
|
|
|
|
if err := json.Unmarshal([]byte(contents), &account); err != nil {
|
|
|
|
|
errors = append(errors,
|
|
|
|
|
fmt.Errorf("account_file not valid JSON '%s': %s", contents, err))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func validateCredentials(v interface{}, k string) (warnings []string, errors []error) {
|
|
|
|
|
if v == nil || v.(string) == "" {
|
|
|
|
|
return
|
|
|
|
|
|