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 theRuleCondition
rule condition. If you do not define the rule condition, the assertions take effect all the time.Assertions
: Defines theAssertions
list. It consists of multipleAssert
andAssertDescription
items that describe the assertion content.The
Assertions
list can contain up to 100Assert
andAssertDescription
items.Assert
: Defines the content of theAssert
assertion.AssertDescription
(optional): Defines theAssertDescription
assertion description, which provides a prompt to users when the assertion result isfalse
.
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.
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