github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/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_monitor": resourceDatadogMonitor(), 29 "datadog_timeboard": resourceDatadogTimeboard(), 30 "datadog_user": resourceDatadogUser(), 31 }, 32 33 ConfigureFunc: providerConfigure, 34 } 35 } 36 37 func providerConfigure(d *schema.ResourceData) (interface{}, error) { 38 39 config := Config{ 40 APIKey: d.Get("api_key").(string), 41 APPKey: d.Get("app_key").(string), 42 } 43 44 log.Println("[INFO] Initializing Datadog client") 45 client := config.Client() 46 47 ok, err := client.Validate() 48 49 if err != nil { 50 return client, err 51 } 52 53 if ok == false { 54 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`) 55 } 56 57 return client, nil 58 }