All Products
Search
Document Center

Resource Orchestration Service:Rules

Last Updated:Apr 24, 2025

When you create or update a stack based on a template, you can use the Rules section to check whether the values that are passed to the parameters in the template are valid.

Syntax

You can declare one or more rules in the Rules section of a Resource Orchestration Service (ROS) template.

Each rule consists of a rule name and a rule description. Separate multiple rules with commas (,).

Rules:
  Rule Name 1:
    RuleCondition: the condition of the rule.
    Assertions:
      - Assert: the assertion of the rule.
        AssertDescription: the description of the assertion.
      - Assert: the assertion of the rule.
        AssertDescription: the description of the assertion.
  Rule Name 2:
    Assertions:
      - Assert: the assertion of the rule.      
  • (Optional) RuleCondition: the condition that determines when the rule takes effect. If you leave RuleCondition empty, the assertions of the rule take effect all the time.

  • Assertions: the assertions that declare the values you can specify for a parameter.

    Note

    The Assertions value can contain up to 100 pairs of the Assert and AssertDescription values.

  • Assert: the assertion of the rule.

  • (Optional) AssertDescription: the description of the assertion. The description is prompted if the result of the assertion is false.

You can define only one RuleCondition for each rule. Assertions takes effect only when RuleCondition is left empty or the result of RuleCondition is true.

If the result of Assert is true, the verification for the parameter values is passed. In this case, you can continue to preview, create, and update the stack.

Important

You cannot reference data source types (DataSource resources) in rule conditions and assertions for logical judgment.

Example

In the following example, rules are configured to ensure that the public bandwidth of the Elastic Compute Service (ECS) instance to be created in the production environment is 0 and the pay-as-you-go billing method is used for the ECS instance to be created in the staging environment.

ROSTemplateFormatVersion: '2015-09-01'
Rules:
  PublicNet:
    RuleCondition:
      Fn::Equals:
        - Ref: Environment
        - prod
    Assertions:
      - Assert:
          Fn::Equals:
            - Ref: InternetMaxBandwidthOut
            - 0
        AssertDescription: ECS instance should be intranet when the environment is prod.
  ChargeType:
    RuleCondition:
      Fn::Equals:
        - Ref: Environment
        - pre
    Assertions:
      - Assert:
          Fn::Equals:
            - Ref: InstanceChargeType
            - PayAsYouGo
        AssertDescription: ECS instance should be postpaid when the environment is pre.
Parameters:
  Environment:
    Type: String
    AllowedValues:
      - prod
      - pre
  InternetMaxBandwidthOut:
    Type: Number
    MaxValue: 10
    MinValue: 0
  InstanceChargeType:
    Type: String
    AllowedValues:
      - PayAsYouGo
      - Subscription
Resources:
  ECS:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      InternetMaxBandwidthOut:
        Ref: InternetMaxBandwidthOut
      InstanceChargeType:
        Ref: InstanceChargeType
      #Other properties (omitted here): null.