github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/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:/run/docker.sock"),
    17  				Description: "The Docker daemon address",
    18  			},
    19  
    20  			"cert_path": &schema.Schema{
    21  				Type:        schema.TypeString,
    22  				Optional:    true,
    23  				DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_PATH", ""),
    24  				Description: "Path to directory with Docker TLS config",
    25  			},
    26  		},
    27  
    28  		ResourcesMap: map[string]*schema.Resource{
    29  			"docker_container": resourceDockerContainer(),
    30  			"docker_image":     resourceDockerImage(),
    31  		},
    32  
    33  		ConfigureFunc: providerConfigure,
    34  	}
    35  }
    36  
    37  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    38  	config := Config{
    39  		Host:     d.Get("host").(string),
    40  		CertPath: d.Get("cert_path").(string),
    41  	}
    42  
    43  	client, err := config.NewClient()
    44  	if err != nil {
    45  		return nil, fmt.Errorf("Error initializing Docker client: %s", err)
    46  	}
    47  
    48  	err = client.Ping()
    49  	if err != nil {
    50  		return nil, fmt.Errorf("Error pinging Docker server: %s", err)
    51  	}
    52  
    53  	return client, nil
    54  }