-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
azurerm_storage_sync_server_endpoint
create/update polling (#26204)
- Loading branch information
1 parent
64a989a
commit 818118d
Showing
3 changed files
with
98 additions
and
1 deletion.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
internal/services/storage/custompollers/storage_sync_server_endpoint_poller.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package custompollers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/pointer" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/storagesync/2020-03-01/serverendpointresource" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers" | ||
) | ||
|
||
var _ pollers.PollerType = &storageSyncServerEndpointPoller{} | ||
|
||
type storageSyncServerEndpointPoller struct { | ||
client *serverendpointresource.ServerEndpointResourceClient | ||
id serverendpointresource.ServerEndpointId | ||
} | ||
|
||
// The `ServerEndpointsCreateThenPoll` and `ServerEndpointsUpdateThenPoll` methods do not properly await, so a custom poller is required | ||
func NewStorageSyncServerEndpointPoller(client *serverendpointresource.ServerEndpointResourceClient, id serverendpointresource.ServerEndpointId) *storageSyncServerEndpointPoller { | ||
return &storageSyncServerEndpointPoller{ | ||
client: client, | ||
id: id, | ||
} | ||
} | ||
|
||
func (p storageSyncServerEndpointPoller) Poll(ctx context.Context) (*pollers.PollResult, error) { | ||
resp, err := p.client.ServerEndpointsGet(ctx, p.id) | ||
if err != nil { | ||
return nil, fmt.Errorf("retrieving %s: %+v", p.id, err) | ||
} | ||
|
||
provisioningState := "" | ||
if model := resp.Model; model != nil && model.Properties != nil { | ||
provisioningState = pointer.From(model.Properties.ProvisioningState) | ||
} | ||
|
||
if strings.EqualFold(provisioningState, "Succeeded") { | ||
return &pollers.PollResult{ | ||
HttpResponse: &client.Response{ | ||
Response: resp.HttpResponse, | ||
}, | ||
PollInterval: 10 * time.Second, | ||
Status: pollers.PollingStatusSucceeded, | ||
}, nil | ||
} | ||
|
||
if strings.EqualFold(provisioningState, "runServerJob") { | ||
return &pollers.PollResult{ | ||
HttpResponse: &client.Response{ | ||
Response: resp.HttpResponse, | ||
}, | ||
PollInterval: 10 * time.Second, | ||
Status: pollers.PollingStatusInProgress, | ||
}, nil | ||
} | ||
|
||
return nil, pollers.PollingFailedError{ | ||
HttpResponse: &client.Response{ | ||
Response: resp.HttpResponse, | ||
}, | ||
Message: fmt.Sprintf("unexpected provisioningState %q", provisioningState), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters