github.com/boyvanduuren/terraform@v0.7.0-rc2.0.20160805175930-de822d909c40/builtin/providers/consul/config.go (about) 1 package consul 2 3 import ( 4 "log" 5 6 consulapi "github.com/hashicorp/consul/api" 7 ) 8 9 type Config struct { 10 Datacenter string `mapstructure:"datacenter"` 11 Address string `mapstructure:"address"` 12 Token string `mapstructure:"token"` 13 Scheme string `mapstructure:"scheme"` 14 } 15 16 // Client() returns a new client for accessing consul. 17 // 18 func (c *Config) Client() (*consulapi.Client, error) { 19 config := consulapi.DefaultConfig() 20 if c.Datacenter != "" { 21 config.Datacenter = c.Datacenter 22 } 23 if c.Address != "" { 24 config.Address = c.Address 25 } 26 if c.Scheme != "" { 27 config.Scheme = c.Scheme 28 } 29 if c.Token != "" { 30 config.Token = c.Token 31 } 32 client, err := consulapi.NewClient(config) 33 34 log.Printf("[INFO] Consul Client configured with address: '%s', scheme: '%s', datacenter: '%s'", 35 config.Address, config.Scheme, config.Datacenter) 36 if err != nil { 37 return nil, err 38 } 39 return client, nil 40 }