Azure Resource Group Set Tags with SDK?

隐身守侯 提交于 2019-12-22 10:59:45

问题


I have used code similar to http://blogs.infinitesquare.com/b/tranise/archives/-azure-resource-group-une-nouvelle-facon-dorganiser-ses-environnements-dans-azure#.Vr1RrfIrLgk to create a Resource Group in Azure with C#. I am now trying to extend it by putting Tags on the Resource.

Adding resourceGroupGetResult.ResourceGroup.Tags.Add("a","1") works, but a subsequent CreateOrUpdateAsync call fails with

"InvalidRequestContent: The request content was invalid and could not be deserialized: 'Could not find member 'provisioningState' on object of type 'ResourceGroupDefinition'. Path 'provisioningState', line 9, position 23.'."

What is the correct way to add Tags to a Resource Group? Of course I will want to add the same Tags to resources within the Group after this.

Thanks.


回答1:


I assume you're using nuget package id="Microsoft.Azure.Management.Resources" version="3.4.0-preview".

The sample code for adding tag(s) to Azure Resource Group using the ARM .NET SDK above is as below:

var tag = new Dictionary<string, string> {{tagName, tagValue}};
var rg = new ResourceGroup() { Name = rgName, Location = rgLocation, Tags = tag };
await client.ResourceGroups.CreateOrUpdateAsync(rgName, rg);

Note: This code sample should backward-compatible with older release version of the above-mentioned nuget package.

Hope this helps!



来源:https://stackoverflow.com/questions/35354412/azure-resource-group-set-tags-with-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!