Thanks for the effort in explaining these alternatives. I apologize I didn't do justice to explaining the bigger picture in the first place.
So here it goes:
Goal: Use hiera to provision different groups of users in different environments.
Approach: First create virtual users from hiera that lists all possible users and then realizing "collection" of users that are also defined in hiera using the <| expression |> to combine various groups. I like this approach because I can list every possible user in a single hiera file so I can keep the UIDs sequential as I add new users, etc.
So the main problem here is that the thing that goes between the spaceship operators is dynamic.
I am using erwbgy/puppet-system module which has been extended to support virtual users.
E.g. My hieradata would look like this:
- common.yaml:
- system::virt_users:
- 'user1':
- uid: 1001
- groups: ["A", "B", "C"]
- 'user2':
- 'user3':
- and so on....
- production.yaml:
- system::realize_users: group == "A"
- qa.yaml:
- system::realize_users: group == "A" or group == "B"
- dev.yaml:
- system::realize_users: # empty value that should mean all matching virtual users like <| |>
So the "foo" class in my original post would really be something like this:
# system module does hiera lookup in init.pp but I am simplifying below to make code concise for this discussion
class system::realize_users ( $collection=hiera("system::realize_users") {
User <| $collection |>
}
I am not married to this approach or module. So any other approach to achieve my goal listed above would do.