I know my expected result can be made using flatten built in function( which I have given below). But I want to know is there any way to create them only using nested for loops.
output "languages" {
value = flatten([
for user in var.users: [
for language in user.languages: language
]
])
}
This is my variable
variable "users" {
default = {
"sam" = {
"name" = "sam"
"age" = 22
"languages" = ["python","nodejs","perl","ruby"]
},
"john" = {
"name" = "john"
"age" = 36
"languages" = ["python","html","cpp","golang","perl","ruby"]
},
"kevin" = {
"name" = "kevin"
"age" = 30
"languages" = ["python","nodejs","bash","cpp","ruby"]
},
"devid" = {
"name" = "devid"
"age" = 40
"languages" = ["python","bash","perl","ruby"]
},
"devon" = {
"name" = "devon"
"age" = 25
"languages" = ["python"]
},
"jain" = {
"name" = "jain"
"age" = 42
"languages" = ["python","bash","perl","ruby"]
}
} }
This is mycode
output "languages" {
value = [
for user in var.users: [
for language in user.languages: language
]
]
}
Current Result
languages = [
[
"python",
"bash",
"perl",
"ruby",
],
[
"python",
],
[
"python",
"bash",
"perl",
"ruby",
],
[
"python",
"html",
"cpp",
"golang",
"perl",
"ruby",
],
[
"python",
"nodejs",
"bash",
"cpp",
"ruby",
],
[
"python",
"nodejs",
"perl",
"ruby",
],
]
Excepted Result
languages = [
"python",
"bash",
"perl",
"ruby",
"python",
"python",
"bash",
"perl",
"ruby",
"python",
"html",
"cpp",
"golang",
"perl",
"ruby",
"python",
"nodejs",
"bash",
"cpp",
"ruby",
"python",
"nodejs",
"perl",
"ruby",
]