首页 资源管理 资源组 开发参考 API参考 API目录 资源组 CreateAutoGroupingRule - 创建自动转组规则

CreateAutoGroupingRule - 创建自动转组规则

更新时间: 2025-02-26 17:15:25

调用CreateAutoGroupingRule创建自动转组规则。支持自定义转组规则和关联资源跟随转组规则两类。

接口说明

自定义转组规则最多创建 10 个,每个自定义转组规则支持最多 10 条规则内容。

调试

您可以在OpenAPI Explorer中直接运行该接口,免去您计算签名的困扰。运行成功后,OpenAPI Explorer可以自动生成SDK代码示例。

授权信息

下表是API对应的授权信息,可以在RAM权限策略语句的Action元素中使用,用来给RAM用户或RAM角色授予调用此API的权限。具体说明如下:

  • 操作:是指具体的权限点。
  • 访问级别:是指每个操作的访问级别,取值为写入(Write)、读取(Read)或列出(List)。
  • 资源类型:是指操作中支持授权的资源类型。具体说明如下:
    • 对于必选的资源类型,用前面加 * 表示。
    • 对于不支持资源级授权的操作,用全部资源表示。
  • 条件关键字:是指云产品自身定义的条件关键字。
  • 关联操作:是指成功执行操作所需要的其他权限。操作者必须同时具备关联操作的权限,操作才能成功。
操作访问级别资源类型条件关键字关联操作
resourcemanager:CreateAutoGroupingRulecreate
*全部资源
*

请求参数

名称类型必填描述示例值
RuleNamestring

规则名称。

A项目线上资源自动转组规则
RuleDescstring

规则描述。

带有标签 {"env": "online"} 和 {"project": "A"} 的资源转移到资源组 rg-aek2********qcy
RuleTypestring

规则类型。取值:

  • custom_condition:自定义转组规则。
  • associated_transfer:关联资源跟随转组规则。
custom_condition
RuleContentsarray<object>

规则内容列表。

object

规则内容。

AutoGroupingScopeConditionstring

自动转组范围条件,用于指定需要自动转组的资源范围。

{"children":[{"desired":"{\"env\":\"online\", \"project\":\"A\"}","featurePath":"$.tags","featureSource":"RESOURCE","operator":"TagMatchAll"}],"operator":"and"}
TargetResourceGroupConditionstring

目标资源组条件,用于指定自动分组的目标资源组。

{"children":[{"desired":"rg-aek2********qcy","featurePath":"$.resourceGroupId","featureSource":"RESOURCE","operator":"StringEquals"}],"operator":"and"}
ResourceGroupIdsScopestring

资源组 ID 范围,多个资源组 ID 用半角逗号(,)分隔。

rg-aekz******4b5ea,rg-aek2******fxykq
ExcludeResourceGroupIdsScopestring

资源组 ID 排除范围,多个资源组 ID 用半角逗号(,)分隔。

rg-aekz******zj2oi,rg-aekz******r62ua
RegionIdsScopestring

地域 ID 范围,多个地域 ID 用半角逗号(,)分隔。

cn-hangzhou,cn-shanghai
ExcludeRegionIdsScopestring

地域 ID 排除范围,多个地域 ID 用半角逗号(,)分隔。

cn-beijing,cn-guangzhou
ResourceIdsScopestring

资源 ID 范围,多个资源 ID 用半角逗号(,)分隔。

i-2zee******ym49kfmwis,vpc-5ts6******fnw493g849a
ExcludeResourceIdsScopestring

资源 ID 排除范围,多个资源 ID 用半角逗号(,)分隔。

pc-uf6p******4h784y,rmq-cn-******ny0y
ResourceTypesScopestring

资源类型范围,多个资源类型用半角逗号(,)分隔。

rds.dbinstance,oss.bucket
ExcludeResourceTypesScopestring

资源类型排除范围,多个资源类型用半角逗号(,)分隔。

mse.cluster,slb.loadbalancer

示例 1:根据资源标签自动转组

{
  "RuleName": "A 项目线上资源自动转组",
  "RuleDesc": "带有标签 {\"env\": \"online\"} 和 {\"project\": \"A\"} 的资源转移到资源组 rg-aek2********qcy",
  "RuleType": "custom_condition",
  "RuleContents": [
    {
      "AutoGroupingScopeCondition": "{\"children\":[{\"desired\":\"{\\\"env\\\":\\\"online\\\", \\\"project\\\":\\\"A\\\"}\",\"featurePath\":\"$.tags\",\"featureSource\":\"RESOURCE\",\"operator\":\"TagMatchAll\"}],\"operator\":\"and\"}",
      "TargetResourceGroupCondition": "{\"children\":[{\"desired\":\"rg-aek2********qcy\",\"featurePath\":\"$.resourceGroupId\",\"featureSource\":\"RESOURCE\",\"operator\":\"StringEquals\"}],\"operator\":\"and\"}"
    }
  ]
}

示例 2:云盘跟随 ECS 实例转组

{
  "RuleName": "云盘跟随 ECS 实例转组",
  "RuleDesc": "当云盘挂载到 ECS 实例或 ECS 实例转组时,与之关联的云盘将自动转入关联 ECS 实例所在的资源组",
  "RuleType": "associated_transfer",
  "ResourceTypesScope": "ecs.disk",
  "RuleContents": [
    {
      "TargetResourceGroupCondition": "{\"desired\":\"$.ResourceGroupId\",\"desiredSource\":\"RESOURCE_RELATIONSHIP_ACS::ECS::Instance\",\"featurePath\":\"$.ResourceGroupId\",\"featureSource\":\"CONFIGURATION\",\"operator\":\"StringEquals\"}"
    }
  ]
}

返回参数

名称类型描述示例值
object

返回结果。

RequestIdstring

请求 ID。

F7701451-340B-5CB3-AEA7-7D831F7F38C0
RuleIdstring

规则 ID。

gr-acfo******hy6a

示例

正常返回示例

JSON格式

{
  "RequestId": "F7701451-340B-5CB3-AEA7-7D831F7F38C0",
  "RuleId": "gr-acfo******hy6a"
}

错误码

HTTP status code错误码错误信息描述
400Invalid.AssociatedTransferRule.AlreadyExistedThe associated transfer rule already exists.关联转组规则已经存在。
400InvalidParameter.ResourceTypesScopeThe parameter ResourceTypesScope is invalid.参数ResourceTypesScope无效。
400InvalidParameter.ExcludeResourceTypesScopeThe parameter ExcludeResourceTypesScope is invalid.参数ExcludeResourceTypesScope无效。
400InvalidParameter.ResourceGroupIdsScopeThe parameter ResourceGroupIdsScope is invalid.参数ResourceGroupIdsScope无效。
400InvalidParameter.ExcludeResourceGroupIdsScopeThe parameter ExcludeResourceGroupIdsScope is invalid.参数ExcludeResourceGroupIdsScope无效。
400InvalidParameterCombination.BothRegionIdScopesThe combination of parameters RegionIdsScope and ExcludeRegionIdsScope is not allowed. Please select only one of these parameters.RegionIdsScope和ExcludeRegionIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400InvalidParameterCombination.BothResourceGroupIdScopesThe combination of parameters ResourceGroupIdsScope and ExcludeResourceGroupIdsScope is not allowed. Please select only one of these parameters.ResourceGroupIdsScope和ExcludeResourceGroupIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400InvalidParameterCombination.BothResourceIdScopesThe combination of parameters ResourceIdsScope and ExcludeResourceIdsScope is not allowed. Please select only one of these parameters.ResourceIdsScope和ExcludeResourceIdsScope是互斥的。同一个请求中只能指定其中一个参数。
400InvalidParameterCombination.BothResourceTypeScopesThe combination of parameters ResourceTypesScope and ExcludeResourceTypesScope is not allowed. Please select only one of these parameters.ResourceTypesScope和ExcludeResourceTypesScope是互斥的。同一个请求中只能指定其中一个参数。
400InvalidParameter.RuleContentsThe parameter RuleContents is invalid.RuleContents 参数非法。
400MissingParameter.RuleContentsThe parameter RuleContents is required.RuleContents是必要参数。
409AutoGroupingNotEnabledThe auto grouping is disabled.自动转组已禁用。
409QuotaExceeded.RuleContentThe number of rule contents exceeds the quota.创建的分组条件内容数量超过限制。
409QuotaExceeded.GroupingRuleThe number of grouping rules exceeds the quota.分组条件数量超过限制。

访问错误中心查看更多错误码。

上一篇: GetAutoGroupingStatus - 查询自动转组状态 下一篇: DeleteAutoGroupingRule - 删除自动转组规则