Below is the code I am using now I have used for_each loop over a map but target_tags and source_tags are optional… So I dont want to pass target_tags or source_tags in every map… But Its throwing error… Its expecting some value… What can be the solution
resource "google_compute_firewall{
target_tags= var.target_tags
source_tags = var.source_tags
source_port = var.source_port
destination_port= var.destination_port
destination_ip = var.destination_ip
source_ip = var.source_ip
}
variable “target_tag” {
default =
}
variable “source_tag” {
default =
}
module “firewall”{
for_each = var.firewall
target_tags= each.value[“target_tags”] == null ? : each.value[“target_tags”]
source_tags = each.value[“source_tags”]== null ? : each.value[“source_tags”]
source_port = each.value[“source_port”]
destination_port= each.value[“dest_port”]
destination_ip = each.value["destination_ip]
source_ip = each.value[“source_ip”]
}
variable “firewall”{
type = map(any)
default = {
target_tags =
source_tags=
}
}
module firewall_config {
firewall= {
firewall1 = {
target_tags= [“t_tag1”]
source_tags = [“s_tag1”]
source_port =[“*”]
dest_port = [“8”]
destination_ip = [“8.8.8.8”]
source_ip = [“19.268.1.2”]
},
firewall2 = {
source_tags = “s_tag2”
source_port = “*”
dest_port = “80”
destination_ip = “0.0.0.0/0”
source_ip = “10.0.0.0/8”
}