2014-08-19 18:18:45 +02:00
|
|
|
package heroku
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"log"
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
"github.com/cyberdelia/heroku-go/v3"
|
2014-08-19 18:18:45 +02:00
|
|
|
"github.com/hashicorp/terraform/helper/schema"
|
|
|
|
)
|
|
|
|
|
|
|
|
func resourceHerokuDrain() *schema.Resource {
|
|
|
|
return &schema.Resource{
|
|
|
|
Create: resourceHerokuDrainCreate,
|
|
|
|
Read: resourceHerokuDrainRead,
|
|
|
|
Delete: resourceHerokuDrainDelete,
|
|
|
|
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
|
|
"url": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"app": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Required: true,
|
|
|
|
ForceNew: true,
|
|
|
|
},
|
|
|
|
|
|
|
|
"token": &schema.Schema{
|
|
|
|
Type: schema.TypeString,
|
|
|
|
Computed: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceHerokuDrainCreate(d *schema.ResourceData, meta interface{}) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := meta.(*heroku.Service)
|
2014-08-19 18:18:45 +02:00
|
|
|
|
|
|
|
app := d.Get("app").(string)
|
|
|
|
url := d.Get("url").(string)
|
|
|
|
|
|
|
|
log.Printf("[DEBUG] Drain create configuration: %#v, %#v", app, url)
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
dr, err := client.LogDrainCreate(app, heroku.LogDrainCreateOpts{url})
|
2014-08-19 18:18:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2014-08-27 16:50:37 +02:00
|
|
|
d.SetId(dr.ID)
|
2014-08-19 18:18:45 +02:00
|
|
|
d.Set("url", dr.URL)
|
|
|
|
d.Set("token", dr.Token)
|
|
|
|
|
|
|
|
log.Printf("[INFO] Drain ID: %s", d.Id())
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceHerokuDrainDelete(d *schema.ResourceData, meta interface{}) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := meta.(*heroku.Service)
|
2014-08-19 18:18:45 +02:00
|
|
|
|
|
|
|
log.Printf("[INFO] Deleting drain: %s", d.Id())
|
|
|
|
|
|
|
|
// Destroy the drain
|
|
|
|
err := client.LogDrainDelete(d.Get("app").(string), d.Id())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error deleting drain: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func resourceHerokuDrainRead(d *schema.ResourceData, meta interface{}) error {
|
2014-08-27 16:50:37 +02:00
|
|
|
client := meta.(*heroku.Service)
|
2014-08-19 18:18:45 +02:00
|
|
|
|
|
|
|
dr, err := client.LogDrainInfo(d.Get("app").(string), d.Id())
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("Error retrieving drain: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
d.Set("url", dr.URL)
|
|
|
|
d.Set("token", dr.Token)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|