modules/mu/clouds/azure/vpc.rb in cloud-mu-3.0.0beta vs modules/mu/clouds/azure/vpc.rb in cloud-mu-3.0.0

- old
+ new

@@ -492,23 +492,33 @@ # tags, do that with .update_tags if !ext_vpc MU.log "Creating VPC #{@mu_name} (#{@config['ip_block']}) in #{@config['region']}", details: vpc_obj need_apply = true elsif ext_vpc.location != vpc_obj.location or - ext_vpc.tags != vpc_obj.tags or +# ext_vpc.tags != vpc_obj.tags or +# XXX updating tags is a different API call ext_vpc.address_space.address_prefixes != vpc_obj.address_space.address_prefixes MU.log "Updating VPC #{@mu_name} (#{@config['ip_block']}) in #{@config['region']}", MU::NOTICE, details: vpc_obj +MU.structToHash(ext_vpc).diff(MU.structToHash(vpc_obj)) need_apply = true end if need_apply - resp = MU::Cloud::Azure.network(credentials: @config['credentials']).virtual_networks.create_or_update( - @resource_group, - @mu_name, - vpc_obj - ) - @cloud_id = Id.new(resp.id) + begin + resp = MU::Cloud::Azure.network(credentials: @config['credentials']).virtual_networks.create_or_update( + @resource_group, + @mu_name, + vpc_obj + ) + @cloud_id = Id.new(resp.id) + rescue ::MU::Cloud::Azure::APIError => e + if e.message.match(/InUseSubnetCannotBeDeleted: /) + MU.log "Cannot delete an in-use Azure subnet", MU::WARN + else + raise e + end + end end # this is slow, so maybe thread it rtb_map = {} routethreads = [] @@ -674,20 +684,29 @@ elsif (!ext_subnet.route_table.nil? and !subnet_obj.route_table.nil? and ext_subnet.route_table.id != subnet_obj.route_table.id) or ext_subnet.address_prefix != subnet_obj.address_prefix or ext_subnet.network_security_group.nil? and !subnet_obj.network_security_group.nil? or (!ext_subnet.network_security_group.nil? and !subnet_obj.network_security_group.nil? and ext_subnet.network_security_group.id != subnet_obj.network_security_group.id) MU.log "Updating Subnet #{subnet_name} in VPC #{@mu_name}", MU::NOTICE, details: subnet_obj +MU.structToHash(ext_subnet).diff(MU.structToHash(subnet_obj)) need_apply = true end if need_apply - MU::Cloud::Azure.network(credentials: @config['credentials']).subnets.create_or_update( - @resource_group, - @cloud_id.to_s, - subnet_name, - subnet_obj - ) + begin + MU::Cloud::Azure.network(credentials: @config['credentials']).subnets.create_or_update( + @resource_group, + @cloud_id.to_s, + subnet_name, + subnet_obj + ) + rescue ::MU::Cloud::Azure::APIError => e + if e.message.match(/InUseSubnetCannotBeUpdated: /) + MU.log "Cannot alter an in-use Azure subnet", MU::WARN + else + raise e + end + end end } } subnetthreads.each { |t|