All Products
Search
Document Center

CloudOps Orchestration Service:ACS::Template

Last Updated:Nov 05, 2024

You can use the ACS::Template action to embed a template into another template as a child template.

Description

The ACS::Template action can be used to embed a template into another template as a child template. You can use this action to modularize a complex template and split the template into multiple child templates for calling. You can also define common O&M operations as reusable child templates. In addition, CloudOps Orchestration Service (OOS) provides cloud product actions as the operation templates of common cloud services. You can embed these templates in your template.

Syntax

Embed a created template by using the template name

  • General format (applicable to all templates that can be embedded)

    Tasks:
    - Name: callChildTemplate1
      Action: ACS::Template
      Properties:
        TemplateName: child_template_name # Required. The name of the child template.
        TemplateVersion: v2 # Optional. By default, the latest version is used. 
        Parameters: # Optional. The parameters that are required for executing the child template. 
          ParameterName1: value1
    {
      "Tasks": [
        {
          "Name": "callChildTemplate1",
          "Action": "ACS::Template",
          "Properties": {
            "TemplateName": "child_template_name",
            "TemplateVersion": "v2",
            "Parameters": {
              "ParameterName1": "value1"
            }
          }
        }
      ]
    }                                
  • Simplified format (applicable only to cloud product actions)

    Tasks:
    - Name: taskName # Required. The name of the task. Example: runMyInstances.
      Action: CloudProductActionName1 # Required. The name of the cloud product action. Example: ACS::ECS::RunInstances.
      Properties:
        ParameterName1: value1 # Optional. The parameter that is required for executing the cloud product action. Example: ImageId.
    {
      "Tasks": [
        {
          "Name": "taskName",
          "Action": "CloudProductActionName1",
          "Properties": {
            "ParameterName1": "parameterName1"
          }
        }
      ]
    }

Embed a new template by using the template content

Tasks:
- Name: callChildTemplate1
  Action: ACS::Template
  Properties:
    TemplateContent: 
      FormatVersion: OOS-2019-06-01 # Required. The version of the template. 
      Parameters: # Optional. The parameters that are required for executing the child template. 
      Tasks: # Optional. The action that is performed by the child template.
{
  "Tasks": [
    {
      "Name": "callChildTemplate1",
      "Action": "ACS::Template",
      "Properties": {
        "TemplateContent": {
          "FormatVersion": "OOS-2019-06-01",
          "Parameters": null,
          "Tasks": null
        }
      }
    }
  ]
}

Limits

Embedding actions have the following limits:

  • A template cannot embed itself.

  • Loop embedding is not allowed. For example, A embeds B, B embeds C, and C embeds A.

  • The total number of embedding layers cannot exceed three.

  • The embedding of a cloud product action is regarded as one layer of embedding, and loop tasks cannot be considered as embedding.

Examples

Create an image for an Elastic Compute Service (ECS) instance by embedding the ACS::ECS::CreateImage action

  • General format (applicable to all templates that can be embedded)

    ---
    FormatVersion: OOS-2019-06-01
    Description: Creates a custom image.
    Parameters:
      imageName:
        Description: The image name.
        Type: String
      instanceId:
        Description: The ID of the instance.
        Type: String
        AllowedPattern: i-[A-Za-z0-9]*
        MinLength: 1
        MaxLength: 30
      OOSAssumeRole:
        Type: String
        Description: oos assume this role to execution task
        Default: OOSServiceRole
    RamRole: '{{OOSAssumeRole}}'
    Tasks:
    - Name: createImage
      Action: ACS::Template
      Description: Creates a custom image.
      Properties:
        TemplateName: 'ACS::ECS::CreateImage'
        Parameters:
          ImageName: '{{ imageName }}'
          InstanceId: '{{ instanceId }}'
      Outputs:
        imageId:
          Type: String
          ValueSelector: ImageId
    Outputs:
      imageId:
        Type: String
        Value: '{{ createImage.imageId }}'        
    {
        "FormatVersion": "OOS-2019-06-01",
        "Description": "Creates a custom image.",
        "Parameters": {
            "imageName": {
                "Description": "The image name.",
                "Type": "String"
            },
            "instanceId": {
                "Description": "The ID of the instance.",
                "Type": "String",
                "AllowedPattern": "i-[A-Za-z0-9]*",
                "MinLength": 1,
                "MaxLength": 30
            },
            "OOSAssumeRole": {
                "Type": "String",
                "Description": "oos assume this role to execution task",
                "Default": "OOSServiceRole"
            }
        },
        "RamRole": "{{OOSAssumeRole}}",
        "Tasks": [
            {
                "Name": "createImage",
                "Action": "ACS::Template",
                "Description": "Creates a custom image.",
                "Properties": {
                    "TemplateName": "ACS::ECS::CreateImage",
                    "Parameters": {
                        "ImageName": "{{ imageName }}",
                        "InstanceId": "{{ instanceId }}"
                    }
                },
                "Outputs": {
                    "imageId": {
                        "Type": "String",
                        "ValueSelector": "ImageId"
                    }
                }
            }
        ],
        "Outputs": {
            "imageId": {
                "Type": "String",
                "Value": "{{ createImage.imageId }}"
            }
        }
    }        
  • Simplified format (applicable only to cloud product actions)

    ---
    FormatVersion: OOS-2019-06-01
    Description: Creates a new Image from existing ECS Instance.
    Parameters:
      InstanceId:
        Description: the Instance Type for the new instances
        Type: String
      ImageName:
        Description:  name of the new image
        Type: String
      OOSAssumeRole:
        Type: String
        Description: oos assume this role to execution task
        Default: OOSServiceRole
    RamRole: "{{OOSAssumeRole}}"
    Tasks:
      - Name: createImage
        Action: ACS::ECS::CreateImage
        Properties:
          ImageName: "{{ ImageName }}"
          InstanceId: "{{ InstanceId }}"
        Outputs:
          ImageId:
            ValueSelector: ImageId
            Type: String
    Outputs:
      ImageId:
        Type: String
        Value: "{{ createImage.ImageId }}"
    {
      "FormatVersion": "OOS-2019-06-01",
      "Description": "Creates a new Image from existing ECS Instance.",
      "Parameters": {
        "InstanceId": {
          "Description": "the Instance Type for the new instances",
          "Type": "String"
        },
        "ImageName": {
          "Description": "name of the new image",
          "Type": "String"
        },
        "OOSAssumeRole": {
          "Type": "String",
          "Description": "oos assume this role to execution task",
          "Default": "OOSServiceRole"
        }
      },
      "RamRole": "{{OOSAssumeRole}}",
      "Tasks": [
        {
          "Name": "createImage",
          "Action": "ACS::ECS::CreateImage",
          "Properties": {
            "ImageName": "{{ ImageName }}",
            "InstanceId": "{{ InstanceId }}"
          },
          "Outputs": {
            "ImageId": {
              "ValueSelector": "ImageId",
              "Type": "String"
            }
          }
        }
      ],
      "Outputs": {
        "ImageId": {
          "Type": "String",
          "Value": "{{ createImage.ImageId }}"
        }
      }
    }

Query ECS instances to which the specified tag is added based on the template content

FormatVersion: OOS-2019-06-01
Description:
  name-en: DescribeInstances
   
Parameters:
  regionId:
    Label:
      en: The ID of region
       
    Type: String
    Default: '{{ ACS::RegionId }}'
Tasks:
  - Name: describeInstances_out
    Action: ACS::Template
    Description:
      en: Queries the ECS instances by specifying tag
       
    Properties:
      TemplateContent:
        FormatVersion: OOS-2019-06-01
        Description: ''
        Parameters:
          regionId:
            Label:
              en: The ID of region
               
            Type: String
            Default: '{{ ACS::RegionId }}'
        Tasks:
          - Name: describeInstances_1
            Action: ACS::Template
            Description:
              en: Queries the ECS instances by specifying tag
               
            Properties:
              TemplateContent:
                FormatVersion: OOS-2019-06-01
                Description: ''
                Parameters:
                  regionId:
                    Label:
                      en: The ID of region
                       
                    Type: String
                    Default: '{{ ACS::RegionId }}'
                Tasks:
                  - Name: describeInstances_2
                    Action: ACS::ExecuteAPI
                    Description:
                      en: Queries the ECS instances by specifying tag
                       
                    Properties:
                      Service: ECS
                      API: DescribeInstances
                      Parameters:
                        RegionId: '{{ regionId }}'
                    Outputs:
                      instanceIdss:
                        Type: List
                        ValueSelector: Instances.Instance[].InstanceId
                Outputs:
                  instanceId1:
                    Type: List
                    Value: '{{ describeInstances_2.instanceIdss}}'
              Parameters:
                regionId: '{{ regionId }}'
            Outputs:
              instanceId2:
                Type: List
                ValueSelector: .instanceId1
        Outputs:
          instanceId1:
            Type: List
            Value: '{{ describeInstances_1.instanceId2 }}'
      Parameters:
        regionId: '{{ regionId }}'
    Outputs:
      instanceId2:
        Type: List
        ValueSelector: .instanceId1
Outputs:
  instanceId4:
    Type: List
    Value: '{{ describeInstances_out.instanceId2}}'
{
  "FormatVersion": "OOS-2019-06-01",
  "Description": {
    "name-en": "DescribeInstances",
     
  },
  "Parameters": {
    "regionId": {
      "Label": {
        "en": "The ID of region",
         
      },
      "Type": "String",
      "Default": "{{ ACS::RegionId }}"
    }
  },
  "Tasks": [
    {
      "Name": "describeInstances_out",
      "Action": "ACS::Template",
      "Description": {
        "en": "Queries the ECS instances by specifying tag",
         
      },
      "Properties": {
        "TemplateContent": {
          "FormatVersion": "OOS-2019-06-01",
          "Description": "",
          "Parameters": {
            "regionId": {
              "Label": {
                "en": "The ID of region",
                 
              },
              "Type": "String",
              "Default": "{{ ACS::RegionId }}"
            }
          },
          "Tasks": [
            {
              "Name": "describeInstances_1",
              "Action": "ACS::Template",
              "Description": {
                "en": "Queries the ECS instances by specifying tag",
                 
              },
              "Properties": {
                "TemplateContent": {
                  "FormatVersion": "OOS-2019-06-01",
                  "Description": "",
                  "Parameters": {
                    "regionId": {
                      "Label": {
                        "en": "The ID of region",
                         
                      },
                      "Type": "String",
                      "Default": "{{ ACS::RegionId }}"
                    }
                  },
                  "Tasks": [
                    {
                      "Name": "describeInstances_2",
                      "Action": "ACS::ExecuteAPI",
                      "Description": {
                        "en": "Queries the ECS instances by specifying tag",
                         
                      },
                      "Properties": {
                        "Service": "ECS",
                        "API": "DescribeInstances",
                        "Parameters": {
                          "RegionId": "{{ regionId }}"
                        }
                      },
                      "Outputs": {
                        "instanceIdss": {
                          "Type": "List",
                          "ValueSelector": "Instances.Instance[].InstanceId"
                        }
                      }
                    }
                  ],
                  "Outputs": {
                    "instanceId1": {
                      "Type": "List",
                      "Value": "{{ describeInstances_2.instanceIdss}}"
                    }
                  }
                },
                "Parameters": {
                  "regionId": "{{ regionId }}"
                }
              },
              "Outputs": {
                "instanceId2": {
                  "Type": "List",
                  "ValueSelector": ".instanceId1"
                }
              }
            }
          ],
          "Outputs": {
            "instanceId1": {
              "Type": "List",
              "Value": "{{ describeInstances_1.instanceId2 }}"
            }
          }
        },
        "Parameters": {
          "regionId": "{{ regionId }}"
        }
      },
      "Outputs": {
        "instanceId2": {
          "Type": "List",
          "ValueSelector": ".instanceId1"
        }
      }
    }
  ],
  "Outputs": {
    "instanceId4": {
      "Type": "List",
      "Value": "{{ describeInstances_out.instanceId2}}"
    }
  }
}