MarcusScipio
MarcusScipio

Reputation: 23

[Terraform]│ The given key does not identify an element in this collection value

Trying to understand what exactly am I missing here in my terraform module(Cloudflare).

Currently developing it but I've hit a stone with this one: Code:

## Variables
variable "filters" {
  description = "required filters for the firwall rules"
  type = map(object({
    description = string
    expression = string
  }))
  default = {
    "filters1" = {
      description = "test-rule"
      expression = "test-exps"
    }
  }
  
}
variable "firewall-rules" {
    description = "A set of Firewall rules"
    type = map(object({
      description = string
      action = string
    }))
    default = {
     "rules1" = {
        description = "value"
        action = "value"
      }
    }

## Resources
resource "cloudflare_filter" "firewall-filters" {
  zone_id = var.zone_id
  for_each = var.filters
  description = each.value["description"]
  expression = each.value["expression"]
  
}
resource "cloudflare_firewall_rule" "firewall-rules" {
  zone_id = var.zone_id
  for_each = var.firewall-rules
  filter_id = cloudflare_filter.firewall-filters
  description = each.value["description"]
  action = each.value["action"] 
}

Ignore "value" it's for testing purpose. Technically shouldn't the for_each work fine, while filter_id points to

"cloudflare_filter.firewall-filters", which inherits the values from the variable "filters".

Thank you in advance!

Upvotes: 0

Views: 573

Answers (0)

Related Questions