Skip to content

Commit

Permalink
Wait for search service provisioning state when creating or updating …
Browse files Browse the repository at this point in the history
…resource

Signed-off-by: Owen Farrell <[email protected]>
  • Loading branch information
owenfarrell committed Oct 8, 2021
1 parent 3bfd30c commit 4c929a9
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions internal/services/search/search_service_resource.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package search

import (
"context"
"fmt"
"log"
"time"
Expand Down Expand Up @@ -217,9 +218,17 @@ func resourceSearchServiceCreateUpdate(d *pluginsdk.ResourceData, meta interface
return fmt.Errorf("waiting for creation/update of %s: %+v", id, err)
}

_, err = client.Get(ctx, id.ResourceGroup, id.Name, nil)
if err != nil {
return fmt.Errorf("issuing get request for %s: %v", id, err)
timeout, _ := ctx.Deadline()

stateConf := &pluginsdk.StateChangeConf{
Pending: []string{string(search.Provisioning)},
Target: []string{string(search.Succeeded)},
Refresh: searchServiceProvisioningStateRefreshFunc(ctx, client, id),
Timeout: time.Until(timeout),
PollInterval: 1 * time.Minute,
}
if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for provisioning state of %s: %+v", id, err)
}

d.SetId(id.ID())
Expand Down Expand Up @@ -394,3 +403,14 @@ func flattenSearchServiceIdentity(identity *search.Identity) []interface{} {
},
}
}

func searchServiceProvisioningStateRefreshFunc(ctx context.Context, client *search.ServicesClient, id parse.SearchServiceId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
resp, err := client.Get(ctx, id.ResourceGroup, id.Name, nil)
if err != nil {
return nil, "", fmt.Errorf("polling for %s: %+v", id, err)
}

return resp, string(resp.ProvisioningState), nil
}
}

0 comments on commit 4c929a9

Please sign in to comment.