Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 32 additions & 13 deletions internal/services/network/private_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ package network

import (
"context"
"errors"
"fmt"
"log"
"slices"
"sort"
"strings"
"time"
Expand All @@ -25,6 +27,7 @@ import (
"github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2024-06-01/privatezones"
"github.com/hashicorp/go-azure-sdk/resource-manager/redis/2024-03-01/redis"
"github.com/hashicorp/go-azure-sdk/resource-manager/signalr/2024-03-01/signalr"
"github.com/hashicorp/go-azure-sdk/sdk/client/pollers"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf"
Expand Down Expand Up @@ -353,27 +356,43 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{})
}

err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
if err = client.CreateOrUpdateThenPoll(ctx, id, parameters); err != nil {
switch {
case strings.EqualFold(err.Error(), "is missing required parameter 'group Id'"):
{
result, err := client.CreateOrUpdate(ctx, id, parameters)
if err != nil {
return &pluginsdk.RetryError{
Err: fmt.Errorf("creating %s: %+v", id, err),
Retryable: false,
}
}

if err := result.Poller.PollUntilDone(ctx); err != nil {
var lroFailError pollers.PollingFailedError
if errors.As(err, &lroFailError) {
type lroErrorType struct {
Error struct {
Code string `json:"code"`
Message string `json:"message"`
} `json:"error"`
}

var lroError lroErrorType
if err := lroFailError.HttpResponse.Unmarshal(&lroError); err != nil {
return &pluginsdk.RetryError{
Err: fmt.Errorf("creating %s due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id, err),
Err: fmt.Errorf("unmarshaling lro error response: %v", err),
Retryable: false,
}
}
case strings.Contains(err.Error(), "PrivateLinkServiceId Invalid private link service id"):
{

retryableErrorCodes := []string{"RetryableError", "StorageAccountOperationInProgress"}
if slices.Contains(retryableErrorCodes, lroError.Error.Code) {
log.Printf("[WARN] Retry polling %q on error code: %q", id, lroError.Error.Code)
return &pluginsdk.RetryError{
Err: fmt.Errorf("creating Private Endpoint %s: %+v", id, err),
Retryable: true,
}
}
default:
return &pluginsdk.RetryError{
Err: fmt.Errorf("creating %s: %+v", id, err),
Retryable: false,
}
}
return &pluginsdk.RetryError{
Err: fmt.Errorf("waiting the creation of %s: %+v", id, err),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the error message stay the same? Or did you mean "waiting for"?

Suggested change
Err: fmt.Errorf("waiting the creation of %s: %+v", id, err),
Err: fmt.Errorf("creating %s: %+v", id, err),

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wyattfry Yes, I meant "waiting for", to differ from the error message for L359:

		result, err := client.CreateOrUpdate(ctx, id, parameters)
		if err != nil {
			return &pluginsdk.RetryError{
				Err:       fmt.Errorf("creating %s: %+v", id, err),
				Retryable: false,
			}
		}

Retryable: false,
}
}

Expand Down
Loading