github.com/ndarilek/terraform@v0.3.8-0.20150320140257-d3135c1b2bac/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 consul.
    15  //
    16  func (c *Config) Client() (*consulapi.Client, error) {
    17  	config := consulapi.DefaultConfig()
    18  	if c.Datacenter != "" {
    19  		config.Datacenter = c.Datacenter
    20  	}
    21  	if c.Address != "" {
    22  		config.Address = c.Address
    23  	}
    24  	client, err := consulapi.NewClient(config)
    25  
    26  	log.Printf("[INFO] Consul Client configured with address: '%s', datacenter: '%s'",
    27  		config.Address, config.Datacenter)
    28  	if err != nil {
    29  		return nil, err
    30  	}
    31  	return client, nil
    32  }