在资源或订阅上创建或更新整个标记集。
此操作允许在指定资源或订阅上添加或替换整个标记集。 指定的实体最多可以有 50 个标记。
PUT https://management.azure.com/{scope}/providers/Microsoft.Resources/tags/default?api-version=2021-04-01
URI 参数
名称 |
在 |
必需 |
类型 |
说明 |
scope
|
path |
True
|
string
|
资源范围。
|
api-version
|
query |
True
|
string
|
要用于此操作的 API 版本。
|
请求正文
名称 |
必需 |
类型 |
说明 |
properties
|
True
|
Tags
|
标记集。
|
响应
安全性
azure_auth
Azure Active Directory OAuth2 流
Type:
oauth2
Flow:
implicit
Authorization URL:
https://login.microsoftonline.com/common/oauth2/authorize
Scopes
名称 |
说明 |
user_impersonation
|
模拟用户帐户
|
示例
Sample Request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm/providers/Microsoft.Resources/tags/default?api-version=2021-04-01
{
"properties": {
"tags": {
"tagKey1": "tag-value-1",
"tagKey2": "tag-value-2"
}
}
}
package armresources_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/PutTagsResource.json
func ExampleTagsClient_CreateOrUpdateAtScope_updateTagsOnAResource() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresources.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewTagsClient().CreateOrUpdateAtScope(ctx, "subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm", armresources.TagsResource{
Properties: &armresources.Tags{
Tags: map[string]*string{
"tagKey1": to.Ptr("tag-value-1"),
"tagKey2": to.Ptr("tag-value-2"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.TagsResource = armresources.TagsResource{
// Properties: &armresources.Tags{
// Tags: map[string]*string{
// "tagKey1": to.Ptr("tag-value-1"),
// "tagKey2": to.Ptr("tag-value-2"),
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceManagementClient } = require("@azure/arm-resources");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to This operation allows adding or replacing the entire set of tags on the specified resource or subscription. The specified entity can have a maximum of 50 tags.
*
* @summary This operation allows adding or replacing the entire set of tags on the specified resource or subscription. The specified entity can have a maximum of 50 tags.
* x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/PutTagsResource.json
*/
async function updateTagsOnAResource() {
const subscriptionId =
process.env["RESOURCES_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope =
"subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/my-resource-group/providers/myPRNameSpace/VM/myVm";
const parameters = {
properties: { tags: { tagKey1: "tag-value-1", tagKey2: "tag-value-2" } },
};
const credential = new DefaultAzureCredential();
const client = new ResourceManagementClient(credential, subscriptionId);
const result = await client.tagsOperations.createOrUpdateAtScope(scope, parameters);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample Response
{
"properties": {
"tags": {
"tagKey1": "tag-value-1",
"tagKey2": "tag-value-2"
}
}
}
Sample Request
PUT https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Resources/tags/default?api-version=2021-04-01
{
"properties": {
"tags": {
"tagKey1": "tag-value-1",
"tagKey2": "tag-value-2"
}
}
}
package armresources_test
import (
"context"
"log"
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources"
)
// Generated from example definition: https://github.com/Azure/azure-rest-api-specs/blob/4fd842fb73656039ec94ce367bcedee25a57bd18/specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/PutTagsSubscription.json
func ExampleTagsClient_CreateOrUpdateAtScope_updateTagsOnASubscription() {
cred, err := azidentity.NewDefaultAzureCredential(nil)
if err != nil {
log.Fatalf("failed to obtain a credential: %v", err)
}
ctx := context.Background()
clientFactory, err := armresources.NewClientFactory("<subscription-id>", cred, nil)
if err != nil {
log.Fatalf("failed to create client: %v", err)
}
res, err := clientFactory.NewTagsClient().CreateOrUpdateAtScope(ctx, "subscriptions/00000000-0000-0000-0000-000000000000", armresources.TagsResource{
Properties: &armresources.Tags{
Tags: map[string]*string{
"tagKey1": to.Ptr("tag-value-1"),
"tagKey2": to.Ptr("tag-value-2"),
},
},
}, nil)
if err != nil {
log.Fatalf("failed to finish the request: %v", err)
}
// You could use response here. We use blank identifier for just demo purposes.
_ = res
// If the HTTP response code is 200 as defined in example definition, your response structure would look as follows. Please pay attention that all the values in the output are fake values for just demo purposes.
// res.TagsResource = armresources.TagsResource{
// Properties: &armresources.Tags{
// Tags: map[string]*string{
// "tagKey1": to.Ptr("tag-value-1"),
// "tagKey2": to.Ptr("tag-value-2"),
// },
// },
// }
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
const { ResourceManagementClient } = require("@azure/arm-resources");
const { DefaultAzureCredential } = require("@azure/identity");
/**
* This sample demonstrates how to This operation allows adding or replacing the entire set of tags on the specified resource or subscription. The specified entity can have a maximum of 50 tags.
*
* @summary This operation allows adding or replacing the entire set of tags on the specified resource or subscription. The specified entity can have a maximum of 50 tags.
* x-ms-original-file: specification/resources/resource-manager/Microsoft.Resources/stable/2021-04-01/examples/PutTagsSubscription.json
*/
async function updateTagsOnASubscription() {
const subscriptionId =
process.env["RESOURCES_SUBSCRIPTION_ID"] || "00000000-0000-0000-0000-000000000000";
const scope = "subscriptions/00000000-0000-0000-0000-000000000000";
const parameters = {
properties: { tags: { tagKey1: "tag-value-1", tagKey2: "tag-value-2" } },
};
const credential = new DefaultAzureCredential();
const client = new ResourceManagementClient(credential, subscriptionId);
const result = await client.tagsOperations.createOrUpdateAtScope(scope, parameters);
console.log(result);
}
To use the Azure SDK library in your project, see this documentation. To provide feedback on this code sample, open a GitHub issue
Sample Response
{
"properties": {
"tags": {
"tagKey1": "tag-value-1",
"tagKey2": "tag-value-2"
}
}
}
定义
CloudError
资源管理请求的错误响应。
名称 |
类型 |
说明 |
error
|
ErrorResponse
|
错误响应
对所有 Azure 资源管理器 API 的常见错误响应,可返回失败操作的错误详细信息。 (这也遵循 OData 错误响应格式。)
|
ErrorAdditionalInfo
资源管理错误附加信息。
名称 |
类型 |
说明 |
info
|
object
|
其他信息。
|
type
|
string
|
其他信息类型。
|
ErrorResponse
错误响应
名称和值对字典。
标记 API 请求和响应的包装器资源。
名称 |
类型 |
说明 |
id
|
string
|
标记包装资源的 ID。
|
name
|
string
|
标记包装器资源的名称。
|
properties
|
Tags
|
标记集。
|
type
|
string
|
标记包装器资源的类型。
|