2015-12-06 19:20:43 +01:00
|
|
|
package powerdns
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Provider() terraform.ResourceProvider {
|
|
|
|
return &schema.Provider{
|
|
|
|
Schema: map[string]*schema.Schema{
|
2016-01-25 19:50:58 +01:00
|
|
|
"api_key": {
|
2015-12-06 19:20:43 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("PDNS_API_KEY"),
|
|
|
|
Description: "REST API authentication key",
|
|
|
|
},
|
2016-01-25 19:50:58 +01:00
|
|
|
"server_url": {
|
2015-12-06 19:20:43 +01:00
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
DefaultFunc: envDefaultFunc("PDNS_SERVER_URL"),
|
|
|
|
Description: "Location of PowerDNS server",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
ResourcesMap: map[string]*schema.Resource{
|
|
|
|
"powerdns_record": resourcePDNSRecord(),
|
|
|
|
},
|
|
|
|
|
|
|
|
ConfigureFunc: providerConfigure,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func providerConfigure(data *schema.ResourceData) (interface{}, error) {
|
|
|
|
config := Config{
|
2016-01-25 19:50:58 +01:00
|
|
|
ApiKey: data.Get("api_key").(string),
|
2015-12-06 19:20:43 +01:00
|
|
|
ServerUrl: data.Get("server_url").(string),
|
|
|
|
}
|
|
|
|
|
|
|
|
return config.Client()
|
|
|
|
}
|
|
|
|
|
|
|
|
func envDefaultFunc(k string) schema.SchemaDefaultFunc {
|
|
|
|
return func() (interface{}, error) {
|
|
|
|
if v := os.Getenv(k); v != "" {
|
|
|
|
return v, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|