2014-08-25 20:48:20 +02:00
|
|
|
package google
|
|
|
|
|
|
|
|
import (
|
2015-07-27 21:35:52 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
|
2014-08-25 20:48:20 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-09-28 20:51:39 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-08-25 20:48:20 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Provider returns a terraform.ResourceProvider.
|
2014-09-28 20:51:39 +02:00
|
|
|
func Provider() terraform.ResourceProvider {
|
2014-08-25 20:48:20 +02:00
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"account_file": &schema.Schema{
|
2015-07-27 21:35:52 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_ACCOUNT_FILE", nil),
|
|
|
|
ValidateFunc: validateAccountFile,
|
2015-07-23 22:53:44 +02:00
|
|
|
},
|
|
|
|
|
2014-08-25 21:55:08 +02:00
|
|
|
"project": &schema.Schema{
|
2014-11-20 11:25:23 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2015-01-16 18:22:09 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_PROJECT", nil),
|
2014-08-25 21:55:08 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"region": &schema.Schema{
|
2014-11-20 11:25:23 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2015-01-16 18:22:09 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("GOOGLE_REGION", nil),
|
2014-08-25 21:55:08 +02:00
|
|
|
},
|
2014-08-25 20:48:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2015-07-28 02:47:10 +02:00
|
|
|
"google_compute_autoscaler": resourceComputeAutoscaler(),
|
2015-05-17 02:14:38 +02:00
|
|
|
"google_compute_address": resourceComputeAddress(),
|
|
|
|
"google_compute_disk": resourceComputeDisk(),
|
|
|
|
"google_compute_firewall": resourceComputeFirewall(),
|
|
|
|
"google_compute_forwarding_rule": resourceComputeForwardingRule(),
|
2014-11-20 18:40:17 +01:00
|
|
|
"google_compute_http_health_check": resourceComputeHttpHealthCheck(),
|
2015-05-17 02:14:38 +02:00
|
|
|
"google_compute_instance": resourceComputeInstance(),
|
2015-02-10 11:29:27 +01:00
|
|
|
"google_compute_instance_template": resourceComputeInstanceTemplate(),
|
2015-05-17 02:14:38 +02:00
|
|
|
"google_compute_network": resourceComputeNetwork(),
|
|
|
|
"google_compute_route": resourceComputeRoute(),
|
|
|
|
"google_compute_target_pool": resourceComputeTargetPool(),
|
2015-07-20 20:25:26 +02:00
|
|
|
"google_container_cluster": resourceContainerCluster(),
|
2015-05-17 02:14:38 +02:00
|
|
|
"google_dns_managed_zone": resourceDnsManagedZone(),
|
|
|
|
"google_dns_record_set": resourceDnsRecordSet(),
|
2015-07-28 02:47:10 +02:00
|
|
|
"google_compute_instance_group_manager": resourceComputeInstanceGroupManager(),
|
2015-07-20 20:25:26 +02:00
|
|
|
"google_storage_bucket": resourceStorageBucket(),
|
2014-08-25 20:48:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
2015-07-27 21:35:52 +02:00
|
|
|
AccountFile: d.Get("account_file").(string),
|
|
|
|
Project: d.Get("project").(string),
|
|
|
|
Region: d.Get("region").(string),
|
2014-08-25 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := config.loadAndValidate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2014-08-25 21:55:08 +02:00
|
|
|
return &config, nil
|
2014-08-25 20:48:20 +02:00
|
|
|
}
|
2015-07-27 21:35:52 +02:00
|
|
|
|
|
|
|
func validateAccountFile(v interface{}, k string) (warnings []string, errors []error) {
|
|
|
|
value := v.(string)
|
|
|
|
|
|
|
|
if value == "" {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var account accountFile
|
|
|
|
if err := json.Unmarshal([]byte(value), &account); err != nil {
|
|
|
|
warnings = append(warnings, `
|
|
|
|
account_file is not valid JSON, so we are assuming it is a file path. This
|
|
|
|
support will be removed in the future. Please update your configuration to use
|
|
|
|
${file("filename.json")} instead.`)
|
2015-07-27 23:06:48 +02:00
|
|
|
} else {
|
2015-07-27 21:35:52 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:07:38 +02:00
|
|
|
if _, err := os.Stat(value); err != nil {
|
|
|
|
errors = append(errors,
|
|
|
|
fmt.Errorf(
|
|
|
|
"account_file path could not be read from '%s': %s",
|
|
|
|
value,
|
|
|
|
err))
|
2015-07-27 21:35:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|