From 30d34908b7f899650ce1ffd1f3c73be9d11e4fba Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Wed, 6 May 2015 16:12:32 -0700 Subject: [PATCH] providers/consul: add scheme argument This enables connecting to consul over https without having to set the envvar CONSUL_HTTP_SSL. --- builtin/providers/consul/config.go | 8 ++++++-- builtin/providers/consul/resource_provider.go | 5 +++++ builtin/providers/consul/resource_provider_test.go | 1 + website/source/docs/providers/consul/index.html.markdown | 3 ++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/builtin/providers/consul/config.go b/builtin/providers/consul/config.go index 6d2ae6f56f3f..7983018c6143 100644 --- a/builtin/providers/consul/config.go +++ b/builtin/providers/consul/config.go @@ -9,6 +9,7 @@ import ( type Config struct { Datacenter string `mapstructure:"datacenter"` Address string `mapstructure:"address"` + Scheme string `mapstructure:"scheme"` } // Client() returns a new client for accessing consul. @@ -21,10 +22,13 @@ func (c *Config) Client() (*consulapi.Client, error) { if c.Address != "" { config.Address = c.Address } + if c.Scheme != "" { + config.Scheme = c.Scheme + } client, err := consulapi.NewClient(config) - log.Printf("[INFO] Consul Client configured with address: '%s', datacenter: '%s'", - config.Address, config.Datacenter) + log.Printf("[INFO] Consul Client configured with address: '%s', scheme: '%s', datacenter: '%s'", + config.Address, config.Scheme, config.Datacenter) if err != nil { return nil, err } diff --git a/builtin/providers/consul/resource_provider.go b/builtin/providers/consul/resource_provider.go index 28cbb98235af..ec5cd43a5c93 100644 --- a/builtin/providers/consul/resource_provider.go +++ b/builtin/providers/consul/resource_provider.go @@ -21,6 +21,11 @@ func Provider() terraform.ResourceProvider { Type: schema.TypeString, Optional: true, }, + + "scheme": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + }, }, ResourcesMap: map[string]*schema.Resource{ diff --git a/builtin/providers/consul/resource_provider_test.go b/builtin/providers/consul/resource_provider_test.go index d78cb741e2e0..15ee38397363 100644 --- a/builtin/providers/consul/resource_provider_test.go +++ b/builtin/providers/consul/resource_provider_test.go @@ -42,6 +42,7 @@ func TestResourceProvider_Configure(t *testing.T) { raw := map[string]interface{}{ "address": "demo.consul.io:80", "datacenter": "nyc3", + "scheme": "https", } rawConfig, err := config.NewRawConfig(raw) diff --git a/website/source/docs/providers/consul/index.html.markdown b/website/source/docs/providers/consul/index.html.markdown index 7c0997294699..793b1fc303c9 100644 --- a/website/source/docs/providers/consul/index.html.markdown +++ b/website/source/docs/providers/consul/index.html.markdown @@ -43,6 +43,7 @@ resource "aws_instance" "app" { 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.