mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-16 03:32:54 -06:00
Locking the NSG to only operate on one resource at a time in the create
This commit is contained in:
parent
8939ac2256
commit
b6866f2187
@ -97,6 +97,22 @@ func resourceArmVirtualNetworkCreate(d *schema.ResourceData, meta interface{}) e
|
||||
Tags: expandTags(tags),
|
||||
}
|
||||
|
||||
networkSecurityGroupNames := make([]string, 0)
|
||||
for _, subnet := range *vnet.VirtualNetworkPropertiesFormat.Subnets {
|
||||
if subnet.NetworkSecurityGroup != nil {
|
||||
subnetId := *subnet.NetworkSecurityGroup.ID
|
||||
id, err := parseAzureResourceID(subnetId)
|
||||
if err != nil {
|
||||
return fmt.Errorf("[ERROR] Unable to Parse Network Security Group ID '%s': %+v", subnetId, err)
|
||||
}
|
||||
nsgName := id.Path["networkSecurityGroups"]
|
||||
networkSecurityGroupNames = append(networkSecurityGroupNames, nsgName)
|
||||
}
|
||||
}
|
||||
|
||||
azureRMVirtualNetworkLockNetworkSecurityGroups(&networkSecurityGroupNames)
|
||||
defer azureRMVirtualNetworkUnlockNetworkSecurityGroups(&networkSecurityGroupNames)
|
||||
|
||||
_, err := vnetClient.CreateOrUpdate(resGroup, name, vnet, make(chan struct{}))
|
||||
if err != nil {
|
||||
return err
|
||||
@ -182,6 +198,8 @@ func resourceArmVirtualNetworkDelete(d *schema.ResourceData, meta interface{}) e
|
||||
resGroup := id.ResourceGroup
|
||||
name := id.Path["virtualNetworks"]
|
||||
|
||||
// TODO: lock any associated NSG's
|
||||
|
||||
_, err = vnetClient.Delete(resGroup, name, make(chan struct{}))
|
||||
|
||||
return err
|
||||
@ -245,3 +263,14 @@ func resourceAzureSubnetHash(v interface{}) int {
|
||||
}
|
||||
return hashcode.String(subnet)
|
||||
}
|
||||
|
||||
func azureRMVirtualNetworkUnlockNetworkSecurityGroups(networkSecurityGroupNames *[]string) {
|
||||
for _, networkSecurityGroupName := range *networkSecurityGroupNames {
|
||||
armMutexKV.Unlock(networkSecurityGroupName)
|
||||
}
|
||||
}
|
||||
func azureRMVirtualNetworkLockNetworkSecurityGroups(networkSecurityGroupNames *[]string) {
|
||||
for _, networkSecurityGroupName := range *networkSecurityGroupNames {
|
||||
armMutexKV.Lock(networkSecurityGroupName)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user