github.com/mohanarpit/terraform@v0.6.16-0.20160909104007-291f29853544/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  			"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  			"docker_network":   resourceDockerNetwork(),
    32  			"docker_volume":    resourceDockerVolume(),
    33  		},
    34  
    35  		DataSourcesMap: map[string]*schema.Resource{
    36  			"docker_registry_image": dataSourceDockerRegistryImage(),
    37  		},
    38  
    39  		ConfigureFunc: providerConfigure,
    40  	}
    41  }
    42  
    43  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    44  	config := Config{
    45  		Host:     d.Get("host").(string),
    46  		CertPath: d.Get("cert_path").(string),
    47  	}
    48  
    49  	client, err := config.NewClient()
    50  	if err != nil {
    51  		return nil, fmt.Errorf("Error initializing Docker client: %s", err)
    52  	}
    53  
    54  	err = client.Ping()
    55  	if err != nil {
    56  		return nil, fmt.Errorf("Error pinging Docker server: %s", err)
    57  	}
    58  
    59  	return client, nil
    60  }