CSV driven terraform security groups deployment

Hi Everyone,
Currently, I looking for options to create multiple security groups with different set of rules data driven from a csv file. Assume I have the first 5 rows of rules for security group1 & next 5rows of rules for security group2 or on other case i have multiple sheets in csv file were 1st sheet contains rules of security group1 & second sheet contains rules of security group2. Please help me to achieve my requirement for aws terraform deployment. How can i do it. can someone share sample code.