github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/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 } 13 14 // Client() returns a new client for accessing digital 15 // ocean. 16 // 17 func (c *Config) Client() (*consulapi.Client, error) { 18 config := consulapi.DefaultConfig() 19 if c.Datacenter != "" { 20 config.Datacenter = c.Datacenter 21 } 22 if c.Address != "" { 23 config.Address = c.Address 24 } 25 client, err := consulapi.NewClient(config) 26 27 log.Printf("[INFO] Consul Client configured with address: '%s', datacenter: '%s'", 28 config.Address, config.Datacenter) 29 if err != nil { 30 return nil, err 31 } 32 return client, nil 33 }