github.com/kwoods/terraform@v0.6.11-0.20160809170336-13497db7138e/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  			},
    24  
    25  			"scheme": &schema.Schema{
    26  				Type:     schema.TypeString,
    27  				Optional: true,
    28  			},
    29  
    30  			"token": &schema.Schema{
    31  				Type:     schema.TypeString,
    32  				Optional: true,
    33  			},
    34  		},
    35  
    36  		DataSourcesMap: map[string]*schema.Resource{
    37  			"consul_keys": dataSourceConsulKeys(),
    38  		},
    39  
    40  		ResourcesMap: map[string]*schema.Resource{
    41  			"consul_agent_service": resourceConsulAgentService(),
    42  			"consul_catalog_entry": resourceConsulCatalogEntry(),
    43  			"consul_keys":          resourceConsulKeys(),
    44  			"consul_key_prefix":    resourceConsulKeyPrefix(),
    45  			"consul_node":          resourceConsulNode(),
    46  			"consul_service":       resourceConsulService(),
    47  		},
    48  
    49  		ConfigureFunc: providerConfigure,
    50  	}
    51  }
    52  
    53  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    54  	var config Config
    55  	configRaw := d.Get("").(map[string]interface{})
    56  	if err := mapstructure.Decode(configRaw, &config); err != nil {
    57  		return nil, err
    58  	}
    59  	log.Printf("[INFO] Initializing Consul client")
    60  	return config.Client()
    61  }