github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/docker/provider.go (about) 1 package docker 2 3 import ( 4 "fmt" 5 6 "github.com/hashicorp/terraform/helper/schema" 7 "github.com/hashicorp/terraform/terraform" 8 ) 9 10 func Provider() terraform.ResourceProvider { 11 return &schema.Provider{ 12 Schema: map[string]*schema.Schema{ 13 "host": &schema.Schema{ 14 Type: schema.TypeString, 15 Required: true, 16 DefaultFunc: schema.EnvDefaultFunc("DOCKER_HOST", "unix:///var/run/docker.sock"), 17 Description: "The Docker daemon address", 18 }, 19 20 "ca_material": &schema.Schema{ 21 Type: schema.TypeString, 22 Optional: true, 23 DefaultFunc: schema.EnvDefaultFunc("DOCKER_CA_MATERIAL", ""), 24 Description: "PEM-encoded content of Docker host CA certificate", 25 }, 26 "cert_material": &schema.Schema{ 27 Type: schema.TypeString, 28 Optional: true, 29 DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_MATERIAL", ""), 30 Description: "PEM-encoded content of Docker client certificate", 31 }, 32 "key_material": &schema.Schema{ 33 Type: schema.TypeString, 34 Optional: true, 35 DefaultFunc: schema.EnvDefaultFunc("DOCKER_KEY_MATERIAL", ""), 36 Description: "PEM-encoded content of Docker client private key", 37 }, 38 39 "cert_path": &schema.Schema{ 40 Type: schema.TypeString, 41 Optional: true, 42 DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_PATH", ""), 43 Description: "Path to directory with Docker TLS config", 44 }, 45 }, 46 47 ResourcesMap: map[string]*schema.Resource{ 48 "docker_container": resourceDockerContainer(), 49 "docker_image": resourceDockerImage(), 50 "docker_network": resourceDockerNetwork(), 51 "docker_volume": resourceDockerVolume(), 52 }, 53 54 DataSourcesMap: map[string]*schema.Resource{ 55 "docker_registry_image": dataSourceDockerRegistryImage(), 56 }, 57 58 ConfigureFunc: providerConfigure, 59 } 60 } 61 62 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 63 config := Config{ 64 Host: d.Get("host").(string), 65 Ca: d.Get("ca_material").(string), 66 Cert: d.Get("cert_material").(string), 67 Key: d.Get("key_material").(string), 68 CertPath: d.Get("cert_path").(string), 69 } 70 71 client, err := config.NewClient() 72 if err != nil { 73 return nil, fmt.Errorf("Error initializing Docker client: %s", err) 74 } 75 76 err = client.Ping() 77 if err != nil { 78 return nil, fmt.Errorf("Error pinging Docker server: %s", err) 79 } 80 81 return client, nil 82 }