providers/consul: add scheme argument

This enables connecting to consul over https
without having to set the envvar CONSUL_HTTP_SSL.
This commit is contained in:
Josh Bleecher Snyder 2015-05-06 16:12:32 -07:00
parent 7311019efe
commit 30d34908b7
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.