Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/heroku_app: always read all config vars #17

Merged
merged 2 commits into from
Nov 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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