Provide each: in software templates
See original GitHub issueFeature Suggestion
Consider the example of creating virtual machines via a gitops process. If we consider backstage as it currently functions, we can articulate this sort of thing as:
spec:
parameters:
# ...
steps:
- name: fetch-repo
action: fetch:plain
- name: fetch-template
action: fetch:template
- name: publish
action: publish:github:pull-request
Now imagine we want to make more than one of these for some static N. We can obviously fill this out multiple times but there should be a better way!
Consider also the case of collecting user input in an array form and wanting to do things for each of them. In the VM request form, I may be hitting “add item” in an array input to add multiple things, or using a multiselect, or any number of possible inputs to add additional VMs I wish to create, and I want to act across these. This currently is not possible via backstage without making custom actions that call out to specific actions for each permutation of this.
It would be fantastic if each of these were solvable, and would allow all manners of automation possibilities using backstage templates.
Possible Implementation
If we just consider what we may like to do in some sort of repeating block, we could tell it to do something N times and if we had access to the index, we could coerce backstage to grab that element where it matters.
- name: Fetch Template
action: fetch:template
times: 10
input:
url: ./template
targetPath: '...'
values:
version: ${{parameters.version}}
index: ${{index}}
object: ${{parameters.objects[$index]}}
We may also want to iterate over them, so something like:
- name: Fetch Template
action: fetch:template
each: ${{parameters.objects}}
input:
url: ./template
targetPath: '...'
values:
version: ${{parameters.version}}
index: ${{index}}
object: ${{object}}
We can probably coerce nunjucks to generate 0…n from an n, so we could get by with just the second I think.
I don’t think ${{object}}
or ${{index}}
are necessarily good ways to articulate those, but illustrate the idea.
Context
There are a large number of automations that boil down to “ask user for input and do it a bunch of times” and I think backstage is exceptionally positioned to be able to make these go away with largely the same primitives that make software templates so useful for n=1.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:18 (11 by maintainers)
Throwing in a possible naming choice here that keeps the number of top-level names low and keeps things a bit namespaced
I think fundamentally, if I can do an action once, it shouldn’t require me making a custom action to do it more than once. That burden seems too high to impose on users, IMO. A custom action makes composing them much harder and requires you to surface details like required, inputs, outputs in multiple places which feels burdensome on users. It will also result in excessive wrapping of built ins, which just feels wrong, to me. If there was a way to generically compose things, I think I’d be a little more open to that, where instead of needing to create a new one, you could tell it you want to do an action multiple times and it do the legwork for you. But I think needing to write it yourself every single time is a bit heavy handed here.