Skip to content

Commit

Permalink
azurerm_log_analytics_data_export - add a workaround for Azure/azur…
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Nov 4, 2024
1 parent 474f00e commit 48dccfc
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package loganalytics

import (
"context"
"fmt"
"log"
"strings"
Expand Down Expand Up @@ -164,6 +165,26 @@ func resourceOperationalinsightsDataExportCreateUpdate(d *pluginsdk.ResourceData
return fmt.Errorf("creating/updating %s: %+v", id, err)
}

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

// Tracked on https://github.com/Azure/azure-rest-api-specs/issues/31399
log.Printf("[DEBUG] Waiting for Log Analytics Workspace Data Export %q to become ready", id.ID())
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"NotFound"},
Target: []string{"Exists"},
Refresh: dataExportRefreshFunc(ctx, client, id),
MinTimeout: 5 * time.Second,
ContinuousTargetOccurence: 3,
Timeout: time.Until(deadline),
}

if _, err = stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for Log Analytics Workspace Data Export %q to become ready: %+v", id.ID(), err)
}

d.SetId(id.ID())
return resourceOperationalinsightsDataExportRead(d, meta)
}
Expand Down Expand Up @@ -255,3 +276,17 @@ func flattenDataExportDestination(input *dataexport.Destination) (string, error)

return resourceID, nil
}

func dataExportRefreshFunc(ctx context.Context, client *dataexport.DataExportClient, id dataexport.DataExportId) pluginsdk.StateRefreshFunc {
return func() (result interface{}, state string, err error) {
res, err := client.Get(ctx, id)
if err != nil {
if response.WasNotFound(res.HttpResponse) {
return "NotFound", "NotFound", nil
}
return nil, "", fmt.Errorf("retrieving %s: %+v", id, err)
}

return res, "Exists", nil
}
}

0 comments on commit 48dccfc

Please sign in to comment.