All Products
Search
Document Center

Resource Orchestration Service:Conditions

Last Updated:Jun 10, 2026

Use the Conditions section to define conditional logic that controls whether resources, properties, and outputs are created. Define condition statements with Fn::And, Fn::Or, Fn::Not, or Fn::Equals — referencing parameters, mappings, or other conditions — then associate each condition with resources or outputs using the Condition key or Fn::If.

Syntax

How conditions work

To use conditions in a template, follow these steps:

  1. Define input parameters — Declare the values your conditions will evaluate in the Parameters section.

  2. Define conditions — Write condition statements in the Conditions section using the supported condition functions listed below. Each condition name must be unique and is of the String type. Conditions can reference other conditions.

  3. Associate conditions with resources or outputs — Reference conditions in the Resources section (via Condition key or Fn::If) and in the Outputs section (via Condition key) to control what gets created.

Condition functions

Use the following functions to define condition statements:

The following functions are supported inside condition statements but cannot be the outermost function in a condition:

Fn::Select, Fn::Join, Fn::Split, Fn::Replace, Fn::Base64Encode, Fn::Base64Decode, Fn::MemberListToMap, Fn::If, Fn::ListMerge, Fn::GetJsonValue, Fn::MergeMapToList, Fn::SelectMapList, Fn::Add, Fn::Avg, Fn::Str, Fn::Calculate, Ref (parameter references only), and Fn::FindInMap.

Examples

  • Define conditions

    The following example defines four conditions based on an EnvType parameter. DevEnv and UTEnv each check for a specific environment value. PREEnv is true when neither DevEnv nor UTEnv is true. ProdEnv combines an equality check with PREEnv using Fn::And, showing how to compose conditions from other conditions.

    Conditions:
      DevEnv:
        Fn::Equals:
          - Dev
          - Ref: EnvType
      UTEnv:
        Fn::Equals:
          - UT
          - Ref: EnvType
      PREEnv:
        Fn::Not:
          Fn::Or:
            - DevEnv
            - UTEnv
      ProdEnv:
        Fn::And:
          - Fn::Equals:
              - Prod
              - Ref: EnvType
          - PREEnv         
  • Associate conditions with resources and outputs

    The following example uses EnvType to control resource creation. When EnvType is prod, the template creates data disks for the Elastic Compute Service (ECS) instance and provisions an Object Storage Service (OSS) bucket. When EnvType is any other value, neither the data disks nor the OSS bucket are created, and the corresponding output is suppressed. The example demonstrates three ways to use a condition: - Fn::If on a property value — Conditionally sets DiskMappings on the ECS instance (WebServer). - Condition key on a resource — Gates creation of the entire OssBucket resource. - Condition key on an output — Suppresses OssDomain when the bucket does not exist.

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      EnvType:
        Default: pre
        Type: String
    Conditions:
      CreateProdRes:
        Fn::Equals:
          - prod
          - Ref: EnvType
    Resources:
      WebServer:
        Type: ALIYUN::ECS::Instance
        Properties:
          DiskMappings:
            Fn::If:
              - CreateProdRes
              - - Category: cloud_efficiency
                  DiskName: FirstDataDiskName
                  Size: 40
                - Category: cloud_ssd
                  DiskName: SecondDataDiskName
                  Size: 40
              - Ref: ALIYUN::NoValue
          VpcId: vpc-2zew9pxh2yirtzqxd****
          SystemDiskCategory: cloud_efficiency
          SecurityGroupId: sg-2zece6wcqriejf1v****
          SystemDiskSize: 40
          ImageId: centos_6_8_64_40G_base_2017****.vhd
          IoOptimized: optimized
          VSwitchId: vsw-2zed9txvy7h2srqo6****
          InstanceType: ecs.n1.medium
      OssBucket:
        Type: ALIYUN::OSS::Bucket
        Condition: CreateProdRes
        Properties:
          AccessControl: private
          BucketName: myprodbucket
    Outputs:
      InstanceId:
        Value:
          Fn::GetAtt:
            - WebServer
            - InstanceId
      OssDomain:
        Condition: CreateProdRes
        Value:
          Fn::GetAtt:
            - OssBucket
            - DomainName