Skip to content

Commit

Permalink
fix: use cluster list api to determine pinned cluster status
Browse files Browse the repository at this point in the history
  • Loading branch information
bgrams committed Nov 8, 2024
1 parent 973189a commit c296fec
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 270 deletions.
27 changes: 15 additions & 12 deletions clusters/resource_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,20 +513,23 @@ func resourceClusterCreate(ctx context.Context, d *schema.ResourceData, c *commo
}

func setPinnedStatus(ctx context.Context, d *schema.ResourceData, clusterAPI compute.ClustersInterface) error {
events, err := clusterAPI.EventsAll(ctx, compute.GetEvents{
ClusterId: d.Id(),
Limit: 1,
Order: compute.GetEventsOrderDesc,
EventTypes: []compute.EventType{compute.EventTypePinned, compute.EventTypeUnpinned},
clusterDetails := clusterAPI.List(ctx, compute.ListClustersRequest{
FilterBy: &compute.ListClustersFilterBy{
IsPinned: true,
},
PageSize: 100, // pinned cluster limit - just get all of them
})
if err != nil {
return err
}
pinnedEvent := compute.EventTypeUnpinned
if len(events) > 0 {
pinnedEvent = events[0].Type

for clusterDetails.HasNext(ctx) {
detail, err := clusterDetails.Next(ctx)
if err != nil {
return err
}
if detail.ClusterId == d.Id() {
return d.Set("is_pinned", true)
}
}
return d.Set("is_pinned", pinnedEvent == compute.EventTypePinned)
return d.Set("is_pinned", false)
}

func resourceClusterRead(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
Expand Down
Loading

0 comments on commit c296fec

Please sign in to comment.