Skip to content

Commit

Permalink
Fix addon create to pass app name for confirmation (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
mars authored Apr 1, 2022
1 parent f6877e1 commit 322de38
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions heroku/resource_heroku_addon.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,16 @@ func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error {
config := meta.(*Config)
client := config.Api

app := d.Get("app_id").(string)
plan := d.Get("plan").(string)
appID := d.Get("app_id").(string)
app, err := client.AppInfo(context.TODO(), appID)
if err != nil {
return fmt.Errorf("Error reading app for addon: %w", err)
}

opts := heroku.AddOnCreateOpts{
Plan: d.Get("plan").(string),
Confirm: &app,
Plan: plan,
Confirm: &app.Name,
}

if c, ok := d.GetOk("config"); ok {
Expand All @@ -132,18 +138,18 @@ func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error {
opts.Name = &v
}

log.Printf("[DEBUG] Addon create configuration: %#v, %#v", app, opts)
addon, err := client.AddOnCreate(context.TODO(), app, opts)
log.Printf("[DEBUG] Addon create configuration: %#v, %#v", appID, opts)
addon, err := client.AddOnCreate(context.TODO(), appID, opts)
if err != nil {
return err
return fmt.Errorf("Error creating addon %s for app %s (%s): %w", plan, app.Name, appID, err)
}

// Wait for the Addon to be provisioned
log.Printf("[DEBUG] Waiting for Addon (%s) to be provisioned", addon.ID)
stateConf := &resource.StateChangeConf{
Pending: []string{"provisioning"},
Target: []string{"provisioned"},
Refresh: AddOnStateRefreshFunc(client, app, addon.ID),
Refresh: AddOnStateRefreshFunc(client, appID, addon.ID),
Timeout: time.Duration(config.AddonCreateTimeout) * time.Minute,
}

Expand Down

0 comments on commit 322de38

Please sign in to comment.