From 59d3c5afc6ee60ce31ea83f6b201933249249f8e Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Thu, 5 Oct 2017 11:29:06 -0500 Subject: [PATCH 1/2] r/heroku_app: always read all config vars --- heroku/resource_heroku_app.go | 43 +++++++++++++---------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/heroku/resource_heroku_app.go b/heroku/resource_heroku_app.go index fc8c3492..f23a86d3 100644 --- a/heroku/resource_heroku_app.go +++ b/heroku/resource_heroku_app.go @@ -146,8 +146,9 @@ func resourceHerokuApp() *schema.Resource { }, "all_config_vars": { - Type: schema.TypeMap, - Computed: true, + Type: schema.TypeMap, + Computed: true, + Deprecated: "Please reference config_vars instead", }, "git_url": { @@ -330,40 +331,22 @@ func resourceHerokuOrgAppCreate(d *schema.ResourceData, meta interface{}) error func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error { client := meta.(*heroku.Service) - configVars := make(map[string]string) - care := make(map[string]struct{}) - for _, v := range d.Get("config_vars").([]interface{}) { - // Protect against panic on type cast for a nil-length array or map - n, ok := v.(map[string]interface{}) - if !ok { - continue - } - for k := range n { - care[k] = struct{}{} - } - } - // Only track buildpacks when set in the configuration. _, buildpacksConfigured := d.GetOk("buildpacks") organizationApp := isOrganizationApp(d) - // Only set the config_vars that we have set in the configuration. - // The "all_config_vars" field has all of them. + // The "all_config_vars" field has all config vars, but will go away, instead + // you should just reference config_vars, which will also have them all. This + // is done to detect drift in config vars. app, err := resourceHerokuAppRetrieve(d.Id(), organizationApp, client) if err != nil { return err } - for k, v := range app.Vars { - if _, ok := care[k]; ok { - configVars[k] = v - } - } - var configVarsValue []map[string]string - if len(configVars) > 0 { - configVarsValue = []map[string]string{configVars} + if len(app.Vars) > 0 { + configVarsValue = []map[string]string{app.Vars} } d.Set("name", app.App.Name) @@ -374,8 +357,14 @@ func resourceHerokuAppRead(d *schema.ResourceData, meta interface{}) error { if buildpacksConfigured { d.Set("buildpacks", app.Buildpacks) } - d.Set("config_vars", configVarsValue) - d.Set("all_config_vars", app.Vars) + + if err := d.Set("config_vars", configVarsValue); err != nil { + log.Printf("[WARN] Error setting config vars: %s", err) + } + if err := d.Set("all_config_vars", app.Vars); err != nil { + log.Printf("[WARN] Error setting all_config_vars: %s", err) + } + if organizationApp { d.Set("space", app.App.Space) From 46939ad516a22b580766d1e43933792730bdf00f Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Thu, 5 Oct 2017 11:54:02 -0500 Subject: [PATCH 2/2] don't not-check config_vars on import --- heroku/import_heroku_app_test.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/heroku/import_heroku_app_test.go b/heroku/import_heroku_app_test.go index 7ede51c6..52915fec 100644 --- a/heroku/import_heroku_app_test.go +++ b/heroku/import_heroku_app_test.go @@ -21,10 +21,9 @@ func TestAccHerokuApp_importBasic(t *testing.T) { Config: testAccCheckHerokuAppConfig_basic(appName), }, { - ResourceName: "heroku_app.foobar", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"config_vars"}, + ResourceName: "heroku_app.foobar", + ImportState: true, + ImportStateVerify: true, }, }, }) @@ -48,10 +47,9 @@ func TestAccHerokuApp_importOrganization(t *testing.T) { Config: testAccCheckHerokuAppConfig_organization(appName, org), }, { - ResourceName: "heroku_app.foobar", - ImportState: true, - ImportStateVerify: true, - ImportStateVerifyIgnore: []string{"config_vars"}, + ResourceName: "heroku_app.foobar", + ImportState: true, + ImportStateVerify: true, }, }, })