github.com/erriapo/terraform@v0.6.12-0.20160203182612-0340ea72354f/builtin/providers/powerdns/provider.go (about)

     1  package powerdns
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/hashicorp/terraform/helper/schema"
     7  	"github.com/hashicorp/terraform/terraform"
     8  )
     9  
    10  func Provider() terraform.ResourceProvider {
    11  	return &schema.Provider{
    12  		Schema: map[string]*schema.Schema{
    13  			"api_key": {
    14  				Type:        schema.TypeString,
    15  				Required:    true,
    16  				DefaultFunc: envDefaultFunc("PDNS_API_KEY"),
    17  				Description: "REST API authentication key",
    18  			},
    19  			"server_url": {
    20  				Type:        schema.TypeString,
    21  				Required:    true,
    22  				DefaultFunc: envDefaultFunc("PDNS_SERVER_URL"),
    23  				Description: "Location of PowerDNS server",
    24  			},
    25  		},
    26  
    27  		ResourcesMap: map[string]*schema.Resource{
    28  			"powerdns_record": resourcePDNSRecord(),
    29  		},
    30  
    31  		ConfigureFunc: providerConfigure,
    32  	}
    33  }
    34  
    35  func providerConfigure(data *schema.ResourceData) (interface{}, error) {
    36  	config := Config{
    37  		ApiKey:    data.Get("api_key").(string),
    38  		ServerUrl: data.Get("server_url").(string),
    39  	}
    40  
    41  	return config.Client()
    42  }
    43  
    44  func envDefaultFunc(k string) schema.SchemaDefaultFunc {
    45  	return func() (interface{}, error) {
    46  		if v := os.Getenv(k); v != "" {
    47  			return v, nil
    48  		}
    49  
    50  		return nil, nil
    51  	}
    52  }