@@ -263,7 +263,14 @@ func createStack(ctx context.Context, d *schema.ResourceData, client *gcom.APICl
263263 return diag
264264 }
265265
266- return waitForStackReadiness (ctx , d )
266+ if d .Get ("wait_for_readiness" ).(bool ) {
267+ timeout := defaultReadinessTimeout
268+ if timeoutVal := d .Get ("wait_for_readiness_timeout" ).(string ); timeoutVal != "" {
269+ timeout , _ = time .ParseDuration (timeoutVal )
270+ }
271+ return waitForStackReadiness (ctx , timeout , d .Get ("url" ).(string ))
272+ }
273+ return nil
267274}
268275
269276func updateStack (ctx context.Context , d * schema.ResourceData , client * gcom.APIClient ) diag.Diagnostics {
@@ -295,7 +302,14 @@ func updateStack(ctx context.Context, d *schema.ResourceData, client *gcom.APICl
295302 return diag
296303 }
297304
298- return waitForStackReadiness (ctx , d )
305+ if d .Get ("wait_for_readiness" ).(bool ) {
306+ timeout := defaultReadinessTimeout
307+ if timeoutVal := d .Get ("wait_for_readiness_timeout" ).(string ); timeoutVal != "" {
308+ timeout , _ = time .ParseDuration (timeoutVal )
309+ }
310+ return waitForStackReadiness (ctx , timeout , d .Get ("url" ).(string ))
311+ }
312+ return nil
299313}
300314
301315func deleteStack (ctx context.Context , d * schema.ResourceData , client * gcom.APIClient ) diag.Diagnostics {
@@ -422,17 +436,13 @@ func appendPath(baseURL, path string) (string, error) {
422436}
423437
424438// waitForStackReadiness retries until the stack is ready, verified by querying the Grafana URL
425- func waitForStackReadiness (ctx context.Context , d * schema.ResourceData ) diag.Diagnostics {
426- if wait := d .Get ("wait_for_readiness" ).(bool ); ! wait {
427- return nil
428- }
429-
430- timeout := defaultReadinessTimeout
431- if timeoutVal := d .Get ("wait_for_readiness_timeout" ).(string ); timeoutVal != "" {
432- timeout , _ = time .ParseDuration (timeoutVal )
439+ func waitForStackReadiness (ctx context.Context , timeout time.Duration , stackURL string ) diag.Diagnostics {
440+ healthURL , joinErr := url .JoinPath (stackURL , "api" , "health" )
441+ if joinErr != nil {
442+ return diag .FromErr (joinErr )
433443 }
434444 err := retry .RetryContext (ctx , timeout , func () * retry.RetryError {
435- req , err := http .NewRequestWithContext (ctx , http .MethodHead , d . Get ( "url" ).( string ) , nil )
445+ req , err := http .NewRequestWithContext (ctx , http .MethodGet , healthURL , nil )
436446 if err != nil {
437447 return retry .NonRetryableError (err )
438448 }
@@ -456,12 +466,21 @@ func waitForStackReadiness(ctx context.Context, d *schema.ResourceData) diag.Dia
456466 return nil
457467 })
458468 if err != nil {
459- return diag .Errorf ("error waiting for stack to be ready: %v" , err )
469+ return diag .Errorf ("error waiting for stack (URL: %s) to be ready: %v" , healthURL , err )
460470 }
461471
462472 return nil
463473}
464474
475+ func waitForStackReadinessFromSlug (ctx context.Context , timeout time.Duration , slug string , client * gcom.APIClient ) diag.Diagnostics {
476+ stack , _ , err := client .InstancesAPI .GetInstance (ctx , slug ).Execute ()
477+ if err != nil {
478+ return apiError (err )
479+ }
480+
481+ return waitForStackReadiness (ctx , timeout , stack .Url )
482+ }
483+
465484func defaultStackURL (slug string ) string {
466485 return fmt .Sprintf ("https://%s.grafana.net" , slug )
467486}
0 commit comments