@@ -115,10 +115,16 @@ func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error {
115
115
config := meta .(* Config )
116
116
client := config .Api
117
117
118
- app := d .Get ("app_id" ).(string )
118
+ plan := d .Get ("plan" ).(string )
119
+ appID := d .Get ("app_id" ).(string )
120
+ app , err := client .AppInfo (context .TODO (), appID )
121
+ if err != nil {
122
+ return fmt .Errorf ("Error reading app for addon: %w" , err )
123
+ }
124
+
119
125
opts := heroku.AddOnCreateOpts {
120
- Plan : d . Get ( " plan" ).( string ) ,
121
- Confirm : & app ,
126
+ Plan : plan ,
127
+ Confirm : & app . Name ,
122
128
}
123
129
124
130
if c , ok := d .GetOk ("config" ); ok {
@@ -132,18 +138,18 @@ func resourceHerokuAddonCreate(d *schema.ResourceData, meta interface{}) error {
132
138
opts .Name = & v
133
139
}
134
140
135
- log .Printf ("[DEBUG] Addon create configuration: %#v, %#v" , app , opts )
136
- addon , err := client .AddOnCreate (context .TODO (), app , opts )
141
+ log .Printf ("[DEBUG] Addon create configuration: %#v, %#v" , appID , opts )
142
+ addon , err := client .AddOnCreate (context .TODO (), appID , opts )
137
143
if err != nil {
138
- return err
144
+ return fmt . Errorf ( "Error creating addon %s for app %s (%s): %w" , plan , app . Name , appID , err )
139
145
}
140
146
141
147
// Wait for the Addon to be provisioned
142
148
log .Printf ("[DEBUG] Waiting for Addon (%s) to be provisioned" , addon .ID )
143
149
stateConf := & resource.StateChangeConf {
144
150
Pending : []string {"provisioning" },
145
151
Target : []string {"provisioned" },
146
- Refresh : AddOnStateRefreshFunc (client , app , addon .ID ),
152
+ Refresh : AddOnStateRefreshFunc (client , appID , addon .ID ),
147
153
Timeout : time .Duration (config .AddonCreateTimeout ) * time .Minute ,
148
154
}
149
155
0 commit comments