1

I'm trying to move a large number of Azure Resources from Azure Resource Group to Azure Resource Group.

My code looks like this:

for i in resource_client.resources.list(filter=f"tagName eq 'run_id' and tagValue eq '{RUN_ID}'"): 
    print_item(i)
    ids.append(i.id)

targetRG = resource_client.resource_groups.get(resource_group_name=DELETE_GROUP_NAME)

for id in ids:
    try:
        poller = resource_client.resources.move_resources(source_resource_group_name=SOURCE_GROUP_NAME, target_resource_group=targetRG.id, resources=id)                           
        rg_move_result = poller.result()
    except:
        pass

I'd PREFER not to have the second loop, and just do it in bulk, but if there are any errors in the move, it fails. Is there a way to do all this and just skip errors?

aronchick
  • 6,786
  • 9
  • 48
  • 75

1 Answers1

0

Basically, you can try to use below structure of code to acheive that you want:

for xxx:
    try:
        #Move single resource in this place.
    except:
        #Use continue to out and continue the loop.
        continue

By the way, if you check the source code, the type of 'resources' in 'move_resources()' should be list type.

Cindy Pau
  • 13,085
  • 1
  • 15
  • 27
  • Gotcha - I guess what I was looking for is a way to tell Azure to do it to attempt to do everything, and just skip (or report errors) for just the ones that don't work. – aronchick Aug 27 '20 at 04:03
  • @aronchick Hi, I am not sure about the meaning of gotcha... Is my answer what you want? – Cindy Pau Aug 27 '20 at 07:37
  • I just meant I understand, but my code already did this. What I'm looking for is something, native to azure (not in python) that accepts a set of bulk commands and executed them all, skipping over any errors (but reporting them at the end). – aronchick Aug 28 '20 at 18:14