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 all 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
39 changes: 26 additions & 13 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 @@ -287,16 +297,6 @@ func flattenAzureRmLogProfileRetentionPolicy(input *insights.RetentionPolicy) []
return []interface{}{result}
}

func retryLogProfilesClientGet(ctx context.Context, client *insights.LogProfilesClient, name string, meta interface{}) func() *resource.RetryError {
return func() *resource.RetryError {
if _, err := client.Get(ctx, name); err != nil {
return resource.RetryableError(err)
}

return nil
}
}

func parseLogProfileNameFromID(id string) (string, error) {
components := strings.Split(id, "/")

Expand All @@ -310,3 +310,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
}
}