All Products
Search
Document Center

Resource Orchestration Service:Fn::MergeMapToList

Last Updated:Mar 15, 2024

The built-in function Fn::MergeMapToList merges multiple mappings into a new mapping list.

Declaration

  • JSON

    {
      "Fn::MergeMapToList": [
        {
          "key_1": ["key_1_item_1", "key_1_item_2", ...]
        },
        {
          "key_2": ["key_2_item_1", "key_2_item_2", ...],
        },
        ...
      ]
    }
  • YAML

    • Syntax for the full function name:

      Fn::MergeMapToList:
        - key_1:
            - key_1_item_1
            - key_1_item_2
            - ...
        - key_2:
            - key_2_item_1
            - key_2_item_2
            - ...
        - ...
    • Syntax for the short form:

      !MergeMapToList [{key_1: [key_1_item_1, key_1_item_2, ..]}, {key_2: [key_2_item_1, key_2_item_2, ...]}, ...]

Parameters

[{key_1: [key_1_item_1, key_1_item_2, ..]}, {key_2: [key_2_item_1, key_2_item_2, ...]},...]: the source mappings. Each source mapping must have a list of values.

The function merges source mappings into a new mapping list based on the following rules:

  1. Merges the key and the first value in each source mapping into the first mapping in the new list.

  2. Merges the key and the second value in each source mapping into the second mapping in the new list. All keys and values follow the same rule.

  3. The number of mappings in the new list varies based on the largest number of values in a source mapping among all source mappings. If the number of values in source mappings are different, the system repeatedly uses the last value of the shorter source mapping to ensure that each mapping in the new list have the same number of values.

Return value

The list of merged mappings.

Syntax examples

  • In the following example, three source mappings are merged. Each source mapping has the same number of values.

    Fn::MergeMapToList:
      - key_1:
          - key_1_item_1
          - key_1_item_2
      - key_2:
          - key_2_item_1
          - key_2_item_2
      - key_3:
          - key_3_item_1
          - key_3_item_2

    Result:

    - key_1: key_1_item_1
      key_2: key_2_item_1
      key_3: key_3_item_1
    - key_1: key_1_item_2
      key_2: key_2_item_2
      key_3: key_3_item_2
  • In the following example, three source mappings are merged. The source mappings have a different number of values.

    Fn::MergeMapToList:
      - key_1:
          - key_1_item_1
          - key_1_item_2
      - key_2:
          - key_2_item_1
          - key_2_item_2
          - key_2_item_3
      - key_3:
          - key_3_item_1
          - key_3_item_2

    Result:

    - key_1: key_1_item_1
      key_2: key_2_item_1
      key_3: key_3_item_1
    - key_1: key_1_item_2
      key_2: key_2_item_2
      key_3: key_3_item_2
    - key_1: key_1_item_2
      key_2: key_2_item_3
      key_3: key_3_item_2

Usage example

In the following sample template, all instances created in WebServer are added to the server group of a Server Load Balancer (SLB) instance:

ROSTemplateFormatVersion: '2015-09-01'
Resources:
  WebServer:
    Type: ALIYUN::ECS::InstanceGroupClone
    Properties:
      SourceInstanceId: i-xxxxx
      Password: Hello****
      MinAmount: 1
      MaxAmount: 1
  CreateVServerGroup:
    Type: ALIYUN::SLB::VServerGroup
    Properties:
      LoadBalancerId: lb-****
      VServerGroupName: VServerGroup-****
      BackendServers:
        !MergeMapToList
          - Port:
              - 6666
              - 9090
              - 8080
          - ServerId: !GetAtt WebServer.InstanceIds
          - Weight:
              - 20
              - 100

Supported functions