This topic describes how to convert an Excel template to a Resource Orchestration Service (ROS) template. In this example, the template that you use to create Elastic Compute Service (ECS) instances is used.
Syntax of an Excel template
You must enter information such as parameters, resource types, and property values in the first sheet of an Excel table.
When you create an Excel template, take note of the following items:
- Column A: enter parameters, resource types, and properties of the resource types.
Resource type Required Description ROS::ParametersNo The parameters that are contained in the ROS template. In the cells in the
ROS::Parameterssection, enter parameter names. In the cells from Column B to Column N, enter!Refto reference parameters.ROS::ResourcesYes The resources that are contained in the ROS template. In the cells in the
ROS::Resourcessection, enter one or more resource types and property names of the resource types to define different resource types for templates.For more information about resource types, see List of resource types by service.
- Column B to Column N: enter values of parameters and enter property values of resource types. Each column can generate a template.
You can add comments to the Excel template.
- If a cell starts with a number sign (
#), the entire row that contains the cell is commented. - If you enter a resource type in a line in a cell that is commented, the content wrapped in the cell is also commented.
Step 1: Modify the Excel template file
You use the syntax of the Excel template to modify the Excel template file. You can also go to the EcsInstance.xlsx page to download a sample Excel template file.
In the preceding figure, the content of Column B and Column C in the Excel template file is entered. This indicates that two templates will be generated based on the content.
Step 2: Convert the template
Run the following command to convert the Excel template to an ROS template and generate
an ROS template file named template-{number}.json in the directory in which the Excel template file is stored.
{number} is an integer that starts from 0. For example, template-0.json is a template file that is generated based on the content in Column B. template-1.json is a template file that is generated based on the content in Column C.
rostran transform templates/excel/EcsInstance.xlsx --target-path tests/template.jsonStep 3: View the ROS template
In this example, the template-0.json and template-1.json template files are generated. The following sample code shows the content of the
template-0.json and template-1.json files:
template-0.json{ "ROSTemplateFormatVersion": "2015-09-01", "Parameters": { "ZoneId": { "Type": "String", "Default": "cn-beijing-h" }, "SystemDiskSize": { "Type": "Number", "Default": 100 } }, "Resources": { "MyInstance": { "Type": "ALIYUN::ECS::InstanceGroup", "Properties": { "RegionId": "cn-beijing", "ZoneId": "cn-beijing-h", "ChargeType": "PostPaid", "InstanceType": "ecs.g5.large", "Amount": 200, "SystemDiskCategory": "cloud_efficiency", "SystemDiskSize": 100, "DiskMappings": [{ "Category": "cloud_ssd", "Size": 200 }], "ImageId": "EasyShopLinux2019****", "Password": "pass****", "VpcId": { "Ref": "MyVpc" }, "VSwitchId": { "Ref": "MyVSwitch" }, "InternetMaxBandwidthOut": 0, "SecurityGroupId": "sg-2zej2g9ep36k3yhh****" } }, "MyVpc": { "Type": "ALIYUN::ECS::Vpc", "Properties": { "VpcName": "MyVpcName" } }, "MyVSwitch": { "Type": "ALIYUN::ECS::VSwitch", "Properties": { "VpcId": { "Ref": "MyVpc" }, "ZoneId": "cn-beijing-h", "VSwitchName": "MyVSwitchName" } } } }template-1.json{ "ROSTemplateFormatVersion": "2015-09-01", "Parameters": { "ZoneId": { "Type": "String" }, "SystemDiskSize": { "Type": "Number" } }, "Resources": { "MyInstance": { "Type": "ALIYUN::ECS::InstanceGroup", "Properties": { "RegionId": "cn-beijing", "ZoneId": { "Ref": "ZoneId" }, "ChargeType": "PostPaid", "InstanceType": "ecs.r5.6xlarge", "Amount": 50, "SystemDiskCategory": "cloud_ssd", "SystemDiskSize": 100, "DiskMappings": [{ "Category": "cloud_ssd", "Size": 200 }], "ImageId": "EasyShopLinux2019****", "Password": "password", "VpcId": "vpc-bp1397wjfjjzlck86****", "VSwitchId": "vsw-bp1apypxlcxdao9w7****", "InternetMaxBandwidthOut": 0, "SecurityGroupId": "sg-2zej2g9ep36k3yhh****" } } } }