github.com/chalford/terraform@v0.3.7-0.20150113080010-a78c69a8c81f/builtin/providers/cloudflare/provider.go (about)

     1  package cloudflare
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  // Provider returns a terraform.ResourceProvider.
    11  func Provider() terraform.ResourceProvider {
    12  	return &schema.Provider{
    13  		Schema: map[string]*schema.Schema{
    14  			"email": &schema.Schema{
    15  				Type:        schema.TypeString,
    16  				Required:    true,
    17  				DefaultFunc: envDefaultFunc("CLOUDFLARE_EMAIL"),
    18  				Description: "A registered CloudFlare email address.",
    19  			},
    20  
    21  			"token": &schema.Schema{
    22  				Type:        schema.TypeString,
    23  				Required:    true,
    24  				DefaultFunc: envDefaultFunc("CLOUDFLARE_TOKEN"),
    25  				Description: "The token key for API operations.",
    26  			},
    27  		},
    28  
    29  		ResourcesMap: map[string]*schema.Resource{
    30  			"cloudflare_record": resourceCloudFlareRecord(),
    31  		},
    32  
    33  		ConfigureFunc: providerConfigure,
    34  	}
    35  }
    36  
    37  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    38  	return func() (interface{}, error) {
    39  		if v := os.Getenv(k); v != "" {
    40  			return v, nil
    41  		}
    42  
    43  		return nil, nil
    44  	}
    45  }
    46  
    47  func providerConfigure(d *schema.ResourceData) (interface{}, error) {
    48  	config := Config{
    49  		Email: d.Get("email").(string),
    50  		Token: d.Get("token").(string),
    51  	}
    52  
    53  	return config.Client()
    54  }