Resource Orchestration Service (ROS) uses templates to create groups of Alibaba Cloud resources called stacks. ROS uses stacks to manage and maintain groups of resources.

Prerequisites

An Alibaba Cloud account is used. To create an Alibaba Cloud account, go to the Alibaba Cloud official website.

Background information

This topic uses the sample template simple_ecs_instance to describe how to create, manage, and maintain Alibaba Cloud resources. ROS templates are text files in JSON format. You can define Alibaba Cloud resources such as security groups, ECS instances, VPCs, and ApsaraDB for RDS instances in your template.

Procedure

  1. Log on to the ROS console.
  2. In the left-side navigation pane, choose Templates > Sample Templates.
  3. Find the template named simple_ecs_instance.templat
  4. Click View Details. The template appears as a JSON file.
    The content of simple_ecs_instance is as follows:
    {  
      "Description": "One simple ECS instance with a security group and a vSwitch in a VPC. The user only needs to specify the image ID.",  
      "Parameters": {    
        "ImageId": {      
          "Type": "String",      
          "Description": {        
            "en": "Image ID, represents the image resource to startup one ECS instance, <a href='https://www.alibabacloud.com/help/doc-detail/112977.html' target='_blank'>View image resources</a>",        
          },      
          "Label": "ECS Image ID",      
          "Default": "centos_7"    
         },    
         "InstanceType": {      
           "Type": "String",      
           "Description": {        
             "en": "The ECS instance type, <a href='https://www.alibabacloud.com/help/doc-detail/25378.html' target='_blank'>View instance types</a>, please confirm the instance type if in the specific zone in ECS console. ",       
           "Label": "ECS Instance Type",      
           "Default": "ecs.c5.large"    
          },    
          "Password": {      
            "NoEcho": true,      
            "Type": "String",      
            "Description": {         
              "en": "[8, 30] characters, consists of uppercase letter, lowercase letter, number or special characters such as ( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? / ",        
           },      
           "AllowedPattern": "[a-zA-Z0-9-\\(\\)\\`\\~\\!@\\#\\$%\\^&\\*-+=\\|\\{\\}\\[\\]\\:\\;\\‘\\,\\.\\?\\/]*",      
           "Label": "Login Password",      
           "ConstraintDescription": "[8, 30] characters, consists of uppercase letter, lowercase letter, number or special characters.",      
           "MinLength": 8,      
           "MaxLength": 30    
           }  
         },  
         "ROSTemplateFormatVersion": "2015-09-01",  
         "Outputs": {    
           "InstanceId": {      
             "Description": "The instance id of created ecs instance",      
             "Value": {        
               "Fn::GetAtt": [          
                 "WebServer",          
                 "InstanceId"        
               ]      
            }    
          },    
          "PublicIp": {      
            "Description": "Public IP address of created ecs instance.",      
            "Value": {        
              "Fn::GetAtt": [          
                "WebServer",          
                "PublicIp"        
              ]     
             }    
           },    
           "SecurityGroupId": {      
             "Description": "Generated security group id for security group.",      
             "Value": {        
               "Fn::GetAtt": [          
                 "SecurityGroup",          
                 "SecurityGroupId"        
               ]
          }
        }
      },  
    "Resources": {
       "VSwitch": {
         "Type": "ALIYUN::ECS::VSwitch",
         "Properties": { 
           "VpcId": {
             "Ref": "VPC"
           }, 
           "ZoneId": { 
             "Fn::Select": [ 
               "0",  
               {  
                 "Fn::GetAZs": { 
                   "Ref": "ALIYUN::Region" 
                } 
               } 
             ]
           },  
           "CidrBlock": "192.168.XX.XX/16" 
         }
       }, 
       "WebServer": { 
         "Type": "ALIYUN::ECS::Instance",  
         "Properties": {
           "VpcId": { 
             "Ref": "VPC" 
           }, 
           "SecurityGroupId": { 
             "Ref": "SecurityGroup" 
           }, 
           "VSwitchId": { 
             "Ref": "VSwitch" 
           }, 
           "ImageId": { 
             "Ref": "ImageId" 
           }, 
           "InstanceType": { 
             "Ref": "InstanceType" 
           }, 
           "Password": { 
             "Ref": "Password" 
           } 
         } 
       }, 
       "VPC": { 
         "Type": "ALIYUN::ECS::VPC", 
         "Properties": { 
           "CidrBlock": "192.168.XX.XX/16", 
           "VpcName": "simple_ecs_vpc" 
         } 
       }, 
       "SecurityGroup": { 
         "Type": "ALIYUN::ECS::SecurityGroup", 
         "Properties": { 
           "VpcId": { 
             "Ref": "VPC" 
           } 
         } 
       } 
     }
    }
    This template contains five top-level objects:
    • "ROSTemplateFormatVersion" defines the version of the template.
    • "Description" defines the description of the template.
    • "Parameters":{ } defines the parameters of the template. This example defines parameters such as ImageId and InstanceType. It also specifies the default values of these parameters.
    • "Resources":{ } defines the Alibaba Cloud resources that the template can create. This example defines an ECS instance and a security group with properties that are defined in Parameters.
    • "Outputs":{ } defines property values that the stack can supply to external requests after the stack is created. This example defines ECS instance ID, public IP address, and security group ID as outputs.
  5. Click Create Stack.
  6. In the Configure Template Parameters step of the Create Stack wizard, set Stack Name and Parameters, and then click Next.
  7. In the Configure Stack step of the Create Stack wizard, set Stack Policy, Rollback on Failure, Timeout Period, and Tags, and then click Next.
    If the resource is not created or updated within the period specified by the Timeout Period parameter, the system will consider the operation a failure and then determine whether to roll back the resource to its previous state based on the value of the Rollback on Failure parameter.
  8. In the Confirm step of the Create Stack wizard, click Create Stack.
    On the stack management page, you can view the status and other information of the current stack.

What to do next

You can also create a stack by providing a URL that points to a template file. You can use ROS to manage and delete resources, or delete a stack while retaining its resources. You can also update your stacks as needed and re-check the status of the updated stacks.