From cc79025a2efc3183c62a4df1ba9ba1f2cf1ae8b6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Fri, 27 Mar 2015 15:18:52 -0700 Subject: [PATCH] providers/docker: support DOCKER_CERT_PATH --- config.go | 22 ++++++++++++++++++---- provider.go | 14 +++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 40355b24..ed13314a 100644 --- a/config.go +++ b/config.go @@ -1,10 +1,15 @@ package docker -import dc "github.com/fsouza/go-dockerclient" +import ( + "path/filepath" + + dc "github.com/fsouza/go-dockerclient" +) type Config struct { - DockerHost string - SkipPull bool + Host string + CertPath string + SkipPull bool } type Data struct { @@ -13,7 +18,16 @@ type Data struct { // NewClient() returns a new Docker client. func (c *Config) NewClient() (*dc.Client, error) { - return dc.NewClient(c.DockerHost) + // If there is no cert information, then just return the direct client + if c.CertPath == "" { + return dc.NewClient(c.Host) + } + + // If there is cert information, load it and use it. + ca := filepath.Join(c.CertPath, "ca.pem") + cert := filepath.Join(c.CertPath, "cert.pem") + key := filepath.Join(c.CertPath, "key.pem") + return dc.NewTLSClient(c.Host, cert, key, ca) } // NewData() returns a new data struct. diff --git a/provider.go b/provider.go index d01ec385..77da4bf1 100644 --- a/provider.go +++ b/provider.go @@ -8,11 +8,18 @@ import ( func Provider() terraform.ResourceProvider { return &schema.Provider{ Schema: map[string]*schema.Schema{ - "docker_host": &schema.Schema{ + "host": &schema.Schema{ Type: schema.TypeString, Required: true, DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:/run/docker.sock"), - Description: "The Docker daemon endpoint", + Description: "The Docker daemon address", + }, + + "cert_path": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_PATH", nil), + Description: "Path to directory with Docker TLS config", }, }, @@ -27,7 +34,8 @@ func Provider() terraform.ResourceProvider { func providerConfigure(d *schema.ResourceData) (interface{}, error) { config := Config{ - DockerHost: d.Get("docker_host").(string), + Host: d.Get("host").(string), + CertPath: d.Get("cert_path").(string), } return &config, nil