ALIYUN::ROS::Assert

更新时间:2024-09-02 02:08:23

ALIYUN::ROS::Assert用于创建断言。断言用于验证条件,支持多种操作类型,并允许配置失败时是否终止创建以及返回的错误消息。

语法

{
  "Type": "ALIYUN::ROS::Assert",
  "Properties": {
    "Values": List,
    "AbortCreation": Boolean,
    "ErrorMessage": String,
    "Operation": String
  }
}

属性

属性名称

类型

必须

允许更新

描述

约束

属性名称

类型

必须

允许更新

描述

约束

Values

List

待验证的断言的列表。

列表中的项目按顺序进行比较。列表长度范围为一到三个。

    说明

    仅当操作为“等于”或“不等于”时,才支持三个值的比较。

    仅当操作为“非”时,才支持一个值。

AbortCreation

Boolean

当断言失败时,是否终止创建。

默认值为True。

ErrorMessage

String

当断言失败时要返回的错误消息。

无。

Operation

String

断言的类型。

支持的操作有:

  • Equal:等于(默认值)

  • NotEqual:不等于

  • Greater:大于

  • GreaterOrEqual:大于或等于

  • Less:小于

  • LessOrEqual:小于或等于

  • Contain:包含

  • NotContain:不包含

  • And:与

  • Or:或

  • Not:非

返回值

Fn::GetAtt

  • Result:断言的结果。

  • FailureCause:断言失败的原因。

示例

YAML
JSON
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Values:
    Type: Json
    Description:
      en: |-
        A list of values to assert. The items in the list are compared in order. The range of length is one to three. 
        - Three values are supported only if the operation is Equal or NotEqual.
        - One value is supported only if the operation is Not.
    Required: true
    MinLength: 1
    MaxLength: 3
Resources:
  Assert:
    Type: ALIYUN::ROS::Assert
    Properties:
      Values:
        Ref: Values
Outputs:
  Result:
    Description: The result of the assert.
    Value:
      Fn::GetAtt:
        - Assert
        - Result
  FailureCause:
    Description: The reason the assertion failed
    Value:
      Fn::GetAtt:
        - Assert
        - FailureCause
{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "Values": {
      "Type": "Json",
      "Description": {
        "en": "A list of values to assert. The items in the list are compared in order. The range of length is one to three. \n- Three values are supported only if the operation is Equal or NotEqual.\n- One value is supported only if the operation is Not."
      },
      "Required": true,
      "MinLength": 1,
      "MaxLength": 3
    }
  },
  "Resources": {
    "Assert": {
      "Type": "ALIYUN::ROS::Assert",
      "Properties": {
        "Values": {
          "Ref": "Values"
        }
      }
    }
  },
  "Outputs": {
    "Result": {
      "Description": "The result of the assert.",
      "Value": {
        "Fn::GetAtt": [
          "Assert",
          "Result"
        ]
      }
    },
    "FailureCause": {
      "Description": "The reason the assertion failed",
      "Value": {
        "Fn::GetAtt": [
          "Assert",
          "FailureCause"
        ]
      }
    }
  }
}
                        
  • 本页导读 (1)
  • 语法
  • 属性
  • 返回值
  • 示例