2014-07-25 23:03:17 +02:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
2014-07-25 23:03:17 +02:00
|
|
|
"github.com/hashicorp/terraform/terraform"
|
2014-10-13 20:35:45 +02:00
|
|
|
"github.com/mitchellh/mapstructure"
|
2014-07-25 23:03:17 +02:00
|
|
|
)
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
// Provider returns a terraform.ResourceProvider.
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"datacenter": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"address": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-08-12 04:22:41 +02:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"CONSUL_ADDRESS",
|
|
|
|
"CONSUL_HTTP_ADDR",
|
2016-08-30 15:28:03 +02:00
|
|
|
}, "localhost:8500"),
|
2014-10-13 20:35:45 +02:00
|
|
|
},
|
2015-05-07 01:12:32 +02:00
|
|
|
|
|
|
|
"scheme": &schema.Schema{
|
2016-08-30 15:28:03 +02:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"CONSUL_SCHEME",
|
|
|
|
"CONSUL_HTTP_SCHEME",
|
|
|
|
}, "http"),
|
2016-08-12 04:22:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"ca_file": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-08-30 15:28:03 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CONSUL_CA_FILE", ""),
|
2016-08-12 04:22:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"cert_file": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-08-30 15:28:03 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CONSUL_CERT_FILE", ""),
|
2016-08-12 04:22:41 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
"key_file": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-08-30 15:28:03 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("CONSUL_KEY_FILE", ""),
|
2015-05-07 01:12:32 +02:00
|
|
|
},
|
2015-09-23 09:43:48 +02:00
|
|
|
|
|
|
|
"token": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2016-08-30 15:28:03 +02:00
|
|
|
DefaultFunc: schema.MultiEnvDefaultFunc([]string{
|
|
|
|
"CONSUL_TOKEN",
|
|
|
|
"CONSUL_HTTP_TOKEN",
|
|
|
|
}, ""),
|
2015-09-23 09:43:48 +02:00
|
|
|
},
|
2014-10-13 20:35:45 +02:00
|
|
|
},
|
2014-09-29 19:28:08 +02:00
|
|
|
|
2016-07-26 19:23:38 +02:00
|
|
|
DataSourcesMap: map[string]*schema.Resource{
|
|
|
|
"consul_keys": dataSourceConsulKeys(),
|
|
|
|
},
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
2016-08-18 09:46:30 +02:00
|
|
|
"consul_agent_service": resourceConsulAgentService(),
|
|
|
|
"consul_catalog_entry": resourceConsulCatalogEntry(),
|
|
|
|
"consul_keys": resourceConsulKeys(),
|
|
|
|
"consul_key_prefix": resourceConsulKeyPrefix(),
|
|
|
|
"consul_node": resourceConsulNode(),
|
|
|
|
"consul_prepared_query": resourceConsulPreparedQuery(),
|
|
|
|
"consul_service": resourceConsulService(),
|
2014-07-25 23:03:17 +02:00
|
|
|
},
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
2014-07-25 23:03:17 +02:00
|
|
|
}
|
|
|
|
|
2014-10-13 20:35:45 +02:00
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
var config Config
|
|
|
|
configRaw := d.Get("").(map[string]interface{})
|
|
|
|
if err := mapstructure.Decode(configRaw, &config); err != nil {
|
|
|
|
return nil, err
|
2014-07-25 23:03:17 +02:00
|
|
|
}
|
2014-07-26 04:14:48 +02:00
|
|
|
log.Printf("[INFO] Initializing Consul client")
|
2014-10-13 20:35:45 +02:00
|
|
|
return config.Client()
|
2014-07-25 23:03:17 +02:00
|
|
|
}
|