github.com/aspring/terraform@v0.8.2-0.20161216122603-6a8619a5db2e/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  				ConflictsWith: []string{"cert_path"},
    25  				Description:   "PEM-encoded content of Docker host CA certificate",
    26  			},
    27  			"cert_material": &schema.Schema{
    28  				Type:          schema.TypeString,
    29  				Optional:      true,
    30  				DefaultFunc:   schema.EnvDefaultFunc("DOCKER_CERT_MATERIAL", ""),
    31  				ConflictsWith: []string{"cert_path"},
    32  				Description:   "PEM-encoded content of Docker client certificate",
    33  			},
    34  			"key_material": &schema.Schema{
    35  				Type:          schema.TypeString,
    36  				Optional:      true,
    37  				DefaultFunc:   schema.EnvDefaultFunc("DOCKER_KEY_MATERIAL", ""),
    38  				ConflictsWith: []string{"cert_path"},
    39  				Description:   "PEM-encoded content of Docker client private key",
    40  			},
    41  
    42  			"cert_path": &schema.Schema{
    43  				Type:        schema.TypeString,
    44  				Optional:    true,
    45  				DefaultFunc: schema.EnvDefaultFunc("DOCKER_CERT_PATH", ""),
    46  				Description: "Path to directory with Docker TLS config",
    47  			},
    48  		},
    49  
    50  		ResourcesMap: map[string]*schema.Resource{
    51  			"docker_container": resourceDockerContainer(),
    52  			"docker_image":     resourceDockerImage(),
    53  			"docker_network":   resourceDockerNetwork(),
    54  			"docker_volume":    resourceDockerVolume(),
    55  		},
    56  
    57  		DataSourcesMap: map[string]*schema.Resource{
    58  			"docker_registry_image": dataSourceDockerRegistryImage(),
    59  		},
    60  
    61  		ConfigureFunc: providerConfigure,
    62  	}
    63  }
    64  
    65  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    66  	config := Config{
    67  		Host:     d.Get("host").(string),
    68  		Ca:       d.Get("ca_material").(string),
    69  		Cert:     d.Get("cert_material").(string),
    70  		Key:      d.Get("key_material").(string),
    71  		CertPath: d.Get("cert_path").(string),
    72  	}
    73  
    74  	client, err := config.NewClient()
    75  	if err != nil {
    76  		return nil, fmt.Errorf("Error initializing Docker client: %s", err)
    77  	}
    78  
    79  	err = client.Ping()
    80  	if err != nil {
    81  		return nil, fmt.Errorf("Error pinging Docker server: %s", err)
    82  	}
    83  
    84  	return client, nil
    85  }