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,
|
|
|
|
DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:/run/docker.sock"),
|
2015-03-27 23:18:52 +01:00
|
|
|
Description: "The Docker daemon address",
|
|
|
|
},
|
|
|
|
|
|
|
|
"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
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
2015-03-27 23:18:52 +01:00
|
|
|
Host: d.Get("host").(string),
|
|
|
|
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
|
|
|
}
|