All Products
Search
Document Center

Resource Orchestration Service:Generate a template based on a scenario with one click

Last Updated:Aug 04, 2023

You can use Resource Orchestration Service (ROS) to generate a template based on a collection of existing resources in a resource management scenario. After the template is generated, you can modify the template based on your business requirements and use the modified template as a common template to deploy multiple resources at a time.

Use case

If you want to create resources to deploy a web application, you can add the app:web tag to the resources. This way, you can filter the required resources by tag when you create a resource management scenario. You can click Create Template to generate a template based on the scenario. After the template is generated, you can add the Parameters section to the template to improve the flexibility and reusability of the template. Then, you can use the modified template as a common template to create a stack and deploy multiple resources at a time. In this example, the following resources are deployed:

  • One virtual private cloud (VPC)

  • One vSwitch

  • One security group

  • Two Elastic Compute Service (ECS) instances

  • One Server Load Balancer (SLB) instance

Step 1: Create resources and add tags to the resources

Create the preceding resources in the relevant consoles and add the app:web tag to the resources. The tag key is app and the tag value is web. For more information about tags, see Tag overview.

Note

If the resources already exist, you need to only add the tag to the resources.

  1. In the VPC console, create a VPC and a vSwitch, and add the app:web tag to them.

    For more information, see Create a VPC and Add tags to an instance.

    Note

    To add the tag to a vSwitch, find the vSwitch and click the p475747..png icon in the Tags column. You can perform similar operations to add the tag to a VPC.

  2. In the ECS console, create a security group of the VPC type and add the app:web tag to the security group. When you create the security group, select the VPC that you created in 1 from the Network drop-down list.

  3. Create two ECS instances and add the app:web tag to the instances.

    1. Select the VPC and the vSwitch that you created in 1.

    2. Select the security group that you created in 2.

    3. Configure relevant parameters for the ECS instances.

      For more information about the parameters, see Create an instance by using the wizard.

    4. Add the app:web tag to the instances.

      For more information, see Create or add a tag.

  4. In the SLB console, create an SLB instance and add the app:web tag to the instance. In this example, an Application Load Balancer (ALB) instance is created.

    1. Select the VPC that you created in 1 to create the ALB instance.

    2. Create a backend server group and add the ECS instances that you created in 3 to the group.

    3. Configure a listener and domain name resolution based on your business requirements.

    4. Add the app:web tag to the ALB instance.

Step 2: Create a resource management scenario

Create a resource management scenario and filter the resources created in Step 1: Create a resource and bind tags.

  1. Log on to the ROS console.
  2. In the left-side navigation pane, click Scenarios.
  3. In the top navigation bar, select a region where you want to create the scenario from the region drop-down list.

  4. On the Scenarios page, click Create Scenario.
  5. In the Create Scenario dialog box, specify a description for the scenario and set the scenario type to Resource Management.

  6. Configure the parameters in the Resource Range section.

    1. Set Method to Source Tag.

    2. In the Source Tag section, set Tag Key to app and Tag Value to web.

    p475750..png
  7. Set Delete Resource to No.

    Note

    In this example, the resources in the stack are retained if the stack is deleted.

  8. Click Create.
    After you create the scenario, Created appears in the Status column on the Scenarios page.

Step 3: Generate a template based on the scenario

  1. On the Scenarios page, click the ID of the scenario.
  2. In the upper-right corner of the scenario management page, click Create Template to generate a template.

The generated template is in the JSON and YAML formats. In this example, the JSON template is used. The following section describes the template body and structure.

Template body

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSInstance_001:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::Instance
    Properties:
      DeletionProtection: false
      VSwitchId:
        Ref: ECSVSwitch_001
      VpcId:
        Ref: ECSVPC_001
      Tags:
        - Value: web
          Key: app
      SystemDiskSize: 40
      HostName: iZbp11ut2d6rr7gg78a****
      SystemDiskCategory: cloud_essd
      ImageId: centos_7_9_x64_20G_alibase_2022****.vhd
      SpotStrategy: NoSpot
      AllocatePublicIP: false
      InstanceChargeType: PostPaid
      IoOptimized: optimized
      SecurityGroupIds:
        - Ref: ECSSecurityGroup_001
      InternetChargeType: PayByTraffic
      ZoneId: cn-hangzhou-i
      InstanceName: launch-advisor-2022****
      InstanceType: ecs.g7.large
      SystemDiskPerformanceLevel: PL0
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001
  ECSInstance_002:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::Instance
    Properties:
      DeletionProtection: false
      VSwitchId:
        Ref: ECSVSwitch_001
      VpcId:
        Ref: ECSVPC_001
      Tags:
        - Value: web
          Key: app
      SystemDiskSize: 40
      HostName: iZbp11ut2d6rr7gg78a****
      SystemDiskCategory: cloud_essd
      ImageId: centos_7_9_x64_20G_alibase_2022****.vhd
      SpotStrategy: NoSpot
      AllocatePublicIP: false
      InstanceChargeType: PostPaid
      IoOptimized: optimized
      SecurityGroupIds:
        - Ref: ECSSecurityGroup_001
      InternetChargeType: PayByTraffic
      ZoneId: cn-hangzhou-i
      InstanceName: launch-advisor-2022****
      InstanceType: ecs.g7.large
      SystemDiskPerformanceLevel: PL0
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001
  ECSSecurityGroup_001:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      VpcId:
        Ref: ECSVPC_001
      Description: web-sg
      SecurityGroupName: web-sg
      Tags:
        - Value: web
          Key: app
      SecurityGroupIngress:
        - PortRange: 1/65535
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 80/80
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 443/443
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 22/22
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 3389/3389
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: '-1/-1'
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: icmp
          SourcePortRange: '-1/-1'
      SecurityGroupType: normal
    DependsOn:
      - ECSVPC_001
  ECSVPC_001:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock: 172.16.0.0/12
      VpcName: web-vpc
      EnableIpv6: false
      Description: web-vpc
      Tags:
        - Value: web
          Key: app
  ECSVSwitch_001:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName: web-vsw
      VpcId:
        Ref: ECSVPC_001
      Description: web-vsw
      Tags:
        - Value: web
          Key: app
      ZoneId: cn-hangzhou-i
      CidrBlock: 172.16.0.0/24
    DependsOn:
      - ECSVPC_001
  SLBBackendServerAttachment_001:
    DeletionPolicy: Retain
    Type: ALIYUN::SLB::BackendServerAttachment
    Properties:
      BackendServers:
        - ServerId:
            Ref: ECSInstance_002
          Type: ecs
          Weight: 100
        - ServerId:
            Ref: ECSInstance_001
          Type: ecs
          Weight: 100
      LoadBalancerId:
        Ref: SLBLoadBalancer_001
    DependsOn:
      - SLBLoadBalancer_001
      - ECSInstance_001
      - ECSInstance_002
  SLBLoadBalancer_001:
    DeletionPolicy: Retain
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      DeletionProtection: false
      VpcId:
        Ref: ECSVPC_001
      AddressIPVersion: ipv4
      Tags:
        - Value: web
          Key: app
      SupportPrivateLink: true
      PayType: PayOnDemand
      SlaveZoneId: cn-hangzhou-h
      AddressType: intranet
      VSwitchId:
        Ref: ECSVSwitch_001
      LoadBalancerName: web-app-slb
      InternetChargeType: paybytraffic
      LoadBalancerSpec: slb.s1.small
      MasterZoneId: cn-hangzhou-i
    DependsOn:
      - ECSVPC_001
      - ECSVSwitch_001

Template structure

The template contains the following sections:

ROSTemplateFormatVersion: '2015-09-01' // The syntax version of the template.
Resources: {} // The details of the resources.
  • ROSTemplateFormatVersion: the syntax version of the template. Set the value to 2015-09-01.

  • Resources: the details of the resources, such as the properties and the dependencies of resources. The Resources section contains the following resources that you created in Step 1: Create resources and add tags to the resources:

    • One VPC: ECSVPC_001.

    • One vSwitch: ECSvSwitch_001.

    • One security group: ECSSecurityGroup_001.

    • Two ECS instances: ECSInstance_001 and ECSInstance_002, hereinafter referred to as ECSInstance_00X.

    • One ALB instance: SLBLoadBalancer_001. SLBListener_001 and SLBBackendServerAttachment_001 are also created.

    The following figure shows the architecture of the resources.

    p475753..png

Step 4: Modify the generated template

In the generated template, the resource property values are literal values that are parsed from the parameters selected when you created the resources in the relevant consoles in Step 1: Create resources and add tags to the resources. You can add the Parameters and the Outputs sections to modify the generated template. This way, you can use the template as a common template in different scenarios. In the Parameters section, you can specify values for parameters to overwrite the literal values of relevant properties such as zones and instance types.

Before the change

ROSTemplateFormatVersion: '2015-09-01' // The syntax version of the template.
Resources: {} // The details of the resources.

After the change

ROSTemplateFormatVersion: '2015-09-01' // The syntax version of the template.
Description: {} // The description of the template, including the scenarios and architecture of the template. 
Parameters: {} // The parameters for which you can specify values to overwrite the literal values of relevant resource properties.
Resources: {} // The details of the resources.
Outputs: {} // The outputs of the template, such as the return values of resource properties. To query outputs, call the GetStack operation or go to the Outputs tab in the ROS console.

Note

For more information about the parameters, see Template syntax.

Mappings between resources, parameters, and outputs

Resource name

Parameter

Output

ECSVPC_001

VpcCidrBlock: the CIDR block of the VPC.

None.

ECSvSwitch_001

ZoneId: the zone ID.

None.

VSwitchCidrBlock: the CIDR block of the vSwitch.

ECSSecurityGroup_001

None.

None.

ECSInstance_00X

ZoneId: the zone ID.

InstanceId: the ID of the ECS instance.

ECSInstanceType: the ECS instance type.

SystemDiskCategory: the system disk category of the ECS instance.

SLBLoadBalancer_001

MasterZoneId: the ID of the primary zone.

IpAddress: the IP address of the ALB instance.

SlaveZoneId: the secondary zone ID of the ALB instance.

LoadBalancerSpec: the specification of the ALB instance.

Procedure

Resource: ECSVPC_001

  • In the Parameters section, add and specify the VpcCidrBlock parameter.

  • Use Ref to reference the VpcCidrBlock parameter contained in the Parameters section for the CidrBlock property.

Before the change

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSVPC_001:
    DeletionPolicy: Retain
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock: 172.16.0.0/12

After the change

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  VpcCidrBlock:
    Type: String
    Label: VPC IPV4 CIDR Block
    Description: the CIDR Block of the VPC
    Default: 172.16.0.0/12
Resources:
  ECSVPC_001:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock:
        Ref: VpcCidrBlock
      VpcName: web-vpc
      EnableIpv6: false
      Description: web-vpc
      Tags:
        - Value: web
          Key: app
Note

For more information about other properties of ECSVPC_001, see ALIYUN::ECS::VPC.

Resource: ECSvSwitch_001

  • In the Parameters section, add and specify the ZoneId and VSwitchCidrBlock parameters.

  • Use Ref to reference the ZoneId parameter contained in the Parameters section for the ZoneId property.

  • Use Ref to reference the VSwitchCidrBlock parameter contained in the Parameters section for the CidrBlock property.

Before the change

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSVSwitch_001:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VpcId:
        Ref: ECSVPC_001
      ZoneId: cn-hangzhou-i
      CidrBlock: 172.16.0.0/24
    DependsOn:
      - ECSVPC_001

After the change

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::ZoneId
    Description: VPC IPV4 CIDR Block
    Label: the CIDR Block of the VPC
  VSwitchCidrBlock:
    Type: String
    Label: VSwitch CIDR Block
    Description: the CIDR block of the vSwitch must belong to the CIDR block of the VPC
    Default: 172.16.0.0/24
Resources:
  ECSVPC_001: ''
  ECSVSwitch_001:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      CidrBlock:
        Ref: VSwitchCidrBlock
      VpcId:
        Ref: ECSVPC_001
      ZoneId:
        Ref: VSwitchZone
    DependsOn:
      - ECSVPC_001
Note
  • In the Parameters section, you can specify AssociationProperty to query resources in the specified region and specify AssociationPropertyMetadata to add filter conditions for parameters. This way, the ROS console displays the parameter values based on the value chosen for a parameter. For the ZoneId parameter, AssociationProperty is set to ALIYUN::ECS::ZoneId. This way, you can query available zone IDs in the specified region and select the required zone from a drop-down list in the ROS console. For more information, see AssociationProperty and AssociationPropertyMetadata.

  • If you specify DependsOn for a resource, the system creates the resource after the dependency of the resource is created. In this example, ECSVSwitch_001 is created after ECSVPC_001 is created.

  • For more information about other properties of ECSVSwitch_001, see ALIYUN::ECS::VSwitch.

Resource: ECSInstance_00X

  • In the Parameters section, add and specify the ZoneId, ECSInstanceType, and SystemDiskCategory parameters.

  • Use Ref to reference the ZoneId parameter contained in the Parameters section for the ZoneId property.

  • Use Ref to reference the ECSInstanceType parameter contained in the Parameters section for the InstanceType property.

  • Use Ref to reference the SystemDiskCategory parameter contained in the Parameters section for the SystemDiskCategory property.

Before the change

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSVSwitch_001: ''
  ECSVPC_001: ''
  ECSSecurityGroup_001: ''
  ECSInstance_001:
    Type: ALIYUN::ECS::Instance
    Properties:
      ZoneId: cn-hangzhou-i
      InstanceType: ecs.g7.large
      SystemDiskCategory: cloud_essd
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001

After the change

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ZoneId: ''
  ECSInstanceType:
    Type: String
    Description: the available ECS instance type in the specified zone
    Label: ECS Instance Type
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ZoneId
  SystemDiskCategory:
    Type: String
    Description: the category of the system disk
    AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
    AssociationPropertyMetadata:
      ZoneId: VSwitchZone
      InstanceType: ECSInstanceType
    Label: System Disk Category
Resources:
  ECSInstance_001:
    Type: ALIYUN::ECS::Instance
    Properties:
      SystemDiskCategory:
        Ref: SystemDiskCategory
      InstanceType:
        Ref: ECSInstanceType
      ZoneId:
        Ref: ZoneId
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001
Note
  • For the EcsInstanceType parameter, AssociationProperty is set to ALIYUN::ECS::Instance::InstanceType. This way, you can query available ECS instance types in the specified region and select the required instance type from a drop-down list in the ROS console.

  • AssociationPropertyMetadata is used to add filter conditions. In this example, AssociationPropertyMetadata is set to ZoneId. This way, you can query available ECS instance types in the specified zone.

  • For the SystemDiskCategory parameter, AssociationProperty is set to ALIYUN::ECS::Disk::SystemDiskCategory. This way, you can query available system disk categories of the ECS instance in the specified region. ZoneId is specified in AssociationPropertyMetadata to use a specific zone ID as a filter condition.

  • For more information about other properties of ECSInstance_00X, see ALIYUN::ECS::Instance.

Resource: SLBLoadBalancer_001

  • In the Parameters section, add and specify the MasterZoneId, SlaveZoneId, and LoadBalancerSpec parameters.

  • Use Ref to reference the ZoneId parameter contained in the Parameters section for the MasterZoneId property.

  • Use Ref to reference the SlaveZoneId parameter contained in the Parameters section for the SlaveZoneId property.

  • Use Ref to reference the LoadBalancerSpec parameter contained in the Parameters section for the LoadBalancerSpec property.

Before the change

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  ECSVPC_001: ''
  ECSVSwitch_001: ''
  SLBLoadBalancer_001:
    DeletionPolicy: Retain
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      MasterZoneId: cn-hangzhou-i
      SlaveZoneId: cn-hangzhou-h
      LoadBalancerSpec: slb.s1.small
    DependsOn:
      - ECSVPC_001
      - ECSVSwitch_001

After the change

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ZoneId: ''
  SlaveZoneId:
    Type: String
    Description: the ID of the secondary zone
    Label: Secondary Zone
  LoadBalancerSpec:
    Type: String
    AssociationProperty: ALIYUN::SLB::Instance::InstanceType
    Description: the specification of the ALB instance
    Label: ALB Instance Specification
    AssociationPropertyMetadata:
      ZoneId: VSwitchZone
Resources:
  ECSVPC_001: ''
  ECSVSwitch_001: ''
  SLBLoadBalancer_001:
    DeletionPolicy: Retain
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      LoadBalancerName: web-app-slb
      LoadBalancerSpec:
        Ref: LoadBalancerSpec
      SlaveZoneId:
        Ref: SlaveZoneId
      MasterZoneId:
        Ref: ZoneId
    DependsOn:
      - ECSVPC_001
      - ECSVSwitch_001
Note
  • In the Parameters section, you can specify AssociationProperty to query the resources in the specified region and specify AssociationPropertyMetadata to add filter conditions for parameters. This way, the ROS console displays the parameter values based on the value chosen for a parameter.

  • For the ZoneId parameter, AssociationProperty is set to ALIYUN::ECS::ZoneId. This way, you can query the available zone IDs in the specified region and select the required zone from a drop-down list in the ROS console.

  • For the LoadBalancerSpec parameter, AssociationProperty is set to ALIYUN::SLB::Instance::InstanceType. This way, you can query the available specifications of the ALB instance in the specified region and select the required specification from a drop-down list in the ROS console. For more information, see AssociationProperty and AssociationPropertyMetadata.

  • For more information about other properties of SLBLoadBalancer_001, see ALIYUN::SLB::LoadBalancer.

Output: IpAddress

For more information about the return values of other properties of SLBLoadBalancer_001, see the "Return values" section of the ALIYUN::SLB::LoadBalancer topic.

Outputs:
  SLBListenerIpAddress:
    Description: TheIPaddressoftheloadbalancer.
    Value:
      Fn::GetAtt:
        - SLBLoadBalancer_001
        - IpAddress

Output: InstanceId

For more information about the return values of other properties of ECSInstance_00X, see the "Return values" section of the ALIYUN::ECS::Instance topic.

Outputs:
  ECSInstance_001:
    Description: TheinstanceIDofcreatedecsinstance
    Value:
      Fn::GetAtt:
        - ECSInstance_001
        - InstanceId
  ECSInstance_002:
    Description: TheinstanceIDofcreatedecsinstance
    Value:
      Fn::GetAtt:
        - ECSInstance_002
        - InstanceId

Complete common template

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  ZoneId:
    Type: String
    AssociationProperty: ALIYUN::ECS::Instance:ZoneId
    Description: the ID of the zone
    Label: Zone
  SlaveZoneId:
    Type: String
    Description: the ID of the secondary zone
    Label: SLB Secondary Zone
  VpcCidrBlock:
    Type: String
    Label: VPC IPv4 CIDR Block
    Description: the CIDR Block of the VPC
    Default: 172.16.0.0/12
  VSwitchCidrBlock:
    Type: String
    Label: VSwitch CIDR Block
    Description: the CIDR block of the vSwitch must belong to the CIDR block of the VPC
    Default: 172.16.0.0/24
  ECSInstanceType:
    Type: String
    Description: the ECS instance type
    Label: ECS Instance Type
    AssociationProperty: ALIYUN::ECS::Instance::InstanceType
    AssociationPropertyMetadata:
      ZoneId: ZoneId
  SystemDiskCategory:
    Type: String
    Description: the category of the system disk
    AssociationProperty: ALIYUN::ECS::Disk::SystemDiskCategory
    AssociationPropertyMetadata:
      ZoneId: ZoneId
      InstanceType: ECSInstanceType
    Label: System Disk Category
  LoadBalancerSpec:
    Type: String
    AssociationProperty: ALIYUN::SLB::Instance::InstanceType
    Description: the specification of the instance
    Label: SLB Specification
    AssociationPropertyMetadata:
      ZoneId: ZoneId
    Default: slb.s1.small
Resources:
  ECSVPC_001:
    Type: ALIYUN::ECS::VPC
    Properties:
      CidrBlock:
        Ref: VpcCidrBlock
      VpcName: web-vpc
      EnableIpv6: false
      Description: web-vpc
      Tags:
        - Value: web
          Key: app
  ECSVSwitch_001:
    Type: ALIYUN::ECS::VSwitch
    Properties:
      VSwitchName: web-vsw
      VpcId:
        Ref: ECSVPC_001
      Description: web-vsw
      Tags:
        - Value: web
          Key: app
      ZoneId:
        Ref: ZoneId
      CidrBlock:
        Ref: VSwitchCidrBlock
    DependsOn:
      - ECSVPC_001
  ECSSecurityGroup_001:
    Type: ALIYUN::ECS::SecurityGroup
    Properties:
      VpcId:
        Ref: ECSVPC_001
      Description: web-sg
      SecurityGroupName: web-sg
      Tags:
        - Value: web
          Key: app
      SecurityGroupIngress:
        - PortRange: 80/80
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 443/443
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
        - PortRange: 22/22
          NicType: intranet
          Priority: 1
          SourceCidrIp: 0.0.0.0/0
          Policy: accept
          IpProtocol: tcp
      SecurityGroupType: normal
    DependsOn:
      - ECSVPC_001
  ECSInstance_001:
    Type: ALIYUN::ECS::Instance
    Properties:
      DeletionProtection: true
      SystemDiskCategory:
        Ref: SystemDiskCategory
      VpcId:
        Ref: ECSVPC_001
      Description: web-ecs
      Tags:
        - Value: web
          Key: app
      VSwitchId:
        Ref: ECSVSwitch_001
      SystemDiskSize: 40
      ImageId: centos_7_9_x64_20G_alibase_2022****.vhd
      SpotStrategy: NoSpot
      AllocatePublicIP: false
      InstanceChargeType: PostPaid
      IoOptimized: optimized
      SecurityGroupIds:
        - Ref: ECSSecurityGroup_001
      InternetChargeType: PayByTraffic
      ZoneId:
        Ref: ZoneId
      InstanceName: web-ecs002
      InstanceType:
        Ref: ECSInstanceType
      SystemDiskPerformanceLevel: PL0
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001
  ECSInstance_002:
    Type: ALIYUN::ECS::Instance
    Properties:
      DeletionProtection: true
      SystemDiskCategory:
        Ref: SystemDiskCategory
      VpcId:
        Ref: ECSVPC_001
      Description: web-ecs
      Tags:
        - Value: web
          Key: app
      VSwitchId:
        Ref: ECSVSwitch_001
      SystemDiskSize: 40
      ImageId: centos_7_9_x64_20G_alibase_2022****.vhd
      SpotStrategy: NoSpot
      AllocatePublicIP: false
      InstanceChargeType: PostPaid
      IoOptimized: optimized
      SecurityGroupIds:
        - Ref: ECSSecurityGroup_001
      InternetChargeType: PayByTraffic
      ZoneId:
        Ref: ZoneId
      InstanceName: web-ecs001
      InstanceType:
        Ref: ECSInstanceType
      SystemDiskPerformanceLevel: PL0
    DependsOn:
      - ECSSecurityGroup_001
      - ECSVSwitch_001
      - ECSVPC_001
  SLBListener_001:
    Type: ALIYUN::SLB::Listener
    Properties:
      AclStatus: 'off'
      Protocol: tcp
      Description: tcp_80
      HealthCheck:
        Interval: 2
        HealthyThreshold: 3
        Switch: 'on'
        UnhealthyThreshold: 3
        HealthCheckType: tcp
      LoadBalancerId:
        Ref: SLBLoadBalancer_001
      ListenerPort: 80
      Bandwidth: -1
      BackendServerPort: 80
      Scheduler: tch
      StartListener: true
      Persistence:
        PersistenceTimeout: 0
    DependsOn:
      - SLBLoadBalancer_001
  SLBLoadBalancer_001:
    Type: ALIYUN::SLB::LoadBalancer
    Properties:
      DeletionProtection: false
      VpcId:
        Ref: ECSVPC_001
      AddressIPVersion: ipv4
      Tags:
        - Value: web
          Key: app
      SupportPrivateLink: true
      PayType: PayOnDemand
      AddressType: intranet
      VSwitchId:
        Ref: ECSVSwitch_001
      LoadBalancerName: web-slb
      InternetChargeType: paybytraffic
      LoadBalancerSpec:
        Ref: LoadBalancerSpec
      MasterZoneId:
        Ref: ZoneId
      SlaveZoneId:
        Ref: SlaveZoneId
    DependsOn:
      - ECSVPC_001
      - ECSVSwitch_001
  SLBBackendServerAttachment_001:
    Type: ALIYUN::SLB::BackendServerAttachment
    Properties:
      BackendServers:
        - ServerId:
            Ref: ECSInstance_001
          Type: ecs
          Weight: 100
        - ServerId:
            Ref: ECSInstance_002
          Type: ecs
          Weight: 100
      LoadBalancerId:
        Ref: SLBLoadBalancer_001
    DependsOn:
      - SLBLoadBalancer_001
      - ECSInstance_001
      - ECSInstance_002
Outputs:
  ECSInstance_001:
    Description: TheinstanceIDofcreatedecsinstance
    Value:
      Fn::GetAtt:
        - ECSInstance_001
        - InstanceId
  ECSInstance_002:
    Description: TheinstanceIDofcreatedecsinstance
    Value:
      Fn::GetAtt:
        - ECSInstance_002
        - InstanceId
  SLBListenerIpAddress:
    Description: TheIPaddressoftheloadbalancer.
    Value:
      Fn::GetAtt:
        - SLBLoadBalancer_001
        - IpAddress

Step 5: (Optional) Deploy multiple resources at a time

You can use the common template to create a stack and deploy multiple resources at a time.

  1. In the ROS console, use the common template that you created in Step 4: Modify the generated template to create a stack and deploy multiple resources at a time.

    For more information, see Create a stack.

  2. On the stack details page, click the Parameters tab to view the details of the deployed resources.