All Products
Search
Document Center

Compute Nest:Create and verify a ROS template

Last Updated:Jun 06, 2025

When you create a service in Compute Nest as a service provider, you must import a template. You can create a template first, and then copy the template content to the Template Content code editor in the Compute Nest console or upload the template as a file to import the template. This topic describes how to create a JSON or YAML template and verify the template in the Resource Orchestration Service (ROS) console. In this example, a virtual private cloud (VPC) is used.

Background information

Templates in Compute Nest are ROS templates. You can create a stack template based on the template specifications defined in ROS. In the template, you can define the required cloud computing resources, such as Elastic Compute Service (ECS) and ApsaraDB RDS instances, and the dependencies between the resources. The ROS engine automatically creates and configures all resources in a stack based on a template to automate deployment and O&M. ROS is a service provided by Alibaba Cloud to simplify the management of cloud computing resources. For more information, see What is ROS?

Create a template

ROS allows you to create a JSON, YAML, or Terraform template. You can create a template by using a sample template or directly create a template.

  • ROS provides sample templates for common scenarios. You can create a template by modifying a sample template on the Sample Templates page in the ROS console. The templates that are suitable for the Independent Software Vendor (ISV) software deployment scenario are commonly used in the Compute Nest scenarios. The details page of each template shows how to modify the template.

    If you want to create a template by making simple changes to a sample template, we recommend that you directly perform the Verify the template in the ROS console step. You can select and modify the sample template when you create a stack to verify the template.

  • You can use a text editor to create a template for complex scenarios.

The following sample code provides an example on how to create a YAML template for creating an ECS instance:

ROSTemplateFormatVersion: '2015-09-01'
# The parameters.
Parameters:
  PayType:
    Type: String
    Label:
      en: ECS Instance Charge Type
      zh-cn: the description in Chinese
    Default: PostPaid
    AllowedValues:
      - PostPaid
      - PrePaid
    AssociationProperty: ChargeType
    AssociationPropertyMetadata:
      LocaleKey: InstanceChargeType
  PayPeriodUnit:
    Type: String
    Label:
      en: Pay Period Unit
      zh-cn: the description in Chinese
    Default: Month
    AllowedValues:
      - Month
      - Year
    AssociationProperty: PayPeriodUnit
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  PayPeriod:
    Type: Number
    Description:
      en: When the resource purchase duration is Month, the value of Period ranges from 1 to 9, 12, 24, 36, 48, or 60. <br><b><font color='red'> When ECS instance types are PrePaid valid </b></font>
      zh-cn: the description in Chinese
    Label:
      en: Period
      zh-cn: the description in Chinese
    Default: 1
    AllowedValues:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
      - 8
      - 9
    AssociationProperty: PayPeriod
    AssociationPropertyMetadata:
      Visible:
        Condition:
          Fn::Not:
            Fn::Equals:
              - ${PayType}
              - PostPaid
  EcsInstanceType:
    Type: String
    Label:
      en: Instance Type
      zh-cn: the description in Chinese
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ${ZoneId}
      InstanceChargeType: ${InstanceChargeType}
  InstancePassword:
    NoEcho: true
    Type: String
    Description:
      en: Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ Special symbol in)
      zh-cn: the description in Chinese
    Label:
      en: Instance Password
      zh-cn: the description in Chinese
    ConstraintDescription:
      en: Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()`~!@#$%^&*_-+=|{}[]:;<>,.?/ Special symbol in)
      zh-cn: the description in Chinese
    AssociationProperty: ALIYUN::ECS::Instance::Password
    AllowedPattern: '^[a-zA-Z0-9-\(\)\`\~\!\@\#\$\%\^\&\*\_\-\+\=\|\{\}\[\]\:\;\<\>\,\.\?\/]*$'
    MinLength: 8
    MaxLength: 30
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance::ZoneId
    Label:
      en: VSwitch Availability Zone
      zh-cn: the description in Chinese
  VpcId:
    AssociationProperty: ALIYUN::ECS::VPC::VPCId
    Type: String
    Description:
      en: Please search the ID starting with (vpc-xxx) from console-Virtual Private Cloud
      zh-cn: the description in Chinese
    Label:
      en: VPC ID
      zh-cn: the description in Chinese
  VSwitchId:
    AssociationProperty: ALIYUN::ECS::VSwitch::VSwitchId
    AssociationPropertyMetadata:
      VpcId: ${VpcId}
      ZoneId: ${ZoneId}
    Type: String
    Description:
      en: Instance ID of existing business network switches, console-Virtual Private Cloud-VSwitches under query
      zh-cn: the description in Chinese
    Label:
      en: VSwitch ID
      zh-cn: the description in Chinese
# The resources.
Resources:
  EcsSecurityGroup:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      SecurityGroupName:
        Ref: ALIYUN::StackName
      VpcId:
        Ref: VpcId
      # The inbound port of the security group.
      SecurityGroupIngress:
        - PortRange: 80/80
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          IpProtocol: tcp
          NicType: internet
  EcsInstanceGroup:
    Type: ALIYUN::ECS::InstanceGroup
    Properties:
      # The instance name.
      InstanceName:
        Fn::Join:
          - '-'
          - - Ref: ALIYUN::StackName
            - '[1,4]'
      IoOptimized: optimized
      # The billing method.
      InstanceChargeType:
        Ref: PayType
      PeriodUnit:
        Ref: PayPeriodUnit
      Period:
        Ref: PayPeriod
      # The network configuration.
      VpcId:
        Ref: VpcId
      ZoneId:
        Ref: ZoneId
      VSwitchId:
        Ref: VSwitchId
      SecurityGroupId:
        Ref: EcsSecurityGroup
      # The type and size of the disk.
      SystemDiskCategory: cloud_essd
      SystemDiskSize: 200
      MaxAmount: 1
      # The image.
      ImageId: centos_7
      # The instance type.
      InstanceType:
        Ref: EcsInstanceType
      Password:
        Ref: InstancePassword
      # Enable the public IP address.
      AllocatePublicIP: true
      # The public bandwidth.
      InternetMaxBandwidthOut: 1
  ECSRunCommand:
    Type: ALIYUN::ECS::RunCommand
    Properties:
      InstanceIds:
        Fn::GetAtt:
          - EcsInstanceGroup
          - InstanceIds
      Type: RunShellScript
      Sync: true
      Timeout: 3600
      CommandContent: |-
        #!/bin/bash

# The output configuration.
Outputs:
  # Display the public IP address as the endpoint returned by HTTP in the console.
  Endpoint:
    Description:
      zh-cn: the description in Chinese
      en: Public IP Addresses
    Value:
      Fn::Sub:
        - http://${ServerAddress}
        - ServerAddress:
            Fn::Select:
              - 0
              - Fn::GetAtt:
                 - EcsInstanceGroup
                 - PublicIps
Metadata:
  ALIYUN::ROS::Interface:
    # The parameter groups.
    ParameterGroups:
      - Parameters:
          - PayType
          - PayPeriodUnit
          - PayPeriod
        Label:
          default:
            en: PayType Configuration
            zh-cn: the description in Chinese
      - Parameters:
          - EcsInstanceType
          - InstancePassword
        Label:
          default:
            en: ECS Instance Configuration
            zh-cn: the description in Chinese
      - Parameters:
          - ZoneId
          - VpcId
          - VSwitchId
        Label:
          default:
            zh-cn: the description in Chinese
            en: Choose existing Infrastructure

In the preceding template, parameters in the Parameters, Resources, Outputs, and Metadata sections are defined.

Parameters

The Parameters section defines the parameters that you need to configure when you create a service instance. The following table describes the parameters defined in the Parameters section in this example.

Parameter

Description

PayType

The billing method.

PayPeriodUnit

The unit of the subscription duration of the resource that you want to purchase.

PayPeriod

The subscription duration of the resource.

EcsInstanceType

The instance type of the ECS instance.

InstancePassword

The password that is used to access the ECS instance.

ZoneId

The ID of the zone in which the vSwitch is deployed.

VpcId

The ID of the VPC.

VSwitchId

The ID of the vSwitch.

Resources

The Resources section defines the resources to be created and the Type and Properties parameters of each resource. The following table describes the resources defined in the Resources section in this example.

Resource type defined in ROS

Description

ALIYUN::ECS::SecurityGroup

ECS security groups.

ALIYUN::ECS::InstanceGroup

ECS instances.

ALIYUN::ECS::RunCommand

Shell scripts to be run on ECS instances.

Note

For each type of Alibaba Cloud resource, you can find its syntax, properties, and return values (output parameters) in the list of resource types by service. For more information, see List of resource types by service. These parameters can be referenced when you create a template to specify resource requirements.

Outputs

The Outputs section defines the information to be returned after you create a service. In this example, information is returned as a public IP address. After the resources are created, the service customer can obtain the IP address for accessing the service.

Metadata

You can use Metadata to group parameters defined in the Parameters section of a template and hide specific parameters. To view the display effect of the parameters, go to the Configure Parameters step in the ROS console. The following table describes the parameter groups in this example.

Group name

Parameter

PayType Configuration

PayType

PayPeriodUnit

PayPeriod

ECS Instance Configuration

EcsInstanceType

InstancePassword

Choose existing Infrastructure

ZoneId

VpcId

VSwitchId

You can also use advanced features such as Mappings and Conditions. For more information about advanced features, see Template structure.

You can also use Terraform to create a template. For more information, see Create a Terraform template.

Verify the template in the ROS console

After you create the template, you can create a stack to verify the template in the ROS console.

  1. Log on to the ROS console.

  2. In the left-side navigation pane, choose Deployment > Stacks.

  3. In the upper-left corner of the Stacks page, click Create Stack and select Use ROS.

  4. On the Create Stack page, configure the parameters.

    1. In the Specify Template section, select Select an Existing Template to copy the content of the template that you created to the Template Content code editor. You can also select Use a Sample Template to modify the content of a sample template.

    2. Click Next. In the Configure Parameters step, check whether the parameter settings are valid. Click Preview Template Resources to check whether the resource configurations are correct.

    3. Optional. Click Next. In the Compliance Precheck (Optional) step, configure the parameters.

    4. Optional. Click Next. In the Check and Confirm (Optional) step, confirm the configurations.

    5. Click Create.

    Note

    The Compliance Precheck (Optional) and Check and Confirm (Optional) steps are optional. You can determine whether to perform these steps based on your business requirements.

If the stack is created, the template is verified and available. If the stack fails to be created, check the failure cause and modify the template.