Azure/bicep

Implement @batchSize() decorator for resource loops

alex-frankel opened this issue · 2 comments

Ideally, we can get rid of the mode property and have one decorator that encapsulates both mode and batchSize, where a batchSize(1) implies serial mode

@batchSize(5)
resource tsDeploy 'Microsoft.Resources/deployments@2020-06-01' = [for i in range(0,100): {
  name: 'deployTemplateSpec${i}'
  properties: {
    mode: 'Incremental'
    templateLink: {
      id: ts.id // deploy the templateSpec
    }
  }
}]

We will be adding new decorator(s) that will be usable with module and resource loops to influence the generation of mode and batchSize attributes on resource copy loops in the generated JSON. Undecorated resource/module loops will run in parallel in the runtime in all the options as that is the default behavior.

There are several options:

Option 1

// same as the default behavior - parallel mode
@parallel()
...

// sets serial mode with batch size 4
@serial(4)
...

Option 2

// same as the default behavior - parallel mode
@mode('parallel')
...

// sets the serial mode with batch size 4
@mode('serial', 4)
...

Option 3

// sets the serial mode with batch size 4.
@batchSize(4)
...

This option does not include an option to explicitly set parallel mode.

Conclusion

We will go with option 3 as it requires fewer decorators to be added to the language and makes the intent more explicit if the user doesn't know what "serial" or "parallel" means.

Coincidentally, the chosen option matches the original issue description. 😊