You can specify DataSource to query the resource data of an Alibaba Cloud service. Data source resources can be referenced by resources and output items. Data source resources and regular resources can be used in different scenarios. Data source resources provide the same features, such as references, dependencies, and updates, as regular resources.
Scenarios
Use filtered values as input properties to create a new resource
Resource Orchestration Service (ROS) filters the values of data source resources based on specified conditions, and uses the filtered values as input properties to create a new 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 the data source resource in the Outputs section of the template. Then, the ROS console can display the details of the resource on the Outputs tab.
Use filtered values as input properties to create a new resource
ROS filters the values of data source resources based on specified conditions, and uses the filtered values as input properties to create a new resource.
The following template shows how to specify the Parameters and Resources sections to filter the values of parameters and resources. Then, ROS uses the filtered values as input properties to create an Elastic Compute Service (ECS) instance. You specify the following properties to set filter conditions:
Cores and Memory: Specify the properties to query available ECS instance specifications. By default, ROS uses the first instance specifications to create the ECS instance.
ImageName: Specify the property to query available images. By default, ROS uses the ID of the first image to create the ECS instance.
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
The template contains the following information:
In the Parameters section, you specify the following parameters:
ZoneId
,VpcId
,VSwitchId
, andSecurityGroupId
. You specifyAssociationProperty
for each parameter. This way, you can view the values of the parameters and select a value for each parameter in the parameter settings section in the ROS console.In the Resources section, you specify the following data source resources and regular resource:
DS-RecommendInstanceTypes
: the logical ID of a data source resource. You set the filter conditions to 1 core and 1 GB memory to query available instance specifications.DS-Images
: the logical ID of a data source resource. You setInstanceType
to{ "Fn::Select": [0, { "Ref": "DS-RecommendInstanceTypes" }]
to use the first ECS instance specifications of available specifications. You also set ImageName to a value prefixed with CentOS to query available images.Instance
: the logical ID of a regular resource. ROS uses the first instance specifications and image ID as input properties to create the ECS instance.
In the Outputs section, you specify
InstanceId
.
Display resource details on the Outputs tab
After you specify a data source resource in the Resources section of a template, you can reference the data source resource in the Outputs section of the template. Then, the ROS console can display the details of the resource on the Outputs tab.
The following template shows how to specify properties to create a virtual private cloud (VPC), and specify the VPC as a data source resource. This way, ROS can query the details of the VPC 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
The template contains the following information:
In the Resources section, you specify the following regular resource and data source resource:
Vpc
: the logical ID of a regular resource. You specify VpcName and CidrBlock to create the VPC.DS-Vpcs
: the logical ID of a data source resource. ROS uses the ID of the created VPC as an input property to query the details of the VPC.
In the Outputs section, you specify ["
DS-Vpcs
", "Vpcs
"] forVpcData
to query the first value.