Skip to content

Commit 32b3f42

Browse files
authored
azurerm_log_analytics_data_export_rule - wait for state after creation (#27876)
* `azurerm_log_analytics_data_export` - add a workaround for Azure/azure-rest-api-specs#31399 * update comment * turn to poller
1 parent 626f458 commit 32b3f42

2 files changed

Lines changed: 57 additions & 0 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package custompollers
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"time"
7+
8+
"github.com/hashicorp/go-azure-helpers/lang/response"
9+
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/dataexport"
10+
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
11+
)
12+
13+
var _ pollers.PollerType = &LogAnalyticsDataExportPoller{}
14+
15+
type LogAnalyticsDataExportPoller struct {
16+
client *dataexport.DataExportClient
17+
id dataexport.DataExportId
18+
}
19+
20+
var (
21+
pollingSuccess = pollers.PollResult{
22+
Status: pollers.PollingStatusSucceeded,
23+
PollInterval: 10 * time.Second,
24+
}
25+
pollingInProgress = pollers.PollResult{
26+
Status: pollers.PollingStatusInProgress,
27+
PollInterval: 10 * time.Second,
28+
}
29+
)
30+
31+
func NewLogAnalyticsDataExportPoller(client *dataexport.DataExportClient, id dataexport.DataExportId) *LogAnalyticsDataExportPoller {
32+
return &LogAnalyticsDataExportPoller{
33+
client: client,
34+
id: id,
35+
}
36+
}
37+
38+
func (p LogAnalyticsDataExportPoller) Poll(ctx context.Context) (*pollers.PollResult, error) {
39+
resp, err := p.client.Get(ctx, p.id)
40+
if err != nil {
41+
if response.WasNotFound(resp.HttpResponse) {
42+
return &pollingInProgress, nil
43+
}
44+
return nil, fmt.Errorf("retrieving %s: %+v", p.id, err)
45+
}
46+
return &pollingSuccess, nil
47+
}

internal/services/loganalytics/log_analytics_data_export_resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2021-11-01/eventhubs"
1616
"github.com/hashicorp/go-azure-sdk/resource-manager/eventhub/2022-01-01-preview/namespaces"
1717
"github.com/hashicorp/go-azure-sdk/resource-manager/operationalinsights/2020-08-01/dataexport"
18+
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
1819
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
1920
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
2021
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
22+
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/custompollers"
2123
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/migration"
2224
"github.com/hashicorp/terraform-provider-azurerm/internal/services/loganalytics/validate"
2325
"github.com/hashicorp/terraform-provider-azurerm/internal/tf/pluginsdk"
@@ -167,6 +169,14 @@ func resourceOperationalinsightsDataExportCreateUpdate(d *pluginsdk.ResourceData
167169
return fmt.Errorf("creating/updating %s: %+v", id, err)
168170
}
169171

172+
// Tracked on https://github.com/Azure/azure-rest-api-specs/issues/31399
173+
log.Printf("[DEBUG] Waiting for Log Analytics Workspace Data Export Rule %q to become ready", id.ID())
174+
pollerType := custompollers.NewLogAnalyticsDataExportPoller(client, id)
175+
poller := pollers.NewPoller(pollerType, 10*time.Second, pollers.DefaultNumberOfDroppedConnectionsToAllow)
176+
if err := poller.PollUntilDone(ctx); err != nil {
177+
return err
178+
}
179+
170180
d.SetId(id.ID())
171181
return resourceOperationalinsightsDataExportRead(d, meta)
172182
}

0 commit comments

Comments
 (0)