Search code examples
pythonazuretagsresourcesazure-sdk-python

tag resources azure python sdk - operation merge?


i am trying to figure out how can i tag resources with operation Merge like in PS.

example in powershell -

Update-AzTag -ResourceId $s.ResourceId -Tag $mergedTags -Operation Replace

my code in python -

    # Tag the resource groups.
    resource_group_client.resource_groups.create_or_update(resource_group_name=rg["Resource-group-name"],parameters=
    {'location': rg['location'], 
        'tags':tags_dict,
        'Operation': 'Merge'})

as you can see i am trying my luck to put 'operation' : 'merge' but it dosent work... any help here please?


Solution

  • i have fixed it with this code.. and it worked PERFECT - (you should work with "update_at_scope".

    resource_group_client = ResourceManagementClient(credential, subscription_id=sub.subscription_id)
    
    
             body = {
                 "operation" :  "Merge",
                 "properties" : {
                     "tags" : 
                         tags_dict,
                 }
             }
    
             resource_group_client.tags.update_at_scope(rg["Resource-id"] ,body)