github.com/minamijoyo/terraform@v0.7.8-0.20161029001309-18b3736ba44b/builtin/providers/consul/resource_provider.go (about)

     1  package consul
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  	"github.com/mitchellh/mapstructure"
     9  )
    10  
    11  // Provider returns a terraform.ResourceProvider.
    12  func Provider() terraform.ResourceProvider {
    13  	return &schema.Provider{
    14  		Schema: map[string]*schema.Schema{
    15  			"datacenter": &schema.Schema{
    16  				Type:     schema.TypeString,
    17  				Optional: true,
    18  			},
    19  
    20  			"address": &schema.Schema{
    21  				Type:     schema.TypeString,
    22  				Optional: true,
    23  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    24  					"CONSUL_ADDRESS",
    25  					"CONSUL_HTTP_ADDR",
    26  				}, "localhost:8500"),
    27  			},
    28  
    29  			"scheme": &schema.Schema{
    30  				Type:     schema.TypeString,
    31  				Optional: true,
    32  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    33  					"CONSUL_SCHEME",
    34  					"CONSUL_HTTP_SCHEME",
    35  				}, "http"),
    36  			},
    37  
    38  			"ca_file": &schema.Schema{
    39  				Type:        schema.TypeString,
    40  				Optional:    true,
    41  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_CA_FILE", ""),
    42  			},
    43  
    44  			"cert_file": &schema.Schema{
    45  				Type:        schema.TypeString,
    46  				Optional:    true,
    47  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_CERT_FILE", ""),
    48  			},
    49  
    50  			"key_file": &schema.Schema{
    51  				Type:        schema.TypeString,
    52  				Optional:    true,
    53  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_KEY_FILE", ""),
    54  			},
    55  
    56  			"token": &schema.Schema{
    57  				Type:     schema.TypeString,
    58  				Optional: true,
    59  				DefaultFunc: schema.MultiEnvDefaultFunc([]string{
    60  					"CONSUL_TOKEN",
    61  					"CONSUL_HTTP_TOKEN",
    62  				}, ""),
    63  			},
    64  		},
    65  
    66  		DataSourcesMap: map[string]*schema.Resource{
    67  			"consul_keys": dataSourceConsulKeys(),
    68  		},
    69  
    70  		ResourcesMap: map[string]*schema.Resource{
    71  			"consul_agent_service":  resourceConsulAgentService(),
    72  			"consul_catalog_entry":  resourceConsulCatalogEntry(),
    73  			"consul_keys":           resourceConsulKeys(),
    74  			"consul_key_prefix":     resourceConsulKeyPrefix(),
    75  			"consul_node":           resourceConsulNode(),
    76  			"consul_prepared_query": resourceConsulPreparedQuery(),
    77  			"consul_service":        resourceConsulService(),
    78  		},
    79  
    80  		ConfigureFunc: providerConfigure,
    81  	}
    82  }
    83  
    84  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    85  	var config Config
    86  	configRaw := d.Get("").(map[string]interface{})
    87  	if err := mapstructure.Decode(configRaw, &config); err != nil {
    88  		return nil, err
    89  	}
    90  	log.Printf("[INFO] Initializing Consul client")
    91  	return config.Client()
    92  }