-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
azurerm_private_endpoint
Try to add retry on creation
#16315
Changes from 4 commits
a9ee7fa
651a545
d2775db
3f1569a
5186632
7a48ddb
c856eaa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |||||
"github.com/hashicorp/go-azure-sdk/resource-manager/postgresql/2017-12-01/servers" | ||||||
"github.com/hashicorp/go-azure-sdk/resource-manager/privatedns/2018-09-01/privatezones" | ||||||
"github.com/hashicorp/go-azure-sdk/resource-manager/signalr/2022-02-01/signalr" | ||||||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/helpers/tf" | ||||||
"github.com/hashicorp/terraform-provider-azurerm/internal/clients" | ||||||
|
@@ -289,17 +290,35 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{}) | |||||
//goland:noinspection GoDeferInLoop | ||||||
defer locks.UnlockByName(cosmosDbResId, "azurerm_private_endpoint") | ||||||
} | ||||||
locks.ByName(subnetId, "azurerm_private_endpoint") | ||||||
defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") | ||||||
|
||||||
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) | ||||||
if err != nil { | ||||||
if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { | ||||||
return fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err) | ||||||
} else { | ||||||
return fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) | ||||||
err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *resource.RetryError { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) | ||||||
if err != nil { | ||||||
if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { | ||||||
return &resource.RetryError{ | ||||||
Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q) due to missing 'group Id', ensure that the 'subresource_names' type is populated: %+v", id.Name, id.ResourceGroup, err), | ||||||
Retryable: false, | ||||||
} | ||||||
} else { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we have to do this can we narrow the scope here and only check for the expected error? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. test /wr |
||||||
return &resource.RetryError{ | ||||||
Err: fmt.Errorf("creating Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), | ||||||
Retryable: false, | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||||||
return fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err) | ||||||
|
||||||
if err = future.WaitForCompletionRef(ctx, client.Client); err != nil { | ||||||
return &resource.RetryError{ | ||||||
Err: fmt.Errorf("waiting for creation of Private Endpoint %q (Resource Group %q): %+v", id.Name, id.ResourceGroup, err), | ||||||
Retryable: strings.Contains(strings.ToLower(err.Error()), "Resource is in Updating state and the last operation that updated/is updating the resource is PutSubnetOperation"), | ||||||
} | ||||||
} | ||||||
return nil | ||||||
}) | ||||||
if err != nil { | ||||||
return err | ||||||
} | ||||||
|
||||||
d.SetId(id.ID()) | ||||||
|
@@ -379,6 +398,9 @@ func resourcePrivateEndpointUpdate(d *pluginsdk.ResourceData, meta interface{}) | |||||
Tags: tags.Expand(d.Get("tags").(map[string]interface{})), | ||||||
} | ||||||
|
||||||
locks.ByName(subnetId, "azurerm_private_endpoint") | ||||||
defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") | ||||||
|
||||||
future, err := client.CreateOrUpdate(ctx, id.ResourceGroup, id.Name, parameters) | ||||||
if err != nil { | ||||||
if strings.EqualFold(err.Error(), "is missing required parameter 'group Id'") { | ||||||
|
@@ -547,6 +569,7 @@ func resourcePrivateEndpointDelete(d *pluginsdk.ResourceData, meta interface{}) | |||||
} | ||||||
log.Printf("[DEBUG] Deleted the Private DNS Zone Group associated with Private Endpoint %q / Resource Group %q.", id.Name, id.ResourceGroup) | ||||||
|
||||||
subnetId := d.Get("subnet_id").(string) | ||||||
privateServiceConnections := d.Get("private_service_connection").([]interface{}) | ||||||
parameters := network.PrivateEndpoint{ | ||||||
PrivateEndpointProperties: &network.PrivateEndpointProperties{ | ||||||
|
@@ -560,6 +583,8 @@ func resourcePrivateEndpointDelete(d *pluginsdk.ResourceData, meta interface{}) | |||||
//goland:noinspection GoDeferInLoop | ||||||
defer locks.UnlockByName(cosmosDbResId, "azurerm_private_endpoint") | ||||||
} | ||||||
locks.ByName(subnetId, "azurerm_private_endpoint") | ||||||
defer locks.UnlockByName(subnetId, "azurerm_private_endpoint") | ||||||
|
||||||
log.Printf("[DEBUG] Deleting the Private Endpoint %q / Resource Group %q..", id.Name, id.ResourceGroup) | ||||||
future, err := client.Delete(ctx, id.ResourceGroup, id.Name) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now that we are locking can we revert this and remove the retry? as it shouldn't be required
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copy that.