-
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_key_vault_managed_hardware_security_module
: fix purge issue (…
…#24301) * fix mhsm purge issue * update purge * update purge poller
- Loading branch information
Showing
3 changed files
with
66 additions
and
8 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
internal/services/keyvault/custompollers/hsm_purge_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,54 @@ | ||
package custompollers | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/hashicorp/go-azure-helpers/lang/response" | ||
"github.com/hashicorp/go-azure-sdk/resource-manager/keyvault/2023-02-01/managedhsms" | ||
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers" | ||
) | ||
|
||
var _ pollers.PollerType = &hsmDownloadPoller{} | ||
|
||
func NewHSMPurgePoller(client *managedhsms.ManagedHsmsClient, id managedhsms.DeletedManagedHSMId) *hsmPurgePoller { | ||
return &hsmPurgePoller{ | ||
client: client, | ||
purgeId: id, | ||
purgeAgainUntil: time.Now().Add(time.Minute), | ||
} | ||
} | ||
|
||
type hsmPurgePoller struct { | ||
client *managedhsms.ManagedHsmsClient | ||
purgeId managedhsms.DeletedManagedHSMId | ||
purgeAgainUntil time.Time | ||
} | ||
|
||
func (p *hsmPurgePoller) Poll(ctx context.Context) (*pollers.PollResult, error) { | ||
deletedResp, err := p.client.GetDeleted(ctx, p.purgeId) | ||
|
||
res := &pollers.PollResult{ | ||
PollInterval: time.Second * 20, | ||
Status: pollers.PollingStatusInProgress, | ||
} | ||
if response.WasNotFound(deletedResp.HttpResponse) { | ||
res.Status = pollers.PollingStatusSucceeded | ||
return res, nil | ||
} | ||
|
||
if err != nil { | ||
return nil, fmt.Errorf("retrieving deleted managed HSM %s: %+v", p.purgeId, err) | ||
} | ||
|
||
if time.Now().After(p.purgeAgainUntil) { | ||
p.purgeAgainUntil = time.Now().Add(time.Minute) | ||
purgeResp, _ := p.client.PurgeDeleted(ctx, p.purgeId) | ||
if response.WasNotFound(purgeResp.HttpResponse) { | ||
res.Status = pollers.PollingStatusSucceeded | ||
} | ||
} | ||
|
||
return res, nil | ||
} |
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