All Products
Search
Document Center

Resource Orchestration Service:Get started with template content

Last Updated:Oct 24, 2024

A template serves as the blueprint for your infrastructure and architecture. You can define cloud service resources and their dependency relationships in a template to deploy the resources by using Resource Orchestration Service (ROS). This topic describes how to define a template. In this example, the template is used to create a virtual private cloud (VPC) and a vSwitch.

Prerequisites

You are familiar with the requirements on template structures. For more information, see Template structure.

Select a template editor

You can use an online or on-premises template editor based on your business scenario. Both types of editors support automatic syntax hinting and resource property validation.

  • Online editor: You can directly and easily use an online editor without the need to install it. An online editor is suitable for simple templates that are used for resource deployment and management scenarios. For more information about how to use an online editor, see Online template editor.

Define a template

To define a template, you must declare the resources that you want to create in the Resources section of the template. You can refer to List of resource types by service to view all resource types that are supported by ROS. Then, you can refer to the documentation of a desired resource type to view the supported properties and return values. The documentation of a resource type describes the details of each resource property, such as the type, whether required, and whether editable. If a property is required, you must declare the property in the Properties part of the Resources section of a template. If a property is optional, you can leave the property empty. If a property is editable, you can modify the property in a new template after the property is specified for a resource in a stack template. Then, you can use the new template to update the stack and the property. If a property is not editable, you cannot modify the property.

  1. View details of the desired resource types.

    1. Refer to List of resource types by service to find the resource types that are suitable for your deployment scenario. In this example, the ALIYUN::ECS::VPC and ALIYUN::ECS::VSwitch resource types that are used to create a VPC and a vSwitch are suitable.

    2. Refer to the documentation of each resource type and view the resource properties.

  2. In the Parameters section, define the parameters of the template.

    You can define the VpcCidrBlock parameter of the VPC, and the ZoneId, VSwitchName, and VSwitchCidrBlock parameters of the vSwitch. The parameters defined in the Parameters section provide parameter values as GUI elements in the ROS console. For more information, see ALIYUN::ECS::VPC and ALIYUN::ECS::VSwitch. If the vSwitch is associated with the VPC, you must make sure that vSwitch CIDR block belongs to the VPC CIDR block.

    Parameters:
      VpcCidrBlock:
        Type: String
        Default: 192.168.0.0/16
        AllowedValues:
          - 10.0.0.0/8
          - 172.16.0.0/12
          - 192.168.0.0/16
      ZoneId:
        Type: String
        AssociationProperty: ALIYUN::ECS::Instance::ZoneId
      VSwitchName:
        Type: String
      VSwitchCidrBlock:
        Type: String
        Default: 192.168.0.0/24
        AllowedValues:
          - 10.0.0.0/24
          - 172.16.0.0/24
          - 192.168.0.0/24
  3. In the Resources section, define the resources that you want to create.

    The VpcId, ZoneId, CidrBlock properties of the vSwitch are required. Other properties of the vSwitch and the VPC are optional. For more information, see ALIYUN::ECS::VPC and ALIYUN::ECS::VSwitch. You can use the Ref function to reference the parameters defined in the Parameters section for properties in the Resources section. You can also directly specify values for properties in the Resources section. For more information, see Ref.

    Resources:
      Vpc:
        Type: ALIYUN::ECS::VPC
        Properties:
          VpcName: MyTest
          CidrBlock:
            Ref: VpcCidrBlock 
      VSwitch:
        Type: ALIYUN::ECS::VSwitch
        Properties:
          VpcId:
            Ref: Vpc
          ZoneId:
            Ref: ZoneId
          VSwitchName:
            Ref: VSwitchName
          CidrBlock:
            Ref: VSwitchCidrBlock
  4. In the Outputs section, define the outputs of the template.

    You can define VpcId as an output of the VPC and VSwitchId as an output of the vSwitch. For more information, see ALIYUN::ECS::VPC and ALIYUN::ECS::VSwitch. You can invoke the Fn::GetAtt built-in function to query the property values of a resource. For more information, see Fn::GetAtt.

    Outputs:
      VpcId:
        Value:
          Fn::GetAtt:
            - Vpc
            - VpcId
      VSwitchId:
        Value:
          Fn::GetAtt:
            - VSwitch
            - VSwitchId
  5. Follow the template structure to define the complete template content.

    ROSTemplateFormatVersion: '2015-09-01'
    Parameters:
      VSwitchName:
        Type: String
      VSwitchCidrBlock:
        Default: 192.168.0.0/24
        Type: String
        AllowedValues:
          - 10.0.0.0/24
          - 172.16.0.0/24
          - 192.168.0.0/24
      VpcCidrBlock:
        Default: 192.168.0.0/16
        Type: String
        AllowedValues:
          - 10.0.0.0/8
          - 172.16.0.0/12
          - 192.168.0.0/16
      ZoneId:
        AssociationProperty: ALIYUN::ECS::Instance::ZoneId
        Type: String
    Resources:
      VSwitch:
        Type: ALIYUN::ECS::VSwitch
        Properties:
          VSwitchName:
            Ref: VSwitchName
          VpcId:
            Ref: Vpc
          CidrBlock:
            Ref: VSwitchCidrBlock
          ZoneId:
            Ref: ZoneId
      Vpc:
        Type: ALIYUN::ECS::VPC
        Properties:
          VpcName: MyTest
          CidrBlock:
            Ref: VpcCidrBlock
    Outputs:
      VpcId:
        Value:
          Fn::GetAtt:
            - Vpc
            - VpcId
      VSwitchId:
        Value:
          Fn::GetAtt:
            - VSwitch
            - VSwitchId

What to do next

Use the defined template to create a stack or save the template as your private template. For more information, see Get started with stacks and Create a template.

References