github.com/daveadams/terraform@v0.6.4-0.20160830094355-13ce74975936/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  				}, nil),
    27  			},
    28  
    29  			"scheme": &schema.Schema{
    30  				Type:        schema.TypeString,
    31  				Optional:    true,
    32  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_SCHEME", nil),
    33  			},
    34  
    35  			"ca_file": &schema.Schema{
    36  				Type:        schema.TypeString,
    37  				Optional:    true,
    38  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_CA_FILE", nil),
    39  			},
    40  
    41  			"cert_file": &schema.Schema{
    42  				Type:        schema.TypeString,
    43  				Optional:    true,
    44  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_CERT_FILE", nil),
    45  			},
    46  
    47  			"key_file": &schema.Schema{
    48  				Type:        schema.TypeString,
    49  				Optional:    true,
    50  				DefaultFunc: schema.EnvDefaultFunc("CONSUL_KEY_FILE", nil),
    51  			},
    52  
    53  			"token": &schema.Schema{
    54  				Type:     schema.TypeString,
    55  				Optional: true,
    56  			},
    57  		},
    58  
    59  		DataSourcesMap: map[string]*schema.Resource{
    60  			"consul_keys": dataSourceConsulKeys(),
    61  		},
    62  
    63  		ResourcesMap: map[string]*schema.Resource{
    64  			"consul_agent_service":  resourceConsulAgentService(),
    65  			"consul_catalog_entry":  resourceConsulCatalogEntry(),
    66  			"consul_keys":           resourceConsulKeys(),
    67  			"consul_key_prefix":     resourceConsulKeyPrefix(),
    68  			"consul_node":           resourceConsulNode(),
    69  			"consul_prepared_query": resourceConsulPreparedQuery(),
    70  			"consul_service":        resourceConsulService(),
    71  		},
    72  
    73  		ConfigureFunc: providerConfigure,
    74  	}
    75  }
    76  
    77  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    78  	var config Config
    79  	configRaw := d.Get("").(map[string]interface{})
    80  	if err := mapstructure.Decode(configRaw, &config); err != nil {
    81  		return nil, err
    82  	}
    83  	log.Printf("[INFO] Initializing Consul client")
    84  	return config.Client()
    85  }