All Products
Search
Document Center

Resource Orchestration Service:How to reference the output variables of a data source resource (DataSource) in a template

Last Updated:Aug 21, 2026

A data source resource (DataSource) is used to query the resource data of an Alibaba Cloud service. A query can return either a single resource or multiple resources as a list. This topic describes how to reference the output variables of a data source resource (DataSource) in a template.

Query result for a single resource

This example shows how to query a single ApsaraDB RDS instance (DATASOURCE::RDS::DBInstance), retrieve the port for its internal network connection, and request a public endpoint for the instance.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  DBInstanceId:
    Type: String
    AssociationProperty: ALIYUN::RDS::Instance::InstanceId
Resources:
  ExtensionDataSource:
    Properties:
      DBInstanceId:
        Ref: DBInstanceId
    Type: DATASOURCE::RDS::DBInstance
  Connection:
    Type: ALIYUN::RDS::Connection
    Properties:
      DBInstanceId:
        Ref: DBInstanceId
      ConnectionStringPrefix: test1
      Port:
        Fn::GetAtt:
          - ExtensionDataSource
          - Port
Outputs:
  Port:
    Description: The port that is used to connect to the instance over an internal network.
    Value:
      Fn::GetAtt:
        - ExtensionDataSource
        - Port
  ConnectionString:
    Description: Connection string
    Value:
      Fn::GetAtt:
        - Connection
        - ConnectionString

Query result for multiple resources

This example shows how to query existing vSwitches (DATASOURCE::VPC::VSwitches) and create an inbound rule for a security group based on the CIDR block of a returned vSwitch. The intrinsic function Fn::Jq is used to retrieve the CIDR block of the first vSwitch from the VSwitches output. For more information about the Jq feature, see the Jq document.

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcId:
    Type: String
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
    Description: Find the ID that starts with vpc- in the Virtual Private Cloud console.
    Label: Existing VPC Instance ID
  SecurityGroupId:
    Type: String
    AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
    Default: ''
Resources:
  ExtensionDataSource:
    Type: DATASOURCE::VPC::VSwitches
    Properties:
      VpcId:
        Ref: VpcId
  SecurityGroupIngress:
    Type: ALIYUN::ECS::SecurityGroupIngress
    Properties:
      IpProtocol: all
      SecurityGroupId:
        Ref: SecurityGroupId
      NicType: intranet
      SourceCidrIp:
        Fn::Jq:
          - First
          - .[0].CidrBlock
          - Fn::GetAtt:
              - ExtensionDataSource
              - VSwitches
      PortRange: '-1/-1'
Outputs:
  CidrBlock:
    Description: The CIDR block.
    Value:
      Fn::Jq:
        - First
        - .[0].CidrBlock
        - Fn::GetAtt:
            - ExtensionDataSource
            - VSwitches