Skip to content

Commit

Permalink
azurerm_log_analytics_data_export_rule - wait for state after creat…
Browse files Browse the repository at this point in the history
…ion (#27876)

* `azurerm_log_analytics_data_export` - add a workaround for Azure/azure-rest-api-specs#31399

* update comment

* turn to poller
  • Loading branch information
ziyeqf authored Dec 17, 2024
1 parent 626f458 commit 32b3f42
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package custompollers

import (
"context"
"fmt"
"time"

"github.com/hashicorp/go-azure-helpers/lang/response"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/dataexport"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
)

var _ pollers.PollerType = &LogAnalyticsDataExportPoller{}

type LogAnalyticsDataExportPoller struct {
client *dataexport.DataExportClient
id dataexport.DataExportId
}

var (
pollingSuccess = pollers.PollResult{
Status: pollers.PollingStatusSucceeded,
PollInterval: 10 * time.Second,
}
pollingInProgress = pollers.PollResult{
Status: pollers.PollingStatusInProgress,
PollInterval: 10 * time.Second,
}
)

func NewLogAnalyticsDataExportPoller(client *dataexport.DataExportClient, id dataexport.DataExportId) *LogAnalyticsDataExportPoller {
return &LogAnalyticsDataExportPoller{
client: client,
id: id,
}
}

func (p LogAnalyticsDataExportPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
resp, err := p.client.Get(ctx, p.id)
if err != nil {
if response.WasNotFound(resp.HttpResponse) {
return &pollingInProgress, nil
}
return nil, fmt.Errorf("retrieving %s: %+v", p.id, err)
}
return &pollingSuccess, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs"
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/dataexport"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/custompollers"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/migration"
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/validate"
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
Expand Down Expand Up @@ -167,6 +169,14 @@ func resourceOperationalinsightsDataExportCreateUpdate(d *pluginsdk.ResourceData
return fmt.Errorf("creating/updating %s: %+v", id, err)
}

// Tracked on https://github.com/Azure/azure-rest-api-specs/issues/31399
log.Printf("[DEBUG] Waiting for Log Analytics Workspace Data Export Rule %q to become ready", id.ID())
pollerType := custompollers.NewLogAnalyticsDataExportPoller(client, id)
poller := pollers.NewPoller(pollerType, 10*time.Second, pollers.DefaultNumberOfDroppedConnectionsToAllow)
if err := poller.PollUntilDone(ctx); err != nil {
return err
}

d.SetId(id.ID())
return resourceOperationalinsightsDataExportRead(d, meta)
}
Expand Down

0 comments on commit 32b3f42

Please sign in to comment.