Merge pull request #1838 from josharian/consul-scheme

providers/consul: add scheme argument
This commit is contained in:
Paul Hinze 2015-05-06 19:09:11 -05:00
commit 9a286402c3
4 changed files with 14 additions and 3 deletions

View File

@ -9,6 +9,7 @@ import (
type Config struct { type Config struct {
Datacenter string `mapstructure:"datacenter"` Datacenter string `mapstructure:"datacenter"`
Address string `mapstructure:"address"` Address string `mapstructure:"address"`
Scheme string `mapstructure:"scheme"`
} }
// Client() returns a new client for accessing consul. // Client() returns a new client for accessing consul.
@ -21,10 +22,13 @@ func (c *Config) Client() (*consulapi.Client, error) {
if c.Address != "" { if c.Address != "" {
config.Address = c.Address config.Address = c.Address
} }
if c.Scheme != "" {
config.Scheme = c.Scheme
}
client, err := consulapi.NewClient(config) client, err := consulapi.NewClient(config)
log.Printf("[INFO] Consul Client configured with address: '%s', datacenter: '%s'", log.Printf("[INFO] Consul Client configured with address: '%s', scheme: '%s', datacenter: '%s'",
config.Address, config.Datacenter) config.Address, config.Scheme, config.Datacenter)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -21,6 +21,11 @@ func Provider() terraform.ResourceProvider {
Type: schema.TypeString, Type: schema.TypeString,
Optional: true, Optional: true,
}, },
"scheme": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
}, },
ResourcesMap: map[string]*schema.Resource{ ResourcesMap: map[string]*schema.Resource{

View File

@ -42,6 +42,7 @@ func TestResourceProvider_Configure(t *testing.T) {
raw := map[string]interface{}{ raw := map[string]interface{}{
"address": "demo.consul.io:80", "address": "demo.consul.io:80",
"datacenter": "nyc3", "datacenter": "nyc3",
"scheme": "https",
} }
rawConfig, err := config.NewRawConfig(raw) rawConfig, err := config.NewRawConfig(raw)

View File

@ -43,6 +43,7 @@ resource "aws_instance" "app" {
The following arguments are supported: The following arguments are supported:
* `address` - (Optional) The HTTP API address of the agent to use. Defaults to "127.0.0.1:8500". * `address` - (Optional) The HTTP(S) API address of the agent to use. Defaults to "127.0.0.1:8500".
* `scheme` - (Optional) The URL scheme of the agent to use ("http" or "https"). Defaults to "http".
* `datacenter` - (Optional) The datacenter to use. Defaults to that of the agent. * `datacenter` - (Optional) The datacenter to use. Defaults to that of the agent.