Features
The ACS::Template action can be used to embed another template to the current template as a child template. You can use this action to modularize a complex template and split it into multiple child templates for calling. You can also define common O&M operations as reusable child templates. In addition, Operation Orchestration Service (OOS) provides operation templates of common cloud product actions. You can embed these templates in your template. For more information, see Cloud product actions.
Syntax
General format (applicable to all embedded templates)
YAML format
Tasks: - Name: callChildTemplate1 Action: ACS::Template Properties: TemplateName: child_template_name # Required. The name of the child template. Parameters: # Optional. The parameters required for executing the child template. ParameterName1: value1
JSON format (For more information, see the parameter description for the YAML format.)
{ "Tasks": [ { "Name": "callChildTemplate1", "Action": "ACS::Template", "Properties": { "TemplateName": "child_template_name", "Parameters": { "ParameterName1": "value1" } } } ] }
Simplified format (only applicable to the cloud product actions)
YAML format
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 required for executing the cloud production action. Example: ImageId.
JSON format (For more information, see the parameter description for the YAML format.)
{ "Tasks": [ { "Name": "taskName", "Action": "CloudProductActionName1", "Properties": { "ParameterName1": "parameterName1" } } ] }
Restrictions
The embedding actions have the following restrictions:
The template cannot embed itself.
Loop embedding, for example, A embeds B, B embeds C, and C embeds A, is not allowed.
The total number of embedding layers cannot exceed three.
The embedding of a cloud product action is regarded as one layer of embedding, while loop tasks cannot be treated as embedding.
Example
The following template is used to create an image for an ECS instance by embedding the cloud product action ACS::ECS::CreateImage
:
General format (applicable to all embedded templates)
YAML format
--- 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 }}'
JSON format
{ "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 (only applicable to the cloud product actions)
YAML format
--- 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 }}"
JSON format
{ "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 }}" } } }