github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/datadog/provider.go (about)

     1  package datadog
     2  
     3  import (
     4  	"log"
     5  
     6  	"errors"
     7  	"github.com/hashicorp/terraform/helper/schema"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  func Provider() terraform.ResourceProvider {
    12  	return &schema.Provider{
    13  		Schema: map[string]*schema.Schema{
    14  			"api_key": &schema.Schema{
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: schema.EnvDefaultFunc("DATADOG_API_KEY", nil),
    18  			},
    19  			"app_key": &schema.Schema{
    20  				Type:        schema.TypeString,
    21  				Required:    true,
    22  				DefaultFunc: schema.EnvDefaultFunc("DATADOG_APP_KEY", nil),
    23  			},
    24  		},
    25  
    26  		ResourcesMap: map[string]*schema.Resource{
    27  			"datadog_monitor":   resourceDatadogMonitor(),
    28  			"datadog_timeboard": resourceDatadogTimeboard(),
    29  		},
    30  
    31  		ConfigureFunc: providerConfigure,
    32  	}
    33  }
    34  
    35  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    36  
    37  	config := Config{
    38  		APIKey: d.Get("api_key").(string),
    39  		APPKey: d.Get("app_key").(string),
    40  	}
    41  
    42  	log.Println("[INFO] Initializing Datadog client")
    43  	client := config.Client()
    44  
    45  	ok, err := client.Validate()
    46  
    47  	if err != nil {
    48  		return client, err
    49  	}
    50  
    51  	if ok == false {
    52  		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`)
    53  	}
    54  
    55  	return client, nil
    56  }