Question - combining map and list while adding data to each

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.

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)" }
# ]

You need: For Expressions - Configuration Language | Terraform by HashiCorp

Something along the lines of:

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..."],
)
1 Like

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:

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)" }
# ]