Hello, I’ve a resource kms
I moved from count
to for_each
however I can not manage some moments:
toset
function doesn’t working, the types should be identical, I don’t know how to convert
Could someone please assist on this
Here is the main.tf
resource "aws_kms_key" "global" {
for_each = toset( var.create_keys ? { for keys in var.parameters : keys.name => keys } : [] ) < Problem
is_enabled = var.create_keys
policy = data.template_file.key_service.rendered
key_usage = lookup(each.value, "usage", "" )
description = lookup(each.value, "description", "" )
enable_key_rotation = lookup(each.value, "rotation", false )
deletion_window_in_days = lookup(each.value, "lifetime", "" )
customer_master_key_spec = lookup(each.value, "customer", "" )
lifecycle {
create_before_destroy = false
ignore_changes = [ policy ]
}
tags = var.tags
}
Variables as well
variable "parameters" {
description = "The parameters of key(s)"
type = list(map(string))
default = null
}
variable "create_keys" {
description = "Condition to create key"
type = bool
default = true
}