Resource Orchestration Service (ROS) provides data source resources, also known as DataSource resources, for you to query the resource data of Alibaba Cloud services. Data source resources can be referenced by regular resources and outputs. Data source resources and regular resources provide the same features, such as references, dependencies, and updates, but apply to different business scenarios.
Business scenarios
Use queried values as inputs to create a resource
ROS queries the values of data source resources based on specified conditions and uses the queried values as input property values to create a regular resource.
Display resource details on the Outputs tab
After you specify a data source resource in the Resources section of a template, you can reference it in the Outputs section of the template. This way, the ROS console displays the resource details on the Outputs tab.
Use queried values as inputs to create a resource
ROS queries the values of data source resources based on specified conditions and uses the queried values as input property values to create a regular resource.
You can use the following template to specify multiple parameters as conditions to query the values of data source resources and use the queried values as input property values to create an Elastic Compute Service (ECS) instance.
Cores and Memory: the conditions that separately specify the number of vCPUs and the memory size. ROS uses the conditions to query available ECS instance types, and uses the first instance type to create the ECS instance by default.
ImageName: the condition that specifies the image name. ROS uses the condition to query available images, and uses the first image ID to create the ECS instance by default.
ROSTemplateFormatVersion: '2015-09-01'
Parameters:
ZoneId:
Type: String
AssociationProperty: ALIYUN::ECS::ZoneId
VpcId:
Type: String
AssociationProperty: ALIYUN::ECS::VPC::VPCId
VSwitchId:
Type: String
AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
AssociationPropertyMetadata:
VpcId: ${VpcId}
ZoneId: ${ZoneId}
SecurityGroupId:
Type: String
AssociationProperty: ALIYUN::ECS::SecurityGroup::SecurityGroupId
AssociationPropertyMetadata:
VpcId: ${VpcId}
Resources:
DS-RecommendInstanceTypes:
Type: DATASOURCE::ECS::RecommendInstanceTypes
Properties:
Cores: 1
Memory: 1
DS-Images:
Type: DATASOURCE::ECS::Images
Properties:
ImageName: CentOS8*
InstanceType:
Fn::Select:
- 0
- Ref: DS-RecommendInstanceTypes
Instance:
Type: ALIYUN::ECS::Instance
Properties:
InstanceName: MyInstance
ImageId:
Fn::Select:
- 0
- Ref: DS-Images
InstanceType:
Fn::Select:
- 0
- Ref: DS-RecommendInstanceTypes
ZoneId:
Ref: ZoneId
VSwitchId:
Ref: VSwitchId
SecurityGroupId:
Ref: SecurityGroupId
SystemDiskCategory: cloud_efficiency
Outputs:
InstanceId:
Value:
Ref: Instance
Configurations in the template:
In the Parameters section, the following parameters are specified:
ZoneId
,VpcId
,VSwitchId
, andSecurityGroupId
. Each parameter is configured withAssociationProperty
. This way, ROS displays a list of parameter values that you can select in the Configure Template Parameters section in the console.In the Resources section, the following data source resources and regular resource are specified:
DS-RecommendInstanceTypes
: the logical ID of a data source resource. ROS uses 1 vCPU and 1 GB memory as conditions to query available ECS instance types.DS-Images
: the logical ID of a data source resource. ROS uses the InstanceType and ImageName properties as conditions to query available images. TheInstanceType
property is set to{ "Fn::Select": [0, { "Ref": "DS-RecommendInstanceTypes" } }
to use the first ECS instance type among available ECS instance types. The ImageName property is set to a value prefixed with CentOS.Instance
: the logical ID of a regular resource. ROS uses the first queried instance type and image ID as input property values to create the ECS instance.
In the Outputs section, the
InstanceId
property is specified.
Display resource details on the Outputs tab
After you specify a data source resource in the Resources section of a template, you can reference it in the Outputs section of the template. This way, the ROS console displays the resource details on the Outputs tab.
You can use the following template to create a virtual private cloud (VPC) and configure a data source resource to query the VPC details and display the details on the Outputs tab:
ROSTemplateFormatVersion: '2015-09-01'
Resources:
Vpc:
Type: ALIYUN::ECS::VPC
Properties:
VpcName: MyVpc
CidrBlock: 172.16.0.0/12
DS-Vpcs:
Type: DATASOURCE::VPC::Vpcs
Properties:
VpcIds:
- Ref: Vpc
Outputs:
VpcData:
Value:
Fn::Select:
- 0
- Fn::GetAtt:
- DS-Vpcs
- Vpcs
Configurations in the template:
In the Resources section, a regular resource and a data source resource are specified:
Vpc
: the logical ID of a regular resource. The VpcName and CidrBlock properties are specified in the Vpc resource to create a VPC.DS-Vpcs
: the logical ID of a data source resource. ROS uses the VPC ID that corresponds to the Vpc resource as an input property value to query the VPC details.
In the Outputs section,
DS-Vpcs
andVpcs
are specified in theVpcData
output to use the first value ofVpcs
.