terraform/builtin/providers/consul/resource_provider.go

55 lines
1.2 KiB
Go
Raw Normal View History

2014-07-25 23:03:17 +02:00
package consul
import (
"log"
"github.com/hashicorp/terraform/helper/schema"
2014-07-25 23:03:17 +02:00
"github.com/hashicorp/terraform/terraform"
"github.com/mitchellh/mapstructure"
2014-07-25 23:03:17 +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,
},
"scheme": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"token": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
},
2014-09-29 19:28:08 +02:00
ResourcesMap: map[string]*schema.Resource{
"consul_agent_service": resourceConsulAgentService(),
"consul_catalog_entry": resourceConsulCatalogEntry(),
"consul_keys": resourceConsulKeys(),
2014-07-25 23:03:17 +02:00
},
ConfigureFunc: providerConfigure,
}
2014-07-25 23:03:17 +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")
return config.Client()
2014-07-25 23:03:17 +02:00
}