Resource Orchestration Service (ROS) uses a template to create a group of Alibaba Cloud resources. This group of resources is defined as a resource stack, or a stack. ROS manages and maintains this group of resources through the resource stack.

Background information

This topic uses the sample template simple_ecs_instance as an example to describe how to create, manage, and maintain Alibaba Cloud resources. Templates are text files in JSON format. You can customize Alibaba Cloud resources such as security groups, Elastic Cloud Service (ECS) instances, Virtual Private Clouds (VPCs), and ApsaraDB for RDS (RDS) instances in your template.

Procedure

  1. Log on to the ROS console.
  2. Click Sample Template in the left-side navigation pane. Find the template named simple_ecs_instance.
  3. Click Preview and the template appears as a JSON file.
    The contents of simple_ecs_instance are as follows:
    {
      "ROSTemplateFormatVersion": "2015-09-01",
      "Description": "A simple ECS instance with a security group and a VSwitch in a VPC. You need to specify an image ID.",
      "Parameters": {
        "ImageId": {
          "Type": "String",
          "Description": "ImageId is the unique identifier of the image that is required by the ECS instance.",
          "Label": "ECS Image ID",
          "Default": "centos_7",
        },
        "InstanceType": {
          "Type": "String",
          "Description": "Type of the ECS instance"
          "Label": "ECS Instance Type",
          "Default": "ecs.c5.large",
          "AllowedValues": [
            "ecs.c5.large",
            "ecs.g5.large",
            "ecs.c5.xlarge",
            "ecs.g5.xlarge"
          ]
        },
        "Password": {
          "Type": "String",
          "Description": "Login password of the ECS instance",
          "ConstraintDescription": "The password must be 8 to 30 characters in length and consist of letters, numbers, and special characters.",
          "Label": "ECS Instance Password",
          "MaxLength": "30",
          "MinLength": "8",
          "AllowedPattern": "[a-zA-Z0-9-\\(\\)\\`\\~\\! @\\#\\$%\\^&\\*-+=\\|\\{\\}\\[\\]\\:\\;\\‘\\,\\. \\? \\/]*",
          "NoEcho": true,
          "Confirm": true
        }
      },
      "Resources": {
        "WebServer": {
          "Type": "ALIYUN::ECS::Instance",
          "Properties": {
            "ImageId": {
              "Ref": "ImageId"
            },
            "InstanceType": {
              "Ref": "InstanceType"
            },
            "SecurityGroupId": {
              "Ref": "SecurityGroup"
            },
            "PrivateIpAddress": "192.168.0.1",
            "VSwitchId": {
              "Ref": "vswitch"
            },
            "VpcId": {
              "Ref": "vpc"
            },
            "Password": {
              "Ref": "Password"
            }
          }
        },
        "vswitch": {
          "Type": "ALIYUN::ECS::VSwitch",
          "Properties": {
            "VpcId": {
              "Ref": "vpc"
            },
            "ZoneId": {
              "Fn::Select": [
                "0",
                {
                  "Fn::GetAZs": {
                    "Ref": "ALIYUN::Region"
                  }
                }
              ]
            },
            "CidrBlock": "192.168.0.0/16",
          }
        },
        "SecurityGroup": {
          "Type": "ALIYUN::ECS::SecurityGroup",
          "Properties": {
            "VpcId": {
              "Ref": "vpc"
            }
          }
        },
        "vpc": {
          "Type": "ALIYUN::ECS::VPC",
          "Properties": {
            "CidrBlock": "192.168.0.0/16",
            "VpcName": "simple_ecs_vpc"
          }
        }
      },
      "Outputs": {
        "InstanceId": {
          "Description": "Instance ID of the created ECS instance",
          "Value": {
            "Fn::GetAtt": [
              "WebServer",
              "InstanceId":
            ]
          }
        },
        "PublicIp": {
          "Description": "Public IP address of the created ECS instance",
          "Value": {
            "Fn::GetAtt": [
              "WebServer",
              "PublicIp": {
            ]
          }
        },
        "SecurityGroupId": {
          "Description": "ID of the security group.",
          "Value": {
            "Fn::GetAtt": [
              "SecurityGroup",
              "SecurityGroupId"
            ]
          }
        }
      }
    }
    This template contains five top-level objects:
    • "ROSTemplateFormatVersion" indicates the version of the template.
    • "Description" is a description of the template.
    • "Parameters":{ } defines the parameters of the template. This example defines parameters such as the image ID, instance type, among other parameters. It also specifies the default values of these parameters.
    • "Resources":{ } defines the Alibaba Cloud resources that the template intends to 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 resource stack is created. This example defines ECS instance ID, public IP address, and security group ID as outputs.
  4. Click Create stack to start creating your resource stack.
  5. Select a region from the Region drop-down list. Click Next to continue.
  6. Enter a name for the stack in the Stack Name field. Click Create.
  7. Click Stack Management in the left-side navigation pane. The Stack Management page appears.
  8. Find your template and click Manage in the Operation column. The Stack Overview page appears.
    • Click Overview in the left-side navigation pane to view the stack overview.
    • Click Resources in the left-side navigation pane to view all resources in the stack.
    • Click Event in the left-side navigation pane to view all events in the lifecycle of the stack. If any operation fails, the specific cause of failure is displayed here.
    • Click Template in the left-side navigation pane to view the content of the template.

What to do next

You can also create a stack by providing a URL that points to a template file. You can use the ROS console to manage and delete resources, or delete a stack but retain the resources it contains. You can also update your resource stacks as needed, and check the status of resource stacks.