Lock Route Table / Subnets

This commit is contained in:
Jay Wang 2017-04-14 16:50:46 -07:00
parent c33810f5ce
commit 279b00dd12
2 changed files with 31 additions and 0 deletions

View File

@ -96,6 +96,15 @@ func resourceArmSubnetCreate(d *schema.ResourceData, meta interface{}) error {
properties.RouteTable = &network.RouteTable{
ID: &rtId,
}
routeTableName, err := parseRouteTableName(rtId)
if err != nil {
return err
}
armMutexKV.Lock(routeTableName)
defer armMutexKV.Unlock(routeTableName)
}
subnet := network.Subnet{
@ -182,6 +191,18 @@ func resourceArmSubnetDelete(d *schema.ResourceData, meta interface{}) error {
name := id.Path["subnets"]
vnetName := id.Path["virtualNetworks"]
if v, ok := d.GetOk("route_table_id"); ok {
rtId := v.(string)
routeTableName, err := parseRouteTableName(rtId)
if err != nil {
return err
}
armMutexKV.Lock(routeTableName)
defer armMutexKV.Unlock(routeTableName)
}
armMutexKV.Lock(vnetName)
defer armMutexKV.Unlock(vnetName)

View File

@ -95,3 +95,13 @@ func parseAzureResourceID(id string) (*ResourceID, error) {
return idObj, nil
}
func parseRouteTableName(routeTableId string) (string, error) {
id, err := parseAzureResourceID(routeTableId)
if err != nil {
return "", fmt.Errorf("[ERROR] Unable to parse Route Table ID '%s': %+v", routeTableId, err)
}
return id.Path["routeTables"], nil
}