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