providers/heroku: refactor update config vars

This commit is contained in:
Jack Pearkes 2014-07-23 11:26:31 -04:00
parent 298b8090f0
commit e523e400b8
1 changed files with 20 additions and 9 deletions

View File

@ -45,21 +45,13 @@ func resource_heroku_app_create(
} }
rs.ID = app.Name rs.ID = app.Name
log.Printf("[INFO] App ID: %s", rs.ID) log.Printf("[INFO] App ID: %s", rs.ID)
if attr, ok := rs.Attributes["config_vars.#"]; ok && attr == "1" { if attr, ok := rs.Attributes["config_vars.#"]; ok && attr == "1" {
vs := flatmap.Expand( vs := flatmap.Expand(
rs.Attributes, "config_vars").([]interface{}) 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 { if err != nil {
return rs, err 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
}