All Products
Search
Document Center

Embedding actions

Last Updated: Sep 26, 2019

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

      1. Tasks:
      2. - Name: callChildTemplate1
      3. Action: ACS::Template
      4. Properties:
      5. TemplateName: child_template_name # Required. The name of the child template.
      6. Parameters: # Optional. The parameters required for executing the child template.
      7. ParameterName1: value1
    • JSON format (For more information, see the parameter description for the YAML format.)

      1. {
      2. "Tasks": [
      3. {
      4. "Name": "callChildTemplate1",
      5. "Action": "ACS::Template",
      6. "Properties": {
      7. "TemplateName": "child_template_name",
      8. "Parameters": {
      9. "ParameterName1": "value1"
      10. }
      11. }
      12. }
      13. ]
      14. }
  • Simplified format (only applicable to the cloud product actions)
    • YAML format
      1. Tasks:
      2. - Name: taskName # Required. The name of the task. Example: runMyInstances.
      3. Action: CloudProductActionName1 # Required. The name of the cloud product action. Example: ACS::ECS::RunInstances.
      4. Properties:
      5. 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.)
      1. {
      2. "Tasks": [
      3. {
      4. "Name": "taskName",
      5. "Action": "CloudProductActionName1",
      6. "Properties": {
      7. "ParameterName1": "parameterName1"
      8. }
      9. }
      10. ]
      11. }

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
    1. ---
    2. FormatVersion: OOS-2019-06-01
    3. Description: Creates a custom image.
    4. Parameters:
    5. imageName:
    6. Description: The image name.
    7. Type: String
    8. instanceId:
    9. Description: The ID of the instance.
    10. Type: String
    11. AllowedPattern: i-[A-Za-z0-9]*
    12. MinLength: 1
    13. MaxLength: 30
    14. OOSAssumeRole:
    15. Type: String
    16. Description: oos assume this role to execution task
    17. Default: OOSServiceRole
    18. RamRole: '{{OOSAssumeRole}}'
    19. Tasks:
    20. - Name: createImage
    21. Action: ACS::Template
    22. Description: Creates a custom image.
    23. Properties:
    24. TemplateName: 'ACS::ECS::CreateImage'
    25. Parameters:
    26. ImageName: '{{ imageName }}'
    27. InstanceId: '{{ instanceId }}'
    28. Outputs:
    29. imageId:
    30. Type: String
    31. ValueSelector: ImageId
    32. Outputs:
    33. imageId:
    34. Type: String
    35. Value: '{{ createImage.imageId }}'
    • JSON format
    1. {
    2. "FormatVersion": "OOS-2019-06-01",
    3. "Description": "Creates a custom image.",
    4. "Parameters": {
    5. "imageName": {
    6. "Description": "The image name.",
    7. "Type": "String"
    8. },
    9. "instanceId": {
    10. "Description": "The ID of the instance.",
    11. "Type": "String",
    12. "AllowedPattern": "i-[A-Za-z0-9]*",
    13. "MinLength": 1,
    14. "MaxLength": 30
    15. },
    16. "OOSAssumeRole": {
    17. "Type": "String",
    18. "Description": "oos assume this role to execution task",
    19. "Default": "OOSServiceRole"
    20. }
    21. },
    22. "RamRole": "{{OOSAssumeRole}}",
    23. "Tasks": [
    24. {
    25. "Name": "createImage",
    26. "Action": "ACS::Template",
    27. "Description": "Creates a custom image.",
    28. "Properties": {
    29. "TemplateName": "ACS::ECS::CreateImage",
    30. "Parameters": {
    31. "ImageName": "{{ imageName }}",
    32. "InstanceId": "{{ instanceId }}"
    33. }
    34. },
    35. "Outputs": {
    36. "imageId": {
    37. "Type": "String",
    38. "ValueSelector": "ImageId"
    39. }
    40. }
    41. }
    42. ],
    43. "Outputs": {
    44. "imageId": {
    45. "Type": "String",
    46. "Value": "{{ createImage.imageId }}"
    47. }
    48. }
    49. }

  • Simplified format (only applicable to the cloud product actions)

    • YAML format
    1. ---
    2. FormatVersion: OOS-2019-06-01
    3. Description: Creates a new Image from existing ECS Instance.
    4. Parameters:
    5. InstanceId:
    6. Description: the Instance Type for the new instances
    7. Type: String
    8. ImageName:
    9. Description: name of the new image
    10. Type: String
    11. OOSAssumeRole:
    12. Type: String
    13. Description: oos assume this role to execution task
    14. Default: OOSServiceRole
    15. RamRole: "{{OOSAssumeRole}}"
    16. Tasks:
    17. - Name: createImage
    18. Action: ACS::ECS::CreateImage
    19. Properties:
    20. ImageName: "{{ ImageName }}"
    21. InstanceId: "{{ InstanceId }}"
    22. Outputs:
    23. ImageId:
    24. ValueSelector: ImageId
    25. Type: String
    26. Outputs:
    27. ImageId:
    28. Type: String
    29. Value: "{{ createImage.ImageId }}"
    • JSON format
    1. {
    2. "FormatVersion": "OOS-2019-06-01",
    3. "Description": "Creates a new Image from existing ECS Instance.",
    4. "Parameters": {
    5. "InstanceId": {
    6. "Description": "the Instance Type for the new instances",
    7. "Type": "String"
    8. },
    9. "ImageName": {
    10. "Description": "name of the new image",
    11. "Type": "String"
    12. },
    13. "OOSAssumeRole": {
    14. "Type": "String",
    15. "Description": "oos assume this role to execution task",
    16. "Default": "OOSServiceRole"
    17. }
    18. },
    19. "RamRole": "{{OOSAssumeRole}}",
    20. "Tasks": [
    21. {
    22. "Name": "createImage",
    23. "Action": "ACS::ECS::CreateImage",
    24. "Properties": {
    25. "ImageName": "{{ ImageName }}",
    26. "InstanceId": "{{ InstanceId }}"
    27. },
    28. "Outputs": {
    29. "ImageId": {
    30. "ValueSelector": "ImageId",
    31. "Type": "String"
    32. }
    33. }
    34. }
    35. ],
    36. "Outputs": {
    37. "ImageId": {
    38. "Type": "String",
    39. "Value": "{{ createImage.ImageId }}"
    40. }
    41. }
    42. }