Method for tagging based on user group?

Hello, I have yet another automatic tagging question. I was wondering if there was a way to tag the vm based on the owner group of the user that’s requesting the service? What I wanted to do was have users joined to groups, and have the vms/instances they request tagged with the owner tag that the group has access to in order to restrict viewing the vms to just that group. Is this possible? I’m not sure how to code it for that, the other threads shows a static tag to assign.

Also, I’m trying to tag (for AWS instances) based on the flavor of instance, so I can do proper chargebacks based on the EC2 sizing. I was thinking we could do it via Policy, but I don’t see a field that pertains to that value, so I’m guessing I need to code it as well?

I’m a newbie to Ruby (and coding in general), so this has been a very steep learning curve for me. Any help is really appreciated!

Try to use vm_provisioned event and vm relationship to group.


You can do it by creating a method that get user group tag from user and apply those tag to the machine, something like:
prov = $evm.root[“miq_provision”]
user = prov.miq_request.requester
ugroup = user.current_group
filters = ugroup.filters
and then use prov.add_tag to tag the resource.