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_eventhub_namespace - adding wait before deletion #19165

Merged
merged 1 commit into from
Jan 9, 2023
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
26 changes: 26 additions & 0 deletions internal/services/eventhub/eventhub_namespace_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,11 @@ func resourceEventHubNamespaceDelete(d *pluginsdk.ResourceData, meta interface{}
return err
}

// need to wait for namespace status to be ready before deleting.
if err := waitForEventHubNamespaceStatusToBeReady(ctx, meta, *id, d.Timeout(pluginsdk.TimeoutUpdate)); err != nil {
return fmt.Errorf("waiting for eventHub namespace %s state to be ready error: %+v", *id, err)
}
Comment on lines +622 to +625
Copy link
Contributor

Choose a reason for hiding this comment

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

this indicates that another resource isn't marking itself as Created/Updated correctly, which resource is causing this?

Copy link
Contributor Author

@xiaxyi xiaxyi Nov 8, 2022

Choose a reason for hiding this comment

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

its disasterRecoveryConfig resource. The situation is the as the same as servicebus namespace. The fix was made in pr #18706

Copy link
Contributor

Choose a reason for hiding this comment

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

So is this fixed in main?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The wait function mentioned in pr #18706 is for servicebus namespace, not for eventhub namespace. The servicebus one was merged. Please feel free to correct me if there is any misunderstanding.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it - so we should look to revert #18706 and then fix the actual issue here - this type of fix ends up causing larger issues elsewhere unfortunately.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @tombuildsstuff for the comment. I left my comment in the thread, hope that explains your concern. :)


future, err := client.Delete(ctx, *id)
if err != nil {
if response.WasNotFound(future.HttpResponse) {
Expand All @@ -630,6 +635,27 @@ func resourceEventHubNamespaceDelete(d *pluginsdk.ResourceData, meta interface{}
return waitForEventHubNamespaceToBeDeleted(ctx, client, *id)
}

func waitForEventHubNamespaceStatusToBeReady(ctx context.Context, meta interface{}, id namespaces.NamespaceId, timeout time.Duration) error {
namespaceClient := meta.(*clients.Client).Eventhub.NamespacesClient
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{
string(namespaces.EndPointProvisioningStateUpdating),
string(namespaces.EndPointProvisioningStateCreating),
string(namespaces.EndPointProvisioningStateDeleting),
},
Target: []string{string(namespaces.EndPointProvisioningStateSucceeded)},
Refresh: eventHubNamespaceProvisioningStateRefreshFunc(ctx, namespaceClient, id),
Timeout: timeout,
PollInterval: 10 * time.Second,
ContinuousTargetOccurence: 5,
}

if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return err
}
return nil
}

func waitForEventHubNamespaceToBeDeleted(ctx context.Context, client *namespaces.NamespacesClient, id namespaces.NamespaceId) error {
deadline, ok := ctx.Deadline()
if !ok {
Expand Down