github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/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  	Scheme     string `mapstructure:"scheme"`
    13  }
    14  
    15  // Client() returns a new client for accessing consul.
    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  	if c.Scheme != "" {
    26  		config.Scheme = c.Scheme
    27  	}
    28  	client, err := consulapi.NewClient(config)
    29  
    30  	log.Printf("[INFO] Consul Client configured with address: '%s', scheme: '%s', datacenter: '%s'",
    31  		config.Address, config.Scheme, config.Datacenter)
    32  	if err != nil {
    33  		return nil, err
    34  	}
    35  	return client, nil
    36  }