# Question - combining map and list while adding data to each

**URL:** <https://discuss.hashicorp.com/t/question-combining-map-and-list-while-adding-data-to-each/39069>\
**Category:** Terraform\
**Created:** [May 4, 2022, 5:05pm UTC](https://discuss.hashicorp.com/t/question-combining-map-and-list-while-adding-data-to-each/39069 "2022-05-04T17:05:50Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![samspade21](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/samspade21/32/27889_2.png) [@samspade21](https://discuss.hashicorp.com/u/samspade21)\
**Post date:** [May 4, 2022, 5:05pm UTC](https://discuss.hashicorp.com/t/question-combining-map-and-list-while-adding-data-to-each/39069/1 "2022-05-04T17:05:50Z")

</div>

I could use some help figuring out how to combine a list of strings with a map (key/value) and then this new map has a different value.

```auto
variable "app_roles_with_rule" {
  type = map(any)
  default = { "User" = "user.userType == 'hrisUser' AND user.employmentStatus == 'Active'" }
}
variable "app_roles_without_rule" {
  type = list(string)
  default = ["Admin", "Super_Duper_Admin"]
}
variable "app_name" {
  type = string
  default = "FancyPantsApp"  
}

locals {
  all_app_roles = {
    #Fake psudo code:
    #
    #all_app_roles = {}
    #for single_role in app_roles_with_rule
    # {
    # all_app_roles += {single_role : "Application: ${var.app_name} - ${single_role.key} Role (with default access rules)"}
    # }
    #for single_role in app_roles_without_rule
    # {
    # all_app_roles += {single_role : "Application: ${var.app_name} - ${single_role} Role (without default access rules)"}
    # }
  }
}

output "example" {
  value = local.all_app_roles
}

# local.all_app_roles returns this
# [
# { "User" = "Application: FancyPantsApp - User Role (with default access rules)" },
# { "Admin" = "Application: FancyPantsApp - Admin Role (without default access rules)" },
# { "Super_Duper_Admin" = "Application: FancyPantsApp - Super_Duper_Admin Role (without default access rules)" }
# ]

```

---

<div class="post-metadata">

**Author:** ![maxb](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/maxb/32/26655_2.png) [@maxb](https://discuss.hashicorp.com/u/maxb)\
**Post date:** [May 4, 2022, 5:34pm UTC](https://discuss.hashicorp.com/t/question-combining-map-and-list-while-adding-data-to-each/39069/2 "2022-05-04T17:34:31Z")

</div>

You need: [For Expressions - Configuration Language | Terraform by HashiCorp](https://www.terraform.io/language/expressions/for)

Something along the lines of:

```auto
concat(
[for k, v in var.app_roles_with_rule : "...fill me in..."],
[for k, v in var.app_roles_without_rule : "...fill me in..."],
)

```

---

<div class="post-metadata">

**Author:** ![samspade21](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/samspade21/32/27889_2.png) [@samspade21](https://discuss.hashicorp.com/u/samspade21)\
**Post date:** [May 4, 2022, 11:02pm UTC](https://discuss.hashicorp.com/t/question-combining-map-and-list-while-adding-data-to-each/39069/3 "2022-05-04T23:02:16Z")

</div>

Thank you so much, that led me down the path I needed. Here is the final answer for anyone who has the exact same issue:

```auto
variable "app_roles_with_rule" {
  type = map(any)
  default = { "User" = "user.userType == 'hrisUser' AND user.employmentStatus == 'Active'" }
}
variable "app_roles_without_rule" {
  type = list(string)
  default = ["Admin", "Super_Duper_Admin"]
}
variable "app_name" {
  type = string
  default = "FancyPantsApp"
}

locals {
  all_app_roles = merge(
    {for k, v in var.app_roles_with_rule : k => "Application: ${var.app_name} - ${k} Role (with default access rules)"},
    {for k in var.app_roles_without_rule : k => "Application: ${var.app_name} - ${k} Role (without default access rules)"},
  )
}

output "example" {
  value = local.all_app_roles
}

# local.all_app_roles returns this
# [
# { "User" = "Application: FancyPantsApp - User Role (with default access rules)" },
# { "Admin" = "Application: FancyPantsApp - Admin Role (without default access rules)" },
# { "Super_Duper_Admin" = "Application: FancyPantsApp - Super_Duper_Admin Role (without default access rules)" }
# ]

```
