github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/datadog/provider.go (about) 1 package datadog 2 3 import ( 4 "log" 5 6 "errors" 7 8 "github.com/hashicorp/terraform/helper/schema" 9 "github.com/hashicorp/terraform/terraform" 10 ) 11 12 func Provider() terraform.ResourceProvider { 13 return &schema.Provider{ 14 Schema: map[string]*schema.Schema{ 15 "api_key": &schema.Schema{ 16 Type: schema.TypeString, 17 Required: true, 18 DefaultFunc: schema.EnvDefaultFunc("DATADOG_API_KEY", nil), 19 }, 20 "app_key": &schema.Schema{ 21 Type: schema.TypeString, 22 Required: true, 23 DefaultFunc: schema.EnvDefaultFunc("DATADOG_APP_KEY", nil), 24 }, 25 }, 26 27 ResourcesMap: map[string]*schema.Resource{ 28 "datadog_downtime": resourceDatadogDowntime(), 29 "datadog_monitor": resourceDatadogMonitor(), 30 "datadog_timeboard": resourceDatadogTimeboard(), 31 "datadog_user": resourceDatadogUser(), 32 }, 33 34 ConfigureFunc: providerConfigure, 35 } 36 } 37 38 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 39 40 config := Config{ 41 APIKey: d.Get("api_key").(string), 42 APPKey: d.Get("app_key").(string), 43 } 44 45 log.Println("[INFO] Initializing Datadog client") 46 client := config.Client() 47 48 ok, err := client.Validate() 49 50 if err != nil { 51 return client, err 52 } 53 54 if ok == false { 55 return client, errors.New(`No valid credential sources found for Datadog Provider. Please see https://terraform.io/docs/providers/datadog/index.html for more information on providing credentials for the Datadog Provider`) 56 } 57 58 return client, nil 59 }