Skip to content

Commit b6bfab3

Browse files
feat: add variable selection_conditions (#94)
* Add variables selection_conditions * fix: tf fmt --------- Co-authored-by: Matt Gowie <[email protected]>
1 parent 204c4ce commit b6bfab3

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

main.tf

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ resource "aws_backup_selection" "default" {
138138
plan_id = join("", aws_backup_plan.default[*].id)
139139
resources = var.backup_resources
140140
not_resources = var.not_resources
141+
141142
dynamic "selection_tag" {
142143
for_each = var.selection_tags
143144
content {
@@ -146,4 +147,38 @@ resource "aws_backup_selection" "default" {
146147
value = selection_tag.value["value"]
147148
}
148149
}
150+
151+
condition {
152+
dynamic "string_equals" {
153+
for_each = var.selection_conditions.string_equals
154+
content {
155+
key = "aws:ResourceTag/${string_equals.value.key}"
156+
value = string_equals.value.value
157+
}
158+
}
159+
160+
dynamic "string_like" {
161+
for_each = var.selection_conditions.string_like
162+
content {
163+
key = "aws:ResourceTag/${string_like.value.key}"
164+
value = string_like.value.value
165+
}
166+
}
167+
168+
dynamic "string_not_equals" {
169+
for_each = var.selection_conditions.string_not_equals
170+
content {
171+
key = "aws:ResourceTag/${string_not_equals.value.key}"
172+
value = string_not_equals.value.value
173+
}
174+
}
175+
176+
dynamic "string_not_like" {
177+
for_each = var.selection_conditions.string_not_like
178+
content {
179+
key = "aws:ResourceTag/${string_not_like.value.key}"
180+
value = string_not_like.value.value
181+
}
182+
}
183+
}
149184
}

variables.tf

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,29 @@ variable "selection_tags" {
7777
default = []
7878
}
7979

80+
variable "selection_conditions" {
81+
type = object({
82+
string_equals = optional(list(object({
83+
key = string
84+
value = string
85+
})), [])
86+
string_like = optional(list(object({
87+
key = string
88+
value = string
89+
})), [])
90+
string_not_equals = optional(list(object({
91+
key = string
92+
value = string
93+
})), [])
94+
string_not_like = optional(list(object({
95+
key = string
96+
value = string
97+
})), [])
98+
})
99+
description = "An array of conditions used to specify a set of resources to assign to a backup plan"
100+
default = {}
101+
}
102+
80103
variable "plan_name_suffix" {
81104
type = string
82105
description = "The string appended to the plan name"

0 commit comments

Comments
 (0)