github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/rancher/provider.go (about) 1 package rancher 2 3 import ( 4 "github.com/hashicorp/terraform/helper/schema" 5 "github.com/hashicorp/terraform/terraform" 6 ) 7 8 // Provider returns a terraform.ResourceProvider. 9 func Provider() terraform.ResourceProvider { 10 return &schema.Provider{ 11 Schema: map[string]*schema.Schema{ 12 "api_url": &schema.Schema{ 13 Type: schema.TypeString, 14 Required: true, 15 DefaultFunc: schema.EnvDefaultFunc("RANCHER_URL", nil), 16 Description: descriptions["api_url"], 17 }, 18 "access_key": &schema.Schema{ 19 Type: schema.TypeString, 20 Optional: true, 21 DefaultFunc: schema.EnvDefaultFunc("RANCHER_ACCESS_KEY", ""), 22 Description: descriptions["access_key"], 23 }, 24 "secret_key": &schema.Schema{ 25 Type: schema.TypeString, 26 Optional: true, 27 DefaultFunc: schema.EnvDefaultFunc("RANCHER_SECRET_KEY", ""), 28 Description: descriptions["secret_key"], 29 }, 30 }, 31 32 ResourcesMap: map[string]*schema.Resource{ 33 "rancher_environment": resourceRancherEnvironment(), 34 "rancher_registration_token": resourceRancherRegistrationToken(), 35 "rancher_registry": resourceRancherRegistry(), 36 "rancher_registry_credential": resourceRancherRegistryCredential(), 37 "rancher_stack": resourceRancherStack(), 38 }, 39 40 ConfigureFunc: providerConfigure, 41 } 42 } 43 44 var descriptions map[string]string 45 46 func init() { 47 descriptions = map[string]string{ 48 "access_key": "API Key used to authenticate with the rancher server", 49 50 "secret_key": "API secret used to authenticate with the rancher server", 51 52 "api_url": "The URL to the rancher API", 53 } 54 } 55 56 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 57 config := &Config{ 58 APIURL: d.Get("api_url").(string) + "/v1", 59 AccessKey: d.Get("access_key").(string), 60 SecretKey: d.Get("secret_key").(string), 61 } 62 63 err := config.CreateClient() 64 65 return config, err 66 }