github.com/rjeczalik/terraform@v0.6.7-0.20160812060014-e251d5c7bd39/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_service":       resourceConsulService(),
    70  		},
    71  
    72  		ConfigureFunc: providerConfigure,
    73  	}
    74  }
    75  
    76  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    77  	var config Config
    78  	configRaw := d.Get("").(map[string]interface{})
    79  	if err := mapstructure.Decode(configRaw, &config); err != nil {
    80  		return nil, err
    81  	}
    82  	log.Printf("[INFO] Initializing Consul client")
    83  	return config.Client()
    84  }