All Products
Search
Document Center

Resource Orchestration Service:Resources

Last Updated:Nov 12, 2025

The Resources section describes the properties of each resource in a stack and the dependencies between them. You can reference a resource from other resources or in the Outputs section.

Resource entity types

Resource entities are classified into regular resources and data source resources. Regular resources are further divided into Alibaba Cloud resources and custom resources. The following table describes the resource entity types.

Resource entity type

Description

Regular resource (Resource)

  • Alibaba Cloud resource: Create, update, and delete Alibaba Cloud resources. Alibaba Cloud resource types start with ALIYUN::.

  • Custom resource: Create resources with custom logic and define how they are updated and deleted. Custom resource types start with Custom:: or are ALIYUN::ROS::CustomResource.

    For more information, see Overview.

Data source resource (DataSource)

Query resource data of Alibaba Cloud services.

For more information, see Data source resources.

Syntax

A resource declaration consists of a resource name and a resource description. The resource description is enclosed in braces ({}). If you declare multiple resources, separate them with commas (,). The following code segment shows the syntax for the Resources section:

Resources:
  Resource 1 Name:
    Type: Resource type
    Condition: Condition to create this resource
    Properties: Resource property description
  Resource 2 Name:
    Type: Resource type
    Condition: Condition to create this resource
    Properties: Resource property description

The following list describes the parameters:

  • A resource name must be unique within a template. You can reference the resource by its name in other parts of the template.

  • Resource type (Type): The type of resource that you are declaring. For example, ALIYUN::ECS::Instance indicates an Alibaba Cloud ECS instance. For more information about all ROS-supported resource types, see Resource type index.

  • Resource properties (Properties): Additional options specified for the resource. For example, you must specify an Image ID for each Alibaba Cloud ECS instance.

Example

Resources:
  ECSInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****

If a resource does not require any properties, you can omit the Properties section.

Property values can be text strings, lists of strings, Boolean values, referenced parameters, or function return values. When you write a JSON template, follow these rules:

  • If the property value is a text string, enclose the value in double quotation marks ("").

  • If the property value is a list of strings, enclose it in brackets ([]).

  • If the property value is an intrinsic function or a referenced parameter, enclose it in braces ({}).

These rules also apply when you combine text, lists, referenced parameters, and function return values. The following example shows how to declare different types of property values:

{
  "Properties": {
    "String": "string",
    "LiteralList": [
      "value1",
      "value2"
    ],
    "Boolean": true,
    "ReferenceForOneValue": {
      "Ref": "ResourceID"
    },
    "FunctionResultWithFunctionParams": {
      "Fn::Join": [
        "%",
        [
          "Key=",
          {
            "Ref": "SomeParameter"
          }
        ]
      ]
    }
  }
}

DeletionPolicy

When you remove resources, two situations can occur:

  • If DeletionPolicy is set to Delete, the resource is deleted when it is removed from the stack.

  • If DeletionPolicy is set to Retain, the resource is retained when it is removed from the stack.

For example, to retain an ECS instance when its stack is deleted, declare the policy as shown in the following code segment:

Resources:
  ECSInstance:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
    DeletionPolicy: Retain

In this example, if the stack that is created from the template is deleted, the ECSInstance resource is retained.

Important

When you call the DeleteStack operation, if a resource has a DeletionPolicy configured in the template and is also included in the RetainResources parameter, the following principles apply:

  • If Resource A has DeletionPolicy=Delete set in the template, whether the resource is retained depends on whether it is included in the RetainResources parameter.

  • If Resource A has DeletionPolicy=Retain set in the template, the resource is always retained, regardless of whether it is included in the RetainResources parameter.

DependsOn

Use the DependsOn property to define dependencies between resources. A resource with a DependsOn property is created only after the resources specified in the DependsOn property are created.

Important

You can set the Condition property of a dependency that is specified in the DependsOn property to False. A value of False specifies that the resource is created even if the dependency is not created.

Examples:

  • To depend on a single resource:

    DependsOn: ResourceName
  • To depend on multiple resources:

    DependsOn:
      - ResourceName1
      - ResourceName2

In the following example, the WebServer resource is created only after the DatabaseServer resource is successfully created:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    DependsOn: DatabseServer
  DatabseServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small

Condition

In a template, you can use the Condition property to specify whether a resource is created. The resource is created only if the Condition evaluates to True.

In the following example, whether the WebServer resource is created is determined by the value of the MaxAmount parameter:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  MaxAmount:
    Type: Number
    Default: 1
Conditions:
  CreateWebServer:
    Fn::Not:
      Fn::Equals:
        - 0
        - Ref: MaxAmount
Resources:
  WebServer:
    Type: ALIYUN::ECS::InstanceGroup
    Condition: CreateWebServer
    Properties:
      ImageId: m-25l0rc****
      InstanceType: ecs.t1.small
      MaxAmount:
        Ref: MaxAmount
  DatabseServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small

Count

If you specify the Count property for a resource in a template, ROS pre-processes the template and expands the resource into multiple resources. Stack operations use the processed template.

  • For example, a resource is named A and its Count value is 3. In the processed template, resource A is replaced by three resources: A[0], A[1], and A[2].

    Resources:
      A:
        Count: 3
        ...

    After processing:

    Resources:
      A[0]:
        ...
      A[1]:
        ...
      A[2]:
        ...
    Important

    If the name of an expanded resource, such as A[1], already exists in the original template, the pre-processing fails and the template fails validation.

    Avoid adding the Count property to existing resources. This action changes the resource name and causes a delete operation.

  • The value of the Count property must resolve to a non-negative integer. Only the following functions are supported:

  • The total number of resources in the processed template cannot exceed the limit. The current limit is 300 resources.

  • In the Properties section of a resource that has the Count property, you can use the ALIYUN::Index pseudo parameter. During pre-processing, this parameter is replaced with the index of the resource replica (starting from 0). For example, the ALIYUN::Index for A[0] is replaced with 0, and the ALIYUN::Index for A[1] is replaced with 1. You cannot use ALIYUN::Index elsewhere in the template.

  • If a resource with the Count property is referenced in a DependsOn property, the reference is expanded.

    DependsOn: A

    After processing:

    DependsOn:
      - A[0]
      - A[1]
      - A[2]
  • If a resource with the Count property is referenced by the Ref or Fn::GetAtt function, the reference is expanded.

    Ref: A
    Fn::GetAtt:
      - A
      - PropertyName

    After processing:

    - Ref: A[0]
    - Ref: A[1]
    - Ref: A[2]
    - Fn::GetAtt:
        - A[0]
        - PropertyName
    - Fn::GetAtt:
        - A[1]
        - PropertyName
    - Fn::GetAtt:
        - A[2]
        - PropertyName

    If multiple resources use the Count property and reference each other, use Count with Fn::Select and ALIYUN::Index.

    Fn::Select:
      - Ref: ALIYUN::Index
      - Ref: A

    Take A as an example. Assume that B references A and the Count of B is 2. After the transformation, parts of the expressions for B[0] and B[1] are as follows:

    - Ref: A[0]
    - Ref: A[1]
  • If a resource specifies the Count property, its DependsOn property also supports expressions. The functions that you can use in a DependsOn expression are the same as those for the Count property. You can also use the ALIYUN::Index pseudo parameter. The following table describes the expression formats and the allowed results.

    Format

    Example

    Allowed results

    Dictionary.

    Fn::Split:
      - ','
      - Server1,Server2

    Null.

    If the result is null, the DependsOn property is removed.

    A string.

    • If the result is an empty string, the DependsOn property is removed.

    • If the result is a non-empty string, it must be a valid resource name.

    A list.

    • If a list item is null or an empty string, the item is discarded.

    • If the list becomes empty after items are discarded, the DependsOn property is removed.

    • If the list is not empty, each item must be a string and a valid resource name.

    List.

    - Server0
    - Fn::Split:
        - ','
        - Server1,Server2

    The list items can be dictionaries or strings. The allowed results vary based on the item type:

    • If a list item is a dictionary, the expression is evaluated. The allowed results are:

      • If the result is null or an empty string, the item is discarded.

      • Otherwise, the result must be a string and a valid resource name.

    • If a list item is a string, it must be a valid resource name.

    Note

    If the list becomes empty after items are discarded, the DependsOn property is removed.

    String.

    Server0

    A string.

    No additional processing is performed.

    The following example template shows how to control the concurrency of resource creation when using Count. The Count parameter specifies the number of resources to create, and the ParallelCount parameter specifies the maximum number of concurrent creation operations.

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      Count:
        Type: Number
      ParallelCount:
        Type: Number
    Resources:
      WaitConditionHandle:
        Type: ALIYUN::ROS::WaitConditionHandle
        Count:
          Ref: Count
        DependsOn:
          Fn::Select:
            - Fn::Calculate:
                - 1-{0}//{1}
                - 0
                - - Fn::Min:
                      - Ref: ALIYUN::Index
                      - Ref: ParallelCount
                  - Ref: ParallelCount
            - - Fn::Replace:
                  - index:
                      Fn::Calculate:
                        - '{0}-{1}'
                        - 0
                        - - Ref: ALIYUN::Index
                          - Ref: ParallelCount
                  - WaitConditionHandle[index]

    The processed template varies based on the values of Count and ParallelCount:

    • If you set Count to 3 and ParallelCount to 1, the processed template is as follows:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number
    • If you set Count to 5 and ParallelCount to 2, the processed template is as follows:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[3]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
        WaitConditionHandle[4]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[2]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number
    • If you set Count to 5 and ParallelCount to 3, the processed template is as follows:

      ROSTemplateFormatVersion: '2015-09-01'
      Resources:
        WaitConditionHandle[0]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[1]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[2]:
          Type: ALIYUN::ROS::WaitConditionHandle
        WaitConditionHandle[3]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[0]
        WaitConditionHandle[4]:
          Type: ALIYUN::ROS::WaitConditionHandle
          DependsOn: WaitConditionHandle[1]
      Parameters:
        Count:
          Type: Number
        ParallelCount:
          Type: Number

The following is an example of a template that uses Count. The template creates a group of EIPs and an equal number of ECS instances, and then attaches each EIP to an ECS instance.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Count:
    Type: Number
Resources:
  Eip:
    Type: ALIYUN::VPC::EIP
    Count:
      Ref: Count
    Properties:
      Bandwidth: 5
  Servers:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      MinAmount:
        Ref: Count
      MaxAmount:
        Ref: Count
      AllocatePublicIP: false
      ...: Null
  EipBind:
    Type: ALIYUN::VPC::EIPAssociation
    Count:
      Ref: Count
    Properties:
      InstanceId:
        Fn::Select:
          - Ref: ALIYUN::Index
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Fn::Select:
          - Ref: ALIYUN::Index
          - Ref: Eip
Outputs:
  InstanceIds:
    Value:
      Fn::GetAtt:
        - Servers
        - InstanceIds
  AllocationIds:
    Value:
      Ref: Eip
  EipAddresses:
    Value:
      Fn::GetAtt:
        - Eip
        - EipAddress

After processing:

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  Count:
    Type: Number
Resources:
  Eip[0]:
    Type: ALIYUN::VPC::EIP
    Properties:
      Bandwidth: 5
  Eip[1]:
    Type: ALIYUN::VPC::EIP
    Properties:
      Bandwidth: 5
  Servers:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      MinAmount:
        Ref: Count
      MaxAmount:
        Ref: Count
      AllocatePublicIP: false
      ...: Null
  EipBind[0]:
    Type: ALIYUN::VPC::EIPAssociation
    Properties:
      InstanceId:
        Fn::Select:
          - 0
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Ref: Eip[0]
  EipBind[1]:
    Type: ALIYUN::VPC::EIPAssociation
    Properties:
      InstanceId:
        Fn::Select:
          - 1
          - Fn::GetAtt:
              - Servers
              - InstanceIds
      AllocationId:
        Ref: Eip[1]
Outputs:
  InstanceIds:
    Value:
      Fn::GetAtt:
        - Servers
        - InstanceIds
  AllocationIds:
    Value:
      - Ref: Eip[0]
      - Ref: Eip[1]
  EipAddresses:
    Value:
      - Fn::GetAtt:
          - Eip[0]
          - EipAddress
      - Fn::GetAtt:
          - Eip[1]
          - EipAddress

Resource declaration example

The following is a typical example of a resource declaration:

Resources:
  WebServer:
    Type: ALIYUN::ECS::Instance
    Properties:
      ImageId: m-25l0r****
      InstanceType: ecs.t1.small
      SecurityGroupId: sg-25zwc****
      ZoneId: cn-beijing-b
      Tags:
        - Key: Department1
          Value: HumanResource
        - Key: Department2
          Value: Finance
  ScalingConfiguration:
    Type: ALIYUN::ESS::ScalingConfiguration
    Properties:
      ImageId: ubuntu_14_04_64_20G_aliaegis_2015****.vhd
      InstanceType: ecs.t1.small
      InstanceId: i-25xhh****
      InternetChargeType: PayByTraffic
      InternetMaxBandwidthIn: 1
      InternetMaxBandwidthOut: 20
      SystemDisk_Category: cloud
      ScalingGroupId: bwhtvpcBcKYac9fe3vd0****
      SecurityGroupId: sg-25zwc****
      DiskMappings:
        - Size: 10
        - Category: cloud
          Size: 10