Skip to content

Commit 6bba7b9

Browse files
authored
Fix hashicorp#14152 by adding lock to avoid parallel race error on service side (hashicorp#14160)
As hashicorp#14152 described, when create multiple azurerm_network_watcher_flow_log with same network_security_group_id, the service side would complain a "AnotherOperationInProgress". This patch add an internal lock on nsg id to avoid this issue. AccTest (The failed test also failed on main branch so I guess it's ok for this patch):
1 parent 1c3cbbf commit 6bba7b9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

internal/services/network/network_watcher_flow_log_resource.go

+7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/hashicorp/go-azure-helpers/resourcemanager/location"
1010
"github.com/hashicorp/terraform-provider-azurerm/helpers/azure"
1111
"github.com/hashicorp/terraform-provider-azurerm/internal/clients"
12+
"github.com/hashicorp/terraform-provider-azurerm/internal/locks"
1213
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/parse"
1314
"github.com/hashicorp/terraform-provider-azurerm/internal/services/network/validate"
1415
"github.com/hashicorp/terraform-provider-azurerm/internal/tags"
@@ -183,6 +184,9 @@ func resourceNetworkWatcherFlowLogCreateUpdate(d *pluginsdk.ResourceData, meta i
183184
nsgId, _ := parse.NetworkSecurityGroupID(networkSecurityGroupID)
184185
id := parse.NewFlowLogID(subscriptionId, resourceGroupName, networkWatcherName, *nsgId)
185186

187+
locks.ByID(nsgId.ID())
188+
defer locks.UnlockByID(nsgId.ID())
189+
186190
loc := d.Get("location").(string)
187191
if loc == "" {
188192
// Get the containing network watcher in order to reuse its location if the "location" is not specified.
@@ -296,6 +300,9 @@ func resourceNetworkWatcherFlowLogDelete(d *pluginsdk.ResourceData, meta interfa
296300
return err
297301
}
298302

303+
locks.ByID(id.NetworkSecurityGroupID())
304+
defer locks.UnlockByID(id.NetworkSecurityGroupID())
305+
299306
future, err := client.Delete(ctx, id.ResourceGroupName, id.NetworkWatcherName, id.Name())
300307
if err != nil {
301308
return fmt.Errorf("deleting %s: %v", id, err)

0 commit comments

Comments
 (0)