github.com/turtlemonvh/terraform@v0.6.9-0.20151204001754-8e40b6b855e8/builtin/providers/dme/provider.go (about)

     1  package dme
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  // Provider provides a Provider...
    11  func Provider() terraform.ResourceProvider {
    12  	return &schema.Provider{
    13  		Schema: map[string]*schema.Schema{
    14  			"akey": &schema.Schema{
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: envDefaultFunc("DME_AKEY"),
    18  				Description: "A DNSMadeEasy API Key.",
    19  			},
    20  			"skey": &schema.Schema{
    21  				Type:        schema.TypeString,
    22  				Required:    true,
    23  				DefaultFunc: envDefaultFunc("DME_SKEY"),
    24  				Description: "The Secret Key for API operations.",
    25  			},
    26  			"usesandbox": &schema.Schema{
    27  				Type:        schema.TypeBool,
    28  				Required:    true,
    29  				DefaultFunc: envDefaultFunc("DME_USESANDBOX"),
    30  				Description: "If true, use the DME Sandbox.",
    31  			},
    32  		},
    33  
    34  		ResourcesMap: map[string]*schema.Resource{
    35  			"dme_record": resourceDMERecord(),
    36  		},
    37  
    38  		ConfigureFunc: providerConfigure,
    39  	}
    40  }
    41  
    42  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    43  	return func() (interface{}, error) {
    44  		if v := os.Getenv(k); v != "" {
    45  			if v == "true" {
    46  				return true, nil
    47  			} else if v == "false" {
    48  				return false, nil
    49  			}
    50  			return v, nil
    51  		}
    52  		return nil, nil
    53  	}
    54  }
    55  
    56  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    57  	config := Config{
    58  		AKey:       d.Get("akey").(string),
    59  		SKey:       d.Get("skey").(string),
    60  		UseSandbox: d.Get("usesandbox").(bool),
    61  	}
    62  	return config.Client()
    63  }