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_monitor_diagnostic_setting - wait resource to become ready in creation #25697

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,20 @@ func resourceMonitorDiagnosticSettingCreate(d *pluginsdk.ResourceData, meta inte
return fmt.Errorf("creating Monitor Diagnostics Setting %q for Resource %q: %+v", id.DiagnosticSettingName, id.ResourceUri, err)
}

log.Printf("[DEBUG] Waiting for Monitor Diagnostic Setting %q for Resource %q to become ready", id.DiagnosticSettingName, id.ResourceUri)
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Exists"},
Refresh: monitorDiagnosticSettingRefreshFunc(ctx, client, id),
MinTimeout: 5 * time.Second,
ContinuousTargetOccurence: 3,
Timeout: d.Timeout(pluginsdk.TimeoutCreate),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use the calculated deadline from the context here otherwise that will potentially expire before this WaitForStateContext is complete. e.g.

	deadline, ok := ctx.Deadline()
	if !ok {
		return fmt.Errorf("could not retrieve context deadline for %s", id.ID())
	}

...

	Timeout: time.Until(deadline)

Can you also update the other instance(s) of this bug in this resource while we're here?

}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Monitor Diagnostic Setting %q for Resource %q to become ready: %s", id.DiagnosticSettingName, id.ResourceUri, err)
}

d.SetId(resourceId)

return resourceMonitorDiagnosticSettingRead(d, meta)
Expand Down Expand Up @@ -600,27 +614,27 @@ func resourceMonitorDiagnosticSettingDelete(d *pluginsdk.ResourceData, meta inte
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"Exists"},
Target: []string{"NotFound"},
Refresh: monitorDiagnosticSettingDeletedRefreshFunc(ctx, client, *id),
Refresh: monitorDiagnosticSettingRefreshFunc(ctx, client, *id),
MinTimeout: 15 * time.Second,
ContinuousTargetOccurence: 5,
Timeout: d.Timeout(pluginsdk.TimeoutDelete),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Monitor Diagnostic Setting %q for Resource %q to become available: %s", id.DiagnosticSettingName, id.ResourceUri, err)
return fmt.Errorf("waiting for Monitor Diagnostic Setting %q for Resource %q to disappear: %s", id.DiagnosticSettingName, id.ResourceUri, err)
}

return nil
}

func monitorDiagnosticSettingDeletedRefreshFunc(ctx context.Context, client *diagnosticsettings.DiagnosticSettingsClient, targetResourceId diagnosticsettings.ScopedDiagnosticSettingId) pluginsdk.StateRefreshFunc {
func monitorDiagnosticSettingRefreshFunc(ctx context.Context, client *diagnosticsettings.DiagnosticSettingsClient, targetResourceId diagnosticsettings.ScopedDiagnosticSettingId) pluginsdk.StateRefreshFunc {
return func() (interface{}, string, error) {
res, err := client.Get(ctx, targetResourceId)
if err != nil {
if response.WasNotFound(res.HttpResponse) {
return "NotFound", "NotFound", nil
}
return nil, "", fmt.Errorf("issuing read request in monitorDiagnosticSettingDeletedRefreshFunc: %s", err)
return nil, "", fmt.Errorf("issuing read request in monitorDiagnosticSettingRefreshFunc: %s", err)
}

return res, "Exists", nil
Expand Down
Loading