providers/heroku: use a helper for common app post-create tasks (#13990)

Buildpacks were being configured post-create for non-org apps but not
for org apps. Consolidate post-create tasks into a helper used by both
paths.
This commit is contained in:
Dan Peterson 2017-04-26 19:02:53 -03:00 committed by Clint
parent ec7869c6a8
commit cf6e86a127
1 changed files with 21 additions and 14 deletions

View File

@ -232,15 +232,8 @@ func resourceHerokuAppCreate(d *schema.ResourceData, meta interface{}) error {
d.SetId(a.Name)
log.Printf("[INFO] App ID: %s", d.Id())
if v, ok := d.GetOk("config_vars"); ok {
err = updateConfigVars(d.Id(), client, nil, v.([]interface{}))
if err != nil {
return err
}
}
if v, ok := d.GetOk("buildpacks"); ok {
err = updateBuildpacks(d.Id(), client, v.([]interface{}))
if err := performAppPostCreateTasks(d, client); err != nil {
return err
}
return resourceHerokuAppRead(d, meta)
@ -305,11 +298,8 @@ func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error
d.SetId(a.Name)
log.Printf("[INFO] App ID: %s", d.Id())
if v, ok := d.GetOk("config_vars"); ok {
err = updateConfigVars(d.Id(), client, nil, v.([]interface{}))
if err != nil {
return err
}
if err := performAppPostCreateTasks(d, client); err != nil {
return err
}
return resourceHerokuAppRead(d, meta)
@ -534,3 +524,20 @@ func updateBuildpacks(id string, client *heroku.Service, v []interface{}) error
return nil
}
// performAppPostCreateTasks performs post-create tasks common to both org and non-org apps.
func performAppPostCreateTasks(d *schema.ResourceData, client *heroku.Service) error {
if v, ok := d.GetOk("config_vars"); ok {
if err := updateConfigVars(d.Id(), client, nil, v.([]interface{})); err != nil {
return err
}
}
if v, ok := d.GetOk("buildpacks"); ok {
if err := updateBuildpacks(d.Id(), client, v.([]interface{})); err != nil {
return err
}
}
return nil
}