すべてのプロダクト
Search
ドキュメントセンター

Resource Orchestration Service:ルール

最終更新日:Apr 25, 2025

テンプレートに基づいてスタックを作成または更新するときに、Rules セクションを使用して、テンプレートのパラメーターに渡される値が有効かどうかを確認できます。

構文

Resource Orchestration Service (ROS) テンプレートの Rules セクションで、1 つ以上のルールを宣言できます。

各ルールは、ルール名とルールの説明で構成されます。複数のルールはコンマ (,) で区切ります。

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.      // ルールのアサーション
  • (オプション) RuleCondition: ルールが有効になる条件。 RuleCondition を空のままにすると、ルールのアサーションは常に有効になります。

  • Assertions: パラメーターに指定できる値を宣言するアサーション。

    説明

    Assertions 値には、最大 100 組の Assert 値と AssertDescription 値を含めることができます。

  • Assert: ルールのアサーション。

  • (オプション) AssertDescription: アサーションの説明。アサーションの結果が false の場合、説明が表示されます。

ルールごとに RuleCondition を 1 つだけ定義できます。Assertions は、RuleCondition が空であるか、RuleCondition の結果が true の場合にのみ有効になります。

Assert の結果が true の場合、パラメーター値の検証は合格です。この場合、スタックのプレビュー、作成、更新を続行できます。

重要

論理判断のために、ルール条件およびアサーションでデータソースタイプ (DataSource リソース) を参照することはできません。

次の例では、本番環境で作成される Elastic Compute Service (ECS) インスタンスのパブリック帯域幅が 0 であり、ステージング環境で作成される ECS インスタンスに 従量課金 方式が使用されるようにルールが構成されています。

ROSTemplateFormatVersion: '2015-09-01'
Rules:
  PublicNet:
    RuleCondition:
      Fn::Equals:
        - Ref: Environment
        - prod // prod 環境の場合
    Assertions:
      - Assert:
          Fn::Equals:
            - Ref: InternetMaxBandwidthOut
            - 0
        AssertDescription: ECS instance should be intranet when the environment is prod. // 環境が prod の場合、ECS インスタンスはイントラネットである必要があります。
  ChargeType:
    RuleCondition:
      Fn::Equals:
        - Ref: Environment
        - pre // pre 環境の場合
    Assertions:
      - Assert:
          Fn::Equals:
            - Ref: InstanceChargeType
            - PayAsYouGo
        AssertDescription: ECS instance should be postpaid when the environment is pre. // 環境が pre の場合、ECS インスタンスは後払いである必要があります。
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. // その他のプロパティ (ここでは省略): null