Skip to content
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 - Remove internal lock on subnet while processing private endpoint #26006

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
8 changes: 0 additions & 8 deletions internal/services/network/private_endpoint_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ func resourcePrivateEndpointCreate(d *pluginsdk.ResourceData, meta interface{})
}

privateDnsZoneGroup := d.Get("private_dns_zone_group").([]interface{})
subnetId := d.Get("subnet_id").(string)

parameters := privateendpoints.PrivateEndpoint{
Location: pointer.To(location.Normalize(d.Get("location").(string))),
Expand Down Expand Up @@ -349,8 +348,6 @@ 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")

err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
if err = client.CreateOrUpdateThenPoll(ctx, id, parameters); err != nil {
Expand Down Expand Up @@ -510,9 +507,6 @@ func resourcePrivateEndpointUpdate(d *pluginsdk.ResourceData, meta interface{})
return err
}

locks.ByName(subnetId, "azurerm_private_endpoint")
defer locks.UnlockByName(subnetId, "azurerm_private_endpoint")

err = pluginsdk.Retry(d.Timeout(pluginsdk.TimeoutCreate), func() *pluginsdk.RetryError {
if err = client.CreateOrUpdateThenPoll(ctx, *id, parameters); err != nil {
switch {
Expand Down Expand Up @@ -740,8 +734,6 @@ 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 %s", id)
if err = client.DeleteThenPoll(ctx, *id); err != nil {
Expand Down
37 changes: 31 additions & 6 deletions internal/services/network/private_endpoint_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,26 @@ func TestAccPrivateEndpoint_multipleInstances(t *testing.T) {
checks = append(checks, check.That(fmt.Sprintf("%s.%d", data.ResourceName, i)).ExistsInAzure(r))
}

config := r.multipleInstances(data, instanceCount)
config := r.multipleInstances(data, instanceCount, false)
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: config,
Check: acceptance.ComposeTestCheckFunc(checks...),
},
})
}

func TestAccPrivateEndpoint_multipleInstancesWithLinkAlias(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_private_endpoint", "test")
r := PrivateEndpointResource{}

instanceCount := 5
var checks []pluginsdk.TestCheckFunc
for i := 0; i < instanceCount; i++ {
checks = append(checks, check.That(fmt.Sprintf("%s.%d", data.ResourceName, i)).ExistsInAzure(r))
}

config := r.multipleInstances(data, instanceCount, true)
data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: config,
Expand Down Expand Up @@ -905,7 +924,13 @@ resource "azurerm_private_endpoint" "test" {
`, r.template(data, r.serviceAutoApprove(data)), data.RandomInteger, tags)
}

func (r PrivateEndpointResource) multipleInstances(data acceptance.TestData, count int) string {
func (r PrivateEndpointResource) multipleInstances(data acceptance.TestData, count int, useAlias bool) string {
privateConnectionAssignment := "private_connection_resource_id = azurerm_private_link_service.test.id"
if useAlias {
privateConnectionAssignment = `private_connection_resource_alias = azurerm_private_link_service.test.alias
request_message = "test"`
}

return fmt.Sprintf(`
%s

Expand All @@ -917,12 +942,12 @@ resource "azurerm_private_endpoint" "test" {
subnet_id = azurerm_subnet.endpoint.id

private_service_connection {
name = azurerm_private_link_service.test.name
is_manual_connection = false
private_connection_resource_id = azurerm_private_link_service.test.id
name = azurerm_private_link_service.test.name
is_manual_connection = %t
%s
}
}
`, r.template(data, r.serviceAutoApprove(data)), count, data.RandomInteger)
`, r.template(data, r.serviceAutoApprove(data)), count, data.RandomInteger, useAlias, privateConnectionAssignment)
}

func (r PrivateEndpointResource) recoveryServiceVaultWithMultiIpConfig(data acceptance.TestData) string {
Expand Down
Loading