Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic auth to consul provider #12679

Merged
merged 1 commit into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions builtin/providers/consul/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package consul
import (
"log"
"net/http"
"strings"

consulapi "github.com/hashicorp/consul/api"
)
Expand All @@ -11,6 +12,7 @@ type Config struct {
Datacenter string `mapstructure:"datacenter"`
Address string `mapstructure:"address"`
Scheme string `mapstructure:"scheme"`
HttpAuth string `mapstructure:"http_auth"`
Token string `mapstructure:"token"`
CAFile string `mapstructure:"ca_file"`
CertFile string `mapstructure:"cert_file"`
Expand Down Expand Up @@ -41,6 +43,18 @@ func (c *Config) Client() (*consulapi.Client, error) {
}
config.HttpClient.Transport.(*http.Transport).TLSClientConfig = cc

if c.HttpAuth != "" {
var username, password string
if strings.Contains(c.HttpAuth, ":") {
split := strings.SplitN(c.HttpAuth, ":", 2)
username = split[0]
password = split[1]
} else {
username = c.HttpAuth
}
config.HttpAuth = &consulapi.HttpBasicAuth{username, password}
}

if c.Token != "" {
config.Token = c.Token
}
Expand Down
6 changes: 6 additions & 0 deletions builtin/providers/consul/resource_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ func Provider() terraform.ResourceProvider {
}, "http"),
},

"http_auth": &schema.Schema{
Type: schema.TypeString,
Optional: true,
DefaultFunc: schema.EnvDefaultFunc("CONSUL_HTTP_AUTH", ""),
},

"ca_file": &schema.Schema{
Type: schema.TypeString,
Optional: true,
Expand Down
1 change: 1 addition & 0 deletions website/source/docs/providers/consul/index.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following arguments are supported:

* `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".
* `http_auth` - (Optional) HTTP Basic Authentication credentials to be used when communicating with Consul, in the format of either `user` or `user:pass`. This may also be specified using the `CONSUL_HTTP_AUTH` environment variable.
* `datacenter` - (Optional) The datacenter to use. Defaults to that of the agent.
* `token` - (Optional) The ACL token to use by default when making requests to the agent.
* `ca_file` - (Optional) A path to a PEM-encoded certificate authority used to verify the remote agent's certificate.
Expand Down