route/cmd/terraform-provider-route/main.go

55 lines
1.2 KiB
Go
Raw Normal View History

2017-12-02 23:34:35 +00:00
package main
import (
"log"
2018-01-21 16:35:41 +00:00
"net/http"
2017-12-02 23:34:35 +00:00
2018-01-21 16:35:41 +00:00
"git.xeserv.us/xena/route/proto/route"
2017-12-02 23:34:35 +00:00
"github.com/hashicorp/terraform/helper/schema"
"github.com/hashicorp/terraform/plugin"
"github.com/hashicorp/terraform/terraform"
)
func main() {
plugin.Serve(&plugin.ServeOpts{
ProviderFunc: provider,
})
}
// provider returns a terraform.ResourceProvider.
func provider() terraform.ResourceProvider {
return &schema.Provider{
Schema: map[string]*schema.Schema{
"token": &schema.Schema{
Type: schema.TypeString,
2017-12-03 01:13:52 +00:00
Optional: true,
2017-12-02 23:34:35 +00:00
DefaultFunc: schema.EnvDefaultFunc("ROUTE_TOKEN", nil),
},
"host": &schema.Schema{
Type: schema.TypeString,
Optional: false,
2017-12-03 02:00:32 +00:00
Required: true,
2017-12-02 23:34:35 +00:00
DefaultFunc: schema.EnvDefaultFunc("ROUTE_HOST", nil),
},
},
ResourcesMap: map[string]*schema.Resource{
"route_route": routeResource(),
"route_token": tokenResource(),
2017-12-02 23:34:35 +00:00
},
ConfigureFunc: providerConfigure,
}
}
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
token := d.Get("token").(string)
host := d.Get("host").(string)
log.Printf("[INFO] Initializing route client connecting to %s", host)
2018-01-21 16:35:41 +00:00
cl := route.New(host, token, &http.Client{})
2017-12-02 23:34:35 +00:00
2018-01-21 16:35:41 +00:00
return cl, nil
2017-12-02 23:34:35 +00:00
}