49 lines
1.1 KiB
Go
49 lines
1.1 KiB
Go
package consul
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
"github.com/hashicorp/terraform/terraform"
|
|
"github.com/mitchellh/mapstructure"
|
|
)
|
|
|
|
// 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,
|
|
},
|
|
},
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
"consul_keys": resourceConsulKeys(),
|
|
"consul_key_prefix": resourceConsulKeyPrefix(),
|
|
},
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
}
|
|
}
|
|
|
|
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
|
|
}
|
|
log.Printf("[INFO] Initializing Consul client")
|
|
return config.Client()
|
|
}
|