Starting point for adding Organization app support for Heroku Provider

This commit is contained in:
Clint Shryock 2014-10-10 11:54:33 -05:00
parent b43ca0aa52
commit 95a815deda
1 changed files with 59 additions and 1 deletions

View File

@ -42,7 +42,7 @@ func (a *application) Update() error {
func resourceHerokuApp() *schema.Resource { func resourceHerokuApp() *schema.Resource {
return &schema.Resource{ return &schema.Resource{
Create: resourceHerokuAppCreate, Create: switchHerokuAppCreate,
Read: resourceHerokuAppRead, Read: resourceHerokuAppRead,
Update: resourceHerokuAppUpdate, Update: resourceHerokuAppUpdate,
Delete: resourceHerokuAppDelete, Delete: resourceHerokuAppDelete,
@ -93,10 +93,24 @@ func resourceHerokuApp() *schema.Resource {
Type: schema.TypeString, Type: schema.TypeString,
Computed: true, Computed: true,
}, },
"organization": &schema.Schema{
Type: schema.TypeString,
Optional: true,
},
}, },
} }
} }
func switchHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
isOrg := d.Get("organization")
if len(isOrg.(string)) != 0 {
return resourceHerokuOrgAppCreate(d, meta)
} else {
return resourceHerokuAppCreate(d, meta)
}
}
func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error { func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service) client := meta.(*heroku.Service)
@ -138,6 +152,50 @@ func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
return resourceHerokuAppRead(d, meta) return resourceHerokuAppRead(d, meta)
} }
func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service)
// Build up our creation options
opts := heroku.OrganizationAppCreateOpts{}
if v := d.Get("organization"); v != nil {
vs := v.(string)
log.Printf("[DEBUG] App name: %s", vs)
opts.Organization = &vs
}
if v := d.Get("name"); v != nil {
vs := v.(string)
log.Printf("[DEBUG] App name: %s", vs)
opts.Name = &vs
}
if v := d.Get("region"); v != nil {
vs := v.(string)
log.Printf("[DEBUG] App region: %s", vs)
opts.Region = &vs
}
if v := d.Get("stack"); v != nil {
vs := v.(string)
log.Printf("[DEBUG] App stack: %s", vs)
opts.Stack = &vs
}
log.Printf("[DEBUG] Creating Heroku app...")
a, err := client.OrganizationAppCreate(opts)
if err != nil {
return err
}
d.SetId(a.Name)
log.Printf("[INFO] App ID: %s", d.Id())
if v := d.Get("config_vars"); v != nil {
err = update_config_vars(d.Id(), client, nil, v.([]interface{}))
if err != nil {
return err
}
}
return resourceHerokuAppRead(d, meta)
}
func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error { func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*heroku.Service) client := meta.(*heroku.Service)
app, err := resource_heroku_app_retrieve(d.Id(), client) app, err := resource_heroku_app_retrieve(d.Id(), client)