This topic was translated by AI and is currently in queue for revision by our editors. Alibaba Cloud does not guarantee the accuracy of AI-translated content. Request expedited revision

Rules

Updated at: 2025-03-27 02:18

Rules verify whether parameter values passed to a template during stack creation or update meet the expected requirements.

Syntax

You can use the keyword Rules to declare template rules in your ROS template.

You can define multiple rules in ROS. Each rule consists of a rule name and a rule description. Use commas to separate multiple rules.

Rules:
  Rule1Name:
    RuleCondition: Rule condition content
    Assertions:
      - Assert: Assertion content
        AssertDescription: Assertion description
      - Assert: Assertion content
        AssertDescription: Assertion description
  Rule2Name:
    Assertions:
      - Assert: Assertion content      
  • RuleCondition (optional): Defines the RuleCondition rule condition. If you do not define the rule condition, the assertions take effect all the time.

  • Assertions: Defines the Assertions list. It consists of multiple Assert and AssertDescription items that describe the assertion content.

    Note

    The Assertions list can contain up to 100 Assert and AssertDescription items.

  • Assert: Defines the content of the Assert assertion.

  • AssertDescription (optional): Defines the AssertDescription assertion description, which provides a prompt to users when the assertion result is false.

Each rule can define at most one RuleCondition. If RuleCondition is not defined or the defined result is true, the Assertions property takes effect. Otherwise, it does not take effect.

If Assert returns true, the rule validation passes, and you can continue to preview, create, and update the stack.

Important

Rule conditions and assertion content do not support referencing Datasource resource types for logical judgments.

Examples

When you create an ECS instance in the production environment, the public bandwidth of the ECS instance must be 0. When you create an ECS instance in the staging environment, the billing method of the ECS instance must be pay-as-you-go.

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 are omitted: null
  • On this page (1)
  • Syntax
  • Examples
Feedback
phone Contact Us