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

azurerm_log_profile wait for stable state #5194

Merged
merged 4 commits into from
Dec 17, 2019
Merged
Changes from 3 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
29 changes: 26 additions & 3 deletions azurerm/resource_arm_monitor_log_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,19 @@ func resourceArmLogProfileCreateUpdate(d *schema.ResourceData, meta interface{})
duration = d.Timeout(schema.TimeoutUpdate)
}
}
// Wait for Log Profile to become available
if err := resource.Retry(duration, retryLogProfilesClientGet(ctx, client, name, meta)); err != nil {
tiwood marked this conversation as resolved.
Show resolved Hide resolved
return fmt.Errorf("Error waiting for Log Profile %q to become available: %+v", name, err)

log.Printf("[DEBUG] Waiting for Log Profile %q to be provisioned", name)
stateConf := &resource.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Available"},
Refresh: logProfilesCreateRefreshFunc(ctx, client, name),
Timeout: duration,
MinTimeout: 15 * time.Second,
ContinuousTargetOccurence: 5,
}

if _, err := stateConf.WaitForState(); err != nil {
return fmt.Errorf("Error waiting for Log Profile %q to become available: %s", name, err)
}

read, err := client.Get(ctx, name)
Expand Down Expand Up @@ -310,3 +320,16 @@ func parseLogProfileNameFromID(id string) (string, error) {

return components[6], nil
}

func logProfilesCreateRefreshFunc(ctx context.Context, client *insights.LogProfilesClient, name string) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
logProfile, err := client.Get(ctx, name)
if err != nil {
if utils.ResponseWasNotFound(logProfile.Response) {
return nil, "NotFound", nil
}
return nil, "", fmt.Errorf("Error issuing read request in logProfilesCreateRefreshFunc for Log profile %q: %s", name, err)
}
return "Available", "Available", nil
}
}