# Loop though nested map to build Security Groups

**URL:** <https://discuss.hashicorp.com/t/loop-though-nested-map-to-build-security-groups/23161>\
**Category:** Terraform\
**Created:** [April 14, 2021, 8:38pm UTC](https://discuss.hashicorp.com/t/loop-though-nested-map-to-build-security-groups/23161 "2021-04-14T20:38:45Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![bennielamb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/bennielamb/32/16334_2.png) [@bennielamb](https://discuss.hashicorp.com/u/bennielamb)\
**Post date:** [April 14, 2021, 8:38pm UTC](https://discuss.hashicorp.com/t/loop-though-nested-map-to-build-security-groups/23161/1 "2021-04-14T20:38:45Z")

</div>

Hello,

I am trying to figure out how to loop through a nested Map of Security Groups in order to build them out from a higher module where actual variables are contained. In this lower-level module, I want to cut the config lines down with iteration. An example map in variables.tf is below:

variable s\_groups\_dev {  
default = {  
“kube\_master” = {  
“name” = “kube\_master”  
“description” = “Security Group for Kube Master”  
“vpc\_id” = “vpc-03da2faf5b1c79290”  
},  
“kube\_master\_instance\_access\_egress” = {  
"name " = “kube\_master\_instance\_access\_egress”  
“description” = “desc”  
“vpc\_id” = “vpc-03da2faf5b1c79290”  
}  
}  
}

I want to loop thorugh the keys kube-master, and kube\_master\_instance\_access\_egress in the map s\_groups\_dev. While on kube-master, I need to build a SG for it using the 3 maps (name, description, and vpc\_id). I don’t know how to do this in Terraform and have been looking everywhere. I think 'for k1, k2, v in s\_groups\_dev could work, but don’t know how to make it work for the 3 lower maps mentioned above.

Any help would be awesome
