Skip to content

Commit

Permalink
Merge pull request heroku#17 from terraform-providers/b-config-vars-u…
Browse files Browse the repository at this point in the history
…pdate

r/heroku_app: always read all config vars
  • Loading branch information
tombuildsstuff authored Nov 6, 2017
2 parents 9deec26 + 46939ad commit 57c2336
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 35 deletions.
14 changes: 6 additions & 8 deletions heroku/import_heroku_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
})
Expand All @@ -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,
},
},
})
Expand Down
43 changes: 16 additions & 27 deletions heroku/resource_heroku_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)
Expand All @@ -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)

Expand Down

0 comments on commit 57c2336

Please sign in to comment.