Locking on the NSG ID

This commit is contained in:
tombuildsstuff 2017-04-13 16:28:48 +01:00
parent b93e6e3af7
commit 3ecb0f4fc4
4 changed files with 47 additions and 9 deletions

View File

@ -172,6 +172,14 @@ func resourceArmNetworkInterfaceCreate(d *schema.ResourceData, meta interface{})
properties.NetworkSecurityGroup = &network.SecurityGroup{
ID: &nsgId,
}
networkSecurityGroupName, err := parseNetworkSecurityGroupName(nsgId)
if err != nil {
return err
}
armMutexKV.Lock(networkSecurityGroupName)
defer armMutexKV.Unlock(networkSecurityGroupName)
}
dns, hasDns := d.GetOk("dns_servers")
@ -308,6 +316,17 @@ func resourceArmNetworkInterfaceDelete(d *schema.ResourceData, meta interface{})
resGroup := id.ResourceGroup
name := id.Path["networkInterfaces"]
if v, ok := d.GetOk("network_security_group_id"); ok {
networkSecurityGroupId := v.(string)
networkSecurityGroupName, err := parseNetworkSecurityGroupName(networkSecurityGroupId)
if err != nil {
return err
}
armMutexKV.Lock(networkSecurityGroupName)
defer armMutexKV.Unlock(networkSecurityGroupName)
}
_, err = ifaceClient.Delete(resGroup, name, make(chan struct{}))
return err

View File

@ -89,6 +89,14 @@ func resourceArmSubnetCreate(d *schema.ResourceData, meta interface{}) error {
properties.NetworkSecurityGroup = &network.SecurityGroup{
ID: &nsgId,
}
networkSecurityGroupName, err := parseNetworkSecurityGroupName(nsgId)
if err != nil {
return err
}
armMutexKV.Lock(networkSecurityGroupName)
defer armMutexKV.Unlock(networkSecurityGroupName)
}
if v, ok := d.GetOk("route_table_id"); ok {
@ -182,6 +190,17 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error {
name := id.Path["subnets"]
vnetName := id.Path["virtualNetworks"]
if v, ok := d.GetOk("network_security_group_id"); ok {
networkSecurityGroupId := v.(string)
networkSecurityGroupName, err := parseNetworkSecurityGroupName(networkSecurityGroupId)
if err != nil {
return err
}
armMutexKV.Lock(networkSecurityGroupName)
defer armMutexKV.Unlock(networkSecurityGroupName)
}
armMutexKV.Lock(vnetName)
defer armMutexKV.Unlock(vnetName)

View File

@ -269,15 +269,6 @@ func resourceAzureSubnetHash(v interface{}) int {
return hashcode.String(subnet)
}
func parseNetworkSecurityGroupName(networkSecurityGroupId string) (string, error) {
id, err := parseAzureResourceID(networkSecurityGroupId)
if err != nil {
return "", fmt.Errorf("[ERROR] Unable to Parse Network Security Group ID '%s': %+v", networkSecurityGroupId, err)
}
return id.Path["networkSecurityGroups"], nil
}
func expandAzureRmVirtualNetworkVirtualNetworkSecurityGroupNames(d *schema.ResourceData) ([]string, error) {
nsgNames := make([]string, 0)

View File

@ -95,3 +95,12 @@ func parseAzureResourceID(id string) (*ResourceID, error) {
return idObj, nil
}
func parseNetworkSecurityGroupName(networkSecurityGroupId string) (string, error) {
id, err := parseAzureResourceID(networkSecurityGroupId)
if err != nil {
return "", fmt.Errorf("[ERROR] Unable to Parse Network Security Group ID '%s': %+v", networkSecurityGroupId, err)
}
return id.Path["networkSecurityGroups"], nil
}