github.com/peterbale/terraform@v0.9.0-beta2.0.20170315142748-5723acd55547/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_agent_self": dataSourceConsulAgentSelf(), 68 "consul_catalog_nodes": dataSourceConsulCatalogNodes(), 69 "consul_catalog_service": dataSourceConsulCatalogService(), 70 "consul_catalog_services": dataSourceConsulCatalogServices(), 71 "consul_keys": dataSourceConsulKeys(), 72 }, 73 74 ResourcesMap: map[string]*schema.Resource{ 75 "consul_agent_service": resourceConsulAgentService(), 76 "consul_catalog_entry": resourceConsulCatalogEntry(), 77 "consul_keys": resourceConsulKeys(), 78 "consul_key_prefix": resourceConsulKeyPrefix(), 79 "consul_node": resourceConsulNode(), 80 "consul_prepared_query": resourceConsulPreparedQuery(), 81 "consul_service": resourceConsulService(), 82 }, 83 84 ConfigureFunc: providerConfigure, 85 } 86 } 87 88 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 89 var config Config 90 configRaw := d.Get("").(map[string]interface{}) 91 if err := mapstructure.Decode(configRaw, &config); err != nil { 92 return nil, err 93 } 94 log.Printf("[INFO] Initializing Consul client") 95 return config.Client() 96 }