From e523e400b8acf3cd52dd9aff0aec5083f9d55664 Mon Sep 17 00:00:00 2001 From: Jack Pearkes Date: Wed, 23 Jul 2014 11:26:31 -0400 Subject: [PATCH] providers/heroku: refactor update config vars --- .../providers/heroku/resource_heroku_app.go | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/builtin/providers/heroku/resource_heroku_app.go b/builtin/providers/heroku/resource_heroku_app.go index 258701746..b8a9328aa 100644 --- a/builtin/providers/heroku/resource_heroku_app.go +++ b/builtin/providers/heroku/resource_heroku_app.go @@ -45,21 +45,13 @@ func resource_heroku_app_create( } rs.ID = app.Name - log.Printf("[INFO] App ID: %s", rs.ID) if attr, ok := rs.Attributes["config_vars.#"]; ok && attr == "1" { vs := flatmap.Expand( rs.Attributes, "config_vars").([]interface{}) - vars := make(map[string]*string) - - for k, v := range vs[0].(map[string]interface{}) { - val := v.(string) - vars[k] = &val - } - - _, err = client.ConfigVarUpdate(rs.ID, vars) + err = update_config_vars(rs.ID, vs, client) if err != nil { return rs, err } @@ -177,3 +169,22 @@ func resource_heroku_app_validation() *config.Validator { }, } } + +// Updates the config vars for from an expanded (prior to assertion) +// []map[string]string config +func update_config_vars(id string, vs []interface{}, client *heroku.Client) error { + vars := make(map[string]*string) + + for k, v := range vs[0].(map[string]interface{}) { + val := v.(string) + vars[k] = &val + } + + _, err := client.ConfigVarUpdate(id, vars) + + if err != nil { + return fmt.Errorf("Error updating config vars: %s", err) + } + + return nil +}