getting below error for aws backup selection
│ Error: Invalid index
│
│ on backup/module/backup-selection.tf line 26, in resource “aws_backup_selection” “ab_selection”:
│ 26: for_each = local.backup_selections[count.index].conditions.string_equals[count.index].key != “null” ? local.backup_selections[count.index].conditions.string_equals :
│ ├────────────────
│ │ count.index is 1
│ │ local.backup_selections is tuple with 2 elements
│
│ The given key does not identify an element in this collection value: the
│ given index is greater than or equal to the length of the collection.
for the code
resource “aws_backup_selection” “ab_selection” {
count = local.backup_selection.create_backup_selection ? length(local.backup_selections) : 0
name = local.backup_selections[count.index].selection_name
plan_id = aws_backup_plan.ab_plan[local.backup_selections[count.index].selection_plan_index].id
iam_role_arn = data.aws_iam_role.ab_selection_iamrole[0].arn
resources = try(local.backup_selection.backup_selections[count.index].resources != null ? split(“,”, local.backup_selections[count.index].resources) : local.input_defaults.resources, local.input_defaults.resources)
not_resources = try(local.backup_selection.backup_selections[count.index].not_resources != null ? local.backup_selection.backup_selections[count.index].not_resources : local.input_defaults.not_resources, local.input_defaults.not_resources)
dynamic “selection_tag” {
for_each = try(local.backup_selection.backup_selections[count.index].selection_tags != null ? local.backup_selection.backup_selections[count.index].selection_tags : local.input_defaults.selection_tags, local.input_defaults.selection_tags)
content {
type = lookup(selection_tag.value, “type”, null)
key = lookup(selection_tag.value, “key”, null)
value = lookup(selection_tag.value, “value”, null)
}
}
condition {
dynamic “string_equals” {
for_each = local.backup_selections[count.index].conditions.string_equals[count.index].key != “null” ? local.backup_selections[count.index].conditions.string_equals :
content {
key = “aws:ResourceTag/{string_equals.value.key}"
value = string_equals.value.value
}
}
dynamic "string_like" {
for_each = local.backup_selections[count.index].conditions.string_like[count.index].key != "null" ? local.backup_selections[count.index].conditions.string_like : []
content {
key = "aws:ResourceTag/{string_like.value.key}”
value = string_like.value.value
}
}
dynamic “string_not_equals” {
for_each = local.backup_selections[count.index].conditions.string_not_equals[count.index].key != “null” ? local.backup_selections[count.index].conditions.string_not_equals :
content {
key = “aws:ResourceTag/{string_not_equals.value.key}"
value = string_not_equals.value.value
}
}
dynamic "string_not_like" {
for_each = local.backup_selections[count.index].conditions.string_not_like[count.index].key != "null" ? local.backup_selections[count.index].conditions.string_not_like : []
content {
key = "aws:ResourceTag/{string_not_like.value.key}”
value = string_not_like.value.value
}
}
}
}