how to use operation Merge/Replce/Delete in azure python for tagging?

Yahav Horev | CloudTeam.ai 136 Reputation points
2021-08-19T10:23:12.507+00:00

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?

Azure Stack Hub
Azure Stack Hub
An extension of Azure for running apps in an on-premises environment and delivering Azure services in a datacenter.
180 questions
{count} votes

Accepted answer
  1. Yahav Horev | CloudTeam.ai 136 Reputation points
    2021-08-25T14:58:24.387+00:00

    hey , i have been fixed it with this way :

    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)
    

    the only way i found it work is to use "ResourceManagementClient" under tags.update_at_scope library .

    0 comments No comments

0 additional answers

Sort by: Most helpful