All Products
Search
Document Center

Resource Orchestration Service:Resources

Last Updated:Mar 13, 2026

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 categorized as regular resources and data source resources. Regular resources are divided into Alibaba Cloud resources and custom resources, as shown in the following table.

Resource entity type

Description

Regular resource (Resource)

  • Alibaba Cloud resource: Creates, updates, and deletes Alibaba Cloud resources. The resource type starts with ALIYUN::.

  • Custom resource: Creates a resource with custom logic and defines how the resource is updated and deleted. The resource type starts with Custom:: or is ALIYUN::ROS::CustomResource.

    For more information, see Overview.

Data source resource (DataSource)

Queries the resource data of an Alibaba Cloud service.

For more information, see Data source resources.

Syntax

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

Resources:
  Resource1 Name:
    Type: Resource type
    Condition: Condition for creating this resource
    Properties: Resource property description
  Resource2 Name:
    Type: Resource type
    Condition: Condition for creating this resource
    Properties: Resource property description

The parameters are described as follows:

  • The resource name must be unique within the template. You can use the resource name to reference the resource in other parts of the template.

  • The resource type (Type) indicates the type of resource that you are declaring. For example, ALIYUN::ECS::Instance represents an Alibaba Cloud ECS instance. For a list of all resource types that ROS supports, see Resource type index.

  • The resource properties (Properties) are additional options that you specify for a 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 for that resource.

A property value can be a text string, a list of strings, a Boolean value, a referenced parameter, or a function return value. When you write a JSON template, you must 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 the list in square 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 property value types:

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

DeletionPolicy

When you remove a resource, two scenarios are possible:

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

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

For example, to keep an ECS instance when the 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 corresponds to this template is deleted, the ECSInstance resource is kept.

Important

If a resource has DeletionPolicy configured and you call the DeleteStack operation and include the resource in the RetainResources parameter, the following principles apply:

  • If Resource A has DeletionPolicy=Delete in the template, whether the resource is kept depends on whether it is included in RetainResources when you delete the stack.

  • If Resource A has DeletionPolicy=Retain in the template, the resource is always kept when you delete the stack, regardless of whether it is included in RetainResources.

DependsOn

In a template, use the DependsOn attribute to ensure that a resource is created only after another specified resource has been created. When you apply the DependsOn attribute to a resource, it will not be created until the resource referenced by DependsOn is fully provisioned.

Important

The resource that DependsOn relies on can have its Condition evaluate to False. A value of False does not affect the creation of the dependent resource.

The following examples show two ways to use this attribute:

  • Dependency on a single resource:

    DependsOn: ResourceName
  • Depend on multiple resources:

    DependsOn:
      - ResourceName1
      - ResourceName2

As shown in the following code segment, WebServer is created only after DatabaseServer 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 attribute to specify whether to create a resource. The resource is created only if the condition value specified by Condition is True.

As shown in the following code segment, the creation of WebServer depends on the value of MaxAmount:

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

In a template, after you specify Count for a resource, ROS pre-processes the template and expands the resource into multiple resources. The processed template is then used when you perform operations on the stack.

  • For example, if a resource is named A and its Count value is 3, the processed template will not contain the A resource. Instead, it will contain 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 does not pass validation.

    Avoid adding the Count attribute to existing resources. This changes the resource name and triggers a delete operation.

  • The final result of Count must be a natural number. Only the following functions are supported:

  • The total number of resources in the processed template must not exceed the limit, which is currently 300.

  • In the Properties of a resource with Count specified, you can use the pseudo parameter ALIYUN::Index. During pre-processing, this parameter is replaced with the corresponding number. For example, the ALIYUN::Index used by A[0] is replaced with 0, and the ALIYUN::Index used by A[1] is replaced with 1. You cannot use ALIYUN::Index elsewhere in the template.

  • If a resource with Count specified appears in DependsOn, it is expanded.

    DependsOn: A

    After processing:

    DependsOn:
      - A[0]
      - A[1]
      - A[2]
  • If a resource with Count specified appears in the Ref or Fn::GetAtt function, it 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 Count and have reference relationships, you can use them with Fn::Select and ALIYUN::Index.

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

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

    - Ref: A[0]
    - Ref: A[1]
  • If a resource has the Count attribute, the DependsOn attribute also supports expressions. The functions that can be used in the DependsOn expression are the same as those for the Count attribute, and you can use the ALIYUN::Index pseudo parameter. The following table describes the format of the expression and the allowed calculation results.

    Format

    Example

    Allowed calculation result

    Dictionary

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

    null

    If the value is null, the DependsOn attribute is removed.

    String

    • If the value is an empty string, the DependsOn attribute is removed.

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

    List

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

    • If the list is empty, the DependsOn attribute 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

    A list item can be a dictionary or a string. The allowed calculation results vary based on the item type:

    • If the list item is a dictionary, the expression is calculated. The allowed calculation results are as follows:

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

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

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

    Note

    If the list is empty, the DependsOn attribute is removed.

    String

    Server0

    String

    No additional processing is performed.

    The following example template controls the concurrency for resources created with Count. The Count parameter specifies the number of resources to create, and the ParallelCount parameter specifies the maximum number of concurrent creations.

    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 template for 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 resource declaration example:

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