From 225f9e22471f53a98092a1224fafe0a173f7233e Mon Sep 17 00:00:00 2001 From: Leonardo Biffi Date: Mon, 11 Nov 2024 10:38:34 -0400 Subject: [PATCH] Add variables selection_conditions --- main.tf | 35 +++++++++++++++++++++++++++++++++++ variables.tf | 23 +++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/main.tf b/main.tf index 9557b4d..42a0a2b 100644 --- a/main.tf +++ b/main.tf @@ -138,6 +138,7 @@ resource "aws_backup_selection" "default" { plan_id = join("", aws_backup_plan.default[*].id) resources = var.backup_resources not_resources = var.not_resources + dynamic "selection_tag" { for_each = var.selection_tags content { @@ -146,4 +147,38 @@ resource "aws_backup_selection" "default" { value = selection_tag.value["value"] } } + + condition { + dynamic "string_equals" { + for_each = var.selection_conditions.string_equals + content { + key = "aws:ResourceTag/${string_equals.value.key}" + value = string_equals.value.value + } + } + + dynamic "string_like" { + for_each = var.selection_conditions.string_like + content { + key = "aws:ResourceTag/${string_like.value.key}" + value = string_like.value.value + } + } + + dynamic "string_not_equals" { + for_each = var.selection_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 = var.selection_conditions.string_not_like + content { + key = "aws:ResourceTag/${string_not_like.value.key}" + value = string_not_like.value.value + } + } + } } diff --git a/variables.tf b/variables.tf index e3ba782..28678ea 100644 --- a/variables.tf +++ b/variables.tf @@ -77,6 +77,29 @@ variable "selection_tags" { default = [] } +variable "selection_conditions" { + type = object({ + string_equals = optional(list(object({ + key = string + value = string + })), []) + string_like = optional(list(object({ + key = string + value = string + })), []) + string_not_equals = optional(list(object({ + key = string + value = string + })), []) + string_not_like = optional(list(object({ + key = string + value = string + })), []) + }) + description = "An array of conditions used to specify a set of resources to assign to a backup plan" + default = {} +} + variable "plan_name_suffix" { type = string description = "The string appended to the plan name"