Adding data to a variable structure

First off I don’t particularly care how I achieve the goal. Under normal programming circumstances I would just add the data in looking for to the existing structure. Anyhow my problem is this.

I have a variable list of maps. The map is effectively an aws sg rule consisting of name of an sg to add to the rule and the protocol. This is the user input for creating an aws security group for a database with a dynamic ingress block. These sg names need to be converted to sg IDs. I can do this with a data source and count of the variable. But I’m having trouble figuring out how to reference this data source and the variable(for the protocol) in the dynamic ingress.

Any help would be appreciated.

Thanks