I am trying to extract the values from map variable based on certain conditions as below :-
Variables.tf File content
variable "users" {
type = "map"
default = {
"101" = "abc@gmail.com"
"102" = "def@gmail.com"
"103" = "xyz@gmail.com"
"104" = "klm@gmail.com"
"105" = "pqr@gmail.com"
"106" = "tuv@gmail.com"
}
}
Below is my main.tf file
module "instance" {
instance_private_ip = ["11.12.13.x"]
dns_map = ["y"]
users = ["z"]
}
module "instance2" {
instance_private_ip = ["11.12.14.a"]
dns_map = ["b"]
users = ["c"]
}
The value x should be all even numbers in users variables like - 102, 104 and so on. The value y should be same as x The value z should be corresponding to x and y. The value a should be all even numbers in users variables like - 101, 103 and so on. The value b should be same as a The value c should be corresponding to a and b. Example as below
module "instance" {
instance_private_ip = ["11.12.13.102", "11.12.13.104", "11.12.13.106"]
dns_map = ["102","104","106"]
users = ["def@gmail.com","klm@gmail.com","tuv@gmail.com"]
}
module "instance2" {
instance_private_ip = ["11.12.14.101", "11.12.14.103", "11.12.14.105"]
dns_map = ["101","103","105"]
users = ["abc@gmail.com","xyz@gmail.com","pqr@gmail.com"]
}
I am trying with ${element(var.notebook[count.index])} but it will give me the username and not the left side variable.
Any help is appreciated