除了 Cloud Assembly 中的简单条件列表之外,还可以使用高级编辑器汇编更复杂的条件表达式,以控制操作何时可用。
创建新的资源操作时,请选择需要条件和使用高级编辑器。然后,输入所需的条件表达式。
表达式是一个子句或子句列表,每个子句均采用键-运算符-值格式。上图显示了目标必须打开电源和存在的条件。
子句
| 子句 | 说明 | 示例 |
|---|---|---|
| 和 | 所有子子句都需要为 true,表达式结果才为 true。 | 仅当 properties.powerState 为 ON 且 syncStatus 不为 MISSING 时,才会评估为 true。 matchExpression:
- and:
- key: properties.powerState
operator: eq
value: ON
- key: syncStatus
operator: notEq
value: MISSING
|
| 或 | 一个或多个子子句需要为 true,表达式结果才为 true。 | 无论 properties.powerState 为 ON 还是 OFF,都评估为 true。 matchExpression:
- or:
- key: properties.powerState
operator: eq
value: ON
- key: properties.powerState
operator: eq
value: OFF
|
运算符
| 运算符 | 说明 | 示例 |
|---|---|---|
| eq | 等于。查找完全匹配项。 | 当 properties.powerState 为 ON 时,评估为 true。 matchExpression:
- and:
- key: properties.powerState
operator: eq
value: ON
|
| notEq | 不等于。避免完全匹配项。 | 当 properties.powerState 为 OFF 时,评估为 true。 matchExpression:
- and:
- key: properties.powerState
operator: notEq
value: OFF
|
| hasAny | 在对象集合中查找匹配项。 | 当 storage.disks 数组包含 100 IOPS EBS 对象时,评估为 true。 matchExpression:
- key: storage.disks
operator: hasAny
value:
matchExpression:
- and:
- key: iops
operator: eq
value: 100
- key: service
operator: eq
value: ebs
|
| in | 在一组值中查找匹配项。 | 当 properties.powerState 为 OFF 或 SUSPEND 时,评估为 true。 matchExpression:
- and:
- key: properties.powerState
operator: in
value: OFF, SUSPEND
|
| notIn | 避免匹配一组值。 | 当 properties.powerState 既不为 OFF 也不为 SUSPEND 时,评估为 true。 matchExpression:
- and:
- key: properties.powerState
operator: notIn
value: OFF, SUSPEND
|
| greaterThan | 查找大于给定阈值的匹配项。仅适用于数字值。 | 当 storage.disks 数组中的第一个对象的 IOPS 大于 50 时,评估为 true。 matchExpression:
- and:
- key: storage.disks[0].iops
operator: greaterThan
value: 50
|
| lessThan | 查找小于给定阈值的匹配项。仅适用于数字值。 | 当 storage.disks 数组中的第一个对象的 IOPS 小于 200 时,评估为 true。 matchExpression:
- and:
- key: storage.disks[0].iops
operator: lessThan
value: 200
|
| greaterThanEquals | 查找等于或大于给定阈值的匹配项。仅适用于数字值。 | 当 storage.disks 数组中的第一个对象的 IOPS 等于或大于 100 时,评估为 true。 matchExpression:
- and:
- key: storage.disks[0].iops
operator: greaterThanEquals
value: 100
|
| lessThanEquals | 查找等于或小于给定阈值的匹配项。仅适用于数字值。 | 当 storage.disks 数组中的第一个对象的 IOPS 等于或小于 100 时,评估为 true。 matchExpression:
- and:
- key: storage.disks[0].iops
operator: lessThanEquals
value: 100
|
| matchesRegex | 使用正则表达式查找匹配项。 | 当 properties.zone 为 us-east-1a 或 us-east-1c 时,评估为 true。 matchExpression:
- and:
- key: properties.zone
operator: matchesRegex
value: (us-east-1)+(a|c){1,2}
|
示例
当 properties.tags 包括键为 key1 且值为 value1 的标记时,以下条件表达式评估为 true。
外部表达式使用 hasAny,因为 properties.tags 是一个数组,且您希望只要 key1=value1 出现在数组中的任何键-值对中,就评估为 true。
在内部表达式中,有两个子句,一个用于键字段,另一个用于值字段。properties.tags 数组包含键-值标记对,您需要同时匹配键字段和值字段。
matchExpression:
- key: properties.tags
operator: hasAny
value:
matchExpression:
- and:
- key: key
operator: eq
value: key1
- key: value
operator: eq
value: value1
以下条件表达式与前一个示例类似,但现在,只要 properties.tags 包括 key1=value1 或 key2=value2 的标记,就评估为 true。
matchExpression:
- or:
- key: properties.tags
operator: hasAny
value:
matchExpression:
- and:
- key: key
operator: eq
value: key1
- key: value
operator: eq
value: value1
- key: properties.tags
operator: hasAny
value:
matchExpression:
- and:
- key: key
operator: eq
value: key2
- key: value
operator: eq
value: value2