I'm trying to create an azure lb rule using element and here's the error message and the code listed below.
What should I be changing within my main.tf file or variables.tf file to get the element to work. However, when I provide ports directly (which are commented) the code executes without any issues.
1 error(s) occurred:
azurerm_lb_rule.test: 1 error(s) occurred:
azurerm_lb_rule.test: At column 3, line 1: element: argument 1 should be type list, got type string in:
${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 2)}
main.tf
resource "azurerm_lb_rule" "test" {
resource_group_name = "${azurerm_resource_group.test.name}"
loadbalancer_id = "${azurerm_lb.lb.id}"
name = "LBRule"
protocol = "Tcp"
#frontend_port = 3389
#backend_port = 3389
protocol = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 0)}"
frontend_port = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 1)}"
backend_port = "${element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 2)}"
frontend_ip_configuration_name = "${var.frontend_name}"
}
variables.tf
variable "lb_port" {
description = "Protocols to be used for lb health probes and rules."
default = {"var1" = "tcp,3389,3389"}
}
${tolist(element(var.lb_port["${element(keys(var.lb_port), count.index)}"], 2))}- 4c74356b41