Complete the code to define an iterator variable in a Terraform for expression.
locals {
names = ["app", "db", "cache"]
upper_names = [for [1] in local.names : upper([1])]
}The iterator variable in a Terraform for expression is a placeholder for each element in the list. Here, item is used as the iterator variable.
Complete the code to create a map using an iterator variable in Terraform.
locals {
ports = [80, 443, 8080]
port_map = { for [1] in local.ports : [1] => "open" }
}The iterator variable port is used to represent each element in the list local.ports. It is used both as the key and in the expression.
Fix the error in the iterator variable usage in this Terraform for expression.
locals {
servers = ["web1", "web2"]
server_ids = [for [1] in local.servers : "id_${server}" ]
}The iterator variable must match the variable used inside the expression. Here, server is the correct iterator variable name.
Fill both blanks to create a map of server names to their uppercase versions using iterator variables.
locals {
servers = ["app", "db", "cache"]
upper_map = { for [1] in local.servers : [2] => upper([2]) }
}The iterator variable server is used consistently as the key and inside the upper() function.
Fill all three blanks to create a list of strings combining iterator variable and index in Terraform.
locals {
names = ["alpha", "beta", "gamma"]
combined = [for [2], [1] in local.names : "$[1]_$[2]"]
}The iterator variables are name and idx. The string combines the name and index using idx.