github.com/facebookincubator/ttpforge@v1.0.13-0.20240405153150-5ae801628835/example-ttps/templating/loops.yaml (about)

     1  ---
     2  api_version: 2.0
     3  uuid: 97484c5d-e1ab-4162-8d55-ce53343b1a4c
     4  name: Creating Loops with Templating
     5  description: |
     6    TTPForge's support for native Golang-style templates can
     7    be used to create dynamic nested loops that execute a
     8    step (or multiple steps) several times
     9  args:
    10    - name: max_i
    11      type: int
    12      default: 2
    13    - name: max_j
    14      type: int
    15      default: 3
    16    - name: max_k
    17      type: int
    18      default: 4
    19  steps:
    20    # we declare our loop limit variables here for two reasons:
    21    # 1. We can shift to one-based indexing for our loops
    22    # 2. Using (for example) ".Args.max_j" inside the loop over $i
    23    #    is not possible due to template scoping rules
    24    {{$lim_i := int (add .Args.max_i 1)}}
    25    {{$lim_j := int (add .Args.max_j 1)}}
    26    {{$lim_k := int (add .Args.max_k 1)}}
    27    {{range $i := untilStep 1 $lim_i 1}}
    28      {{range $j := untilStep 1 $lim_j 1}}
    29        - name: outer_step_{{$i}}_{{$j}}
    30          print_str: "Executing outer step with (i,j) = ({{$i}},{{$j}})"
    31          # note that we need the indentation of the step in the inner
    32          # loop to match the outer loop or our YAML will be invalid.
    33          # Hence, the lines inside the $k loop are not indented as much
    34          # as you might expect
    35          {{range $k := untilStep 1 $lim_k 1}}
    36        - name: inner_step_{{$i}}_{{$j}}_{{$k}}
    37          print_str: "Executing inner step with (i,j,k) = ({{$i}},{{$j}},{{$k}})"
    38          {{end}}
    39      {{end}}
    40    {{end}}