2015-02-17 17:28:33 +01:00
|
|
|
package docker
|
|
|
|
|
|
|
|
import (
|
2015-03-29 04:06:48 +02:00
|
|
|
"fmt"
|
|
|
|
|
2015-02-17 17:28:33 +01:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2015-03-27 23:18:52 +01:00
|
|
|
"host": &schema.Schema{
|
2015-02-17 17:28:33 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
2016-02-10 20:21:17 +01:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"),
|
2015-03-27 23:18:52 +01:00
|
|
|
Description: "The Docker daemon address",
|
|
|
|
},
|
|
|
|
|
2016-11-22 13:18:09 +01:00
|
|
|
"ca_material": &schema.Schema{
|
2016-12-17 13:41:08 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_CA_MATERIAL", ""),
|
|
|
|
Description: "PEM-encoded content of Docker host CA certificate",
|
2016-11-22 13:18:09 +01:00
|
|
|
},
|
|
|
|
"cert_material": &schema.Schema{
|
2016-12-17 13:41:08 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_MATERIAL", ""),
|
|
|
|
Description: "PEM-encoded content of Docker client certificate",
|
2016-11-22 13:18:09 +01:00
|
|
|
},
|
|
|
|
"key_material": &schema.Schema{
|
2016-12-17 13:41:08 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_KEY_MATERIAL", ""),
|
|
|
|
Description: "PEM-encoded content of Docker client private key",
|
2016-11-22 13:18:09 +01:00
|
|
|
},
|
|
|
|
|
2015-03-27 23:18:52 +01:00
|
|
|
"cert_path": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Optional: true,
|
2015-04-09 18:49:03 +02:00
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_PATH", ""),
|
2015-03-27 23:18:52 +01:00
|
|
|
Description: "Path to directory with Docker TLS config",
|
2015-02-17 17:28:33 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
|
|
"docker_container": resourceDockerContainer(),
|
|
|
|
"docker_image": resourceDockerImage(),
|
2016-01-02 12:20:55 +01:00
|
|
|
"docker_network": resourceDockerNetwork(),
|
2016-01-15 18:33:17 +01:00
|
|
|
"docker_volume": resourceDockerVolume(),
|
2015-02-17 17:28:33 +01:00
|
|
|
},
|
|
|
|
|
2016-07-26 17:18:38 +02:00
|
|
|
DataSourcesMap: map[string]*schema.Resource{
|
|
|
|
"docker_registry_image": dataSourceDockerRegistryImage(),
|
|
|
|
},
|
|
|
|
|
2015-02-17 17:28:33 +01:00
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
2015-03-27 23:18:52 +01:00
|
|
|
Host: d.Get("host").(string),
|
2016-11-22 13:18:09 +01:00
|
|
|
Ca: d.Get("ca_material").(string),
|
|
|
|
Cert: d.Get("cert_material").(string),
|
|
|
|
Key: d.Get("key_material").(string),
|
2015-03-27 23:18:52 +01:00
|
|
|
CertPath: d.Get("cert_path").(string),
|
2015-02-17 17:28:33 +01:00
|
|
|
}
|
|
|
|
|
2015-03-29 04:06:48 +02:00
|
|
|
client, err := config.NewClient()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error initializing Docker client: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
err = client.Ping()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("Error pinging Docker server: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return client, nil
|
2015-02-17 17:28:33 +01:00
|
|
|
}
|