github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/spotinst/provider.go (about) 1 package spotinst 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 "email": &schema.Schema{ 13 Type: schema.TypeString, 14 Optional: true, 15 DefaultFunc: schema.EnvDefaultFunc("SPOTINST_EMAIL", ""), 16 Description: "Spotinst Email", 17 }, 18 19 "password": &schema.Schema{ 20 Type: schema.TypeString, 21 Optional: true, 22 DefaultFunc: schema.EnvDefaultFunc("SPOTINST_PASSWORD", ""), 23 Description: "Spotinst Password", 24 }, 25 26 "client_id": &schema.Schema{ 27 Type: schema.TypeString, 28 Optional: true, 29 DefaultFunc: schema.EnvDefaultFunc("SPOTINST_CLIENT_ID", ""), 30 Description: "Spotinst OAuth Client ID", 31 }, 32 33 "client_secret": &schema.Schema{ 34 Type: schema.TypeString, 35 Optional: true, 36 DefaultFunc: schema.EnvDefaultFunc("SPOTINST_CLIENT_SECRET", ""), 37 Description: "Spotinst OAuth Client Secret", 38 }, 39 40 "token": &schema.Schema{ 41 Type: schema.TypeString, 42 Optional: true, 43 DefaultFunc: schema.EnvDefaultFunc("SPOTINST_TOKEN", ""), 44 Description: "Spotinst Personal API Access Token", 45 }, 46 }, 47 48 ResourcesMap: map[string]*schema.Resource{ 49 "spotinst_aws_group": resourceSpotinstAwsGroup(), 50 "spotinst_subscription": resourceSpotinstSubscription(), 51 "spotinst_healthcheck": resourceSpotinstHealthCheck(), 52 }, 53 54 ConfigureFunc: providerConfigure, 55 } 56 } 57 58 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 59 config := Config{ 60 Email: d.Get("email").(string), 61 Password: d.Get("password").(string), 62 ClientID: d.Get("client_id").(string), 63 ClientSecret: d.Get("client_secret").(string), 64 Token: d.Get("token").(string), 65 } 66 if err := config.Validate(); err != nil { 67 return nil, err 68 } 69 return config.Client() 70 }