-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathselection.tf
70 lines (62 loc) · 2.52 KB
/
selection.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
resource "aws_backup_selection" "ab_selection" {
count = var.enabled ? length(local.selections) : 0
iam_role_arn = var.iam_role_arn != null ? var.iam_role_arn : aws_iam_role.ab_role[0].arn
name = lookup(element(local.selections, count.index), "name", null)
plan_id = aws_backup_plan.ab_plan[0].id
resources = lookup(element(local.selections, count.index), "resources", null)
not_resources = lookup(element(local.selections, count.index), "not_resources", null)
dynamic "selection_tag" {
for_each = length(lookup(element(local.selections, count.index), "selection_tags", [])) == 0 ? [] : lookup(element(local.selections, count.index), "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 = lookup(lookup(element(local.selections, count.index), "conditions", {}), "string_equals", [])
content {
key = lookup(string_equals.value, "key", null)
value = lookup(string_equals.value, "value", null)
}
}
dynamic "string_like" {
for_each = lookup(lookup(element(local.selections, count.index), "conditions", {}), "string_like", [])
content {
key = lookup(string_like.value, "key", null)
value = lookup(string_like.value, "value", null)
}
}
dynamic "string_not_equals" {
for_each = lookup(lookup(element(local.selections, count.index), "conditions", {}), "string_not_equals", [])
content {
key = lookup(string_not_equals.value, "key", null)
value = lookup(string_not_equals.value, "value", null)
}
}
dynamic "string_not_like" {
for_each = lookup(lookup(element(local.selections, count.index), "conditions", {}), "string_not_like", [])
content {
key = lookup(string_not_like.value, "key", null)
value = lookup(string_not_like.value, "value", null)
}
}
}
}
locals {
# Selection
selection = var.selection_name == null ? [] : [
{
name = var.selection_name
resources = var.selection_resources
not_resources = var.selection_not_resources
conditions = var.selection_conditions
selection_tags = var.selection_tags
}
]
# Selections
selections = concat(local.selection, var.selections)
# Make sure the role can get tag resources
depends_on = [aws_iam_role_policy_attachment.ab_tag_policy_attach]
}