Skip to content

Commit b180323

Browse files
author
Abdul Wahid
authored
Allow for multiple selection conditions for a backup plan (#4)
* Allow multiple tags for selection * Altering how selection condition resource are created For every backup plan that is created there will be only one selection condition resource. * Update example in README
1 parent c185d36 commit b180323

File tree

6 files changed

+57
-50
lines changed

6 files changed

+57
-50
lines changed

README.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,19 @@ module "backup" {
3939
}
4040
]
4141
42-
selections = [
42+
selection_name = "test-backup-selection"
43+
selection_resources = ["arn:aws:rds:eu-west-1:1111111111:cluster:example-dataabase-1"]
44+
45+
selection_tags = [
4346
{
44-
name = "test-backup-selection"
45-
resources = [
46-
"arn:aws:rds:eu-west-1:1111111111:cluster:example-database-1"
47-
]
48-
49-
selection_tag = {
50-
type = "STRINGEQUALS"
51-
key = "Environment"
52-
value = "test"
53-
}
47+
type = "STRINGEQUALS"
48+
key = "Project"
49+
value = "Test"
50+
},
51+
{
52+
type = "STRINGEQUALS"
53+
key = "Environment"
54+
value = "test"
5455
}
5556
]
5657
}
@@ -108,7 +109,7 @@ Module managed by:
108109
| selection\_tag\_key | The key in a key-value pair | `string` | `null` | no |
109110
| selection\_tag\_type | An operation, such as StringEquals, that is applied to a key-value pair used to filter resources in a selection | `string` | `null` | no |
110111
| selection\_tag\_value | The value in a key-value pair | `string` | `null` | no |
111-
| selections | A list of selection maps | `list` | `[]` | no |
112+
| selection\_tags | A list of selection tags map | `list` | `[]` | no |
112113
| tags | A mapping of tags to assign to the resource | `map(string)` | `{}` | no |
113114
| vault\_kms\_key\_arn | The server-side encryption key that is used to protect your backups | `string` | `null` | no |
114115
| vault\_name | Name of the backup vault to create. If not given, AWS use default | `string` | `null` | no |

examples/external-vault/main.tf

+11-7
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,18 @@ module "backup" {
9292
}
9393
]
9494

95-
selections = [
95+
selection_name = "test-backup-selection"
96+
97+
selection_tags = [
9698
{
97-
name = "test-backup-selection"
98-
selection_tag = {
99-
type = "STRINGEQUALS"
100-
key = "Environment"
101-
value = "test"
102-
}
99+
type = "STRINGEQUALS"
100+
key = "Project"
101+
value = "Test"
102+
},
103+
{
104+
type = "STRINGEQUALS"
105+
key = "Environment"
106+
value = "test"
103107
}
104108
]
105109

examples/multiple-dbs/main.tf

+16-13
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ module "backup" {
194194
target_vault_name = "test-rds-aurora"
195195
schedule = "cron(0 12 * * ? *)"
196196
start_window = "65"
197-
completion_window = "180"
197+
completion_window = "190"
198198
recovery_point_tags = {
199199
Project = "test"
200200
Region = "eu-west-1"
@@ -207,19 +207,22 @@ module "backup" {
207207
}
208208
]
209209

210-
selections = [
211-
{
212-
name = "test-backup-selection"
213-
resources = [
214-
module.aurora-mysql.rds_cluster_arn,
215-
module.aurora-postgresql.rds_cluster_arn
216-
]
210+
selection_name = "test-backup-selection"
211+
selection_resources = [
212+
module.aurora-mysql.rds_cluster_arn,
213+
module.aurora-postgresql.rds_cluster_arn
214+
]
217215

218-
selection_tag = {
219-
type = "STRINGEQUALS"
220-
key = "Environment"
221-
value = "test"
222-
}
216+
selection_tags = [
217+
{
218+
type = "STRINGEQUALS"
219+
key = "Project"
220+
value = "Test"
221+
},
222+
{
223+
type = "STRINGEQUALS"
224+
key = "Environment"
225+
value = "test"
223226
}
224227
]
225228
}

examples/one-db/main.tf

+12-11
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,19 @@ module "backup" {
183183
}
184184
]
185185

186-
selections = [
187-
{
188-
name = "test-backup-selection"
189-
resources = [
190-
module.aurora.rds_cluster_arn
191-
]
186+
selection_name = "test-backup-selection"
187+
selection_resources = [module.aurora.rds_cluster_arn]
192188

193-
selection_tag = {
194-
type = "STRINGEQUALS"
195-
key = "Environment"
196-
value = "test"
197-
}
189+
selection_tags = [
190+
{
191+
type = "STRINGEQUALS"
192+
key = "Project"
193+
value = "Test"
194+
},
195+
{
196+
type = "STRINGEQUALS"
197+
key = "Environment"
198+
value = "test"
198199
}
199200
]
200201
}

main.tf

+3-5
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@ resource "aws_backup_plan" "main" {
6565
# Backup Selection
6666
#####
6767
resource "aws_backup_selection" "main" {
68-
count = length(var.selections) >= 1 ? length(var.selections) : 0
69-
7068
iam_role_arn = aws_iam_role.main.arn
71-
name = lookup(element(var.selections, count.index), "name", null)
69+
name = var.selection_name
7270
plan_id = aws_backup_plan.main.id
7371

74-
resources = lookup(element(var.selections, count.index), "resources", null)
72+
resources = var.selection_resources
7573

7674
dynamic "selection_tag" {
77-
for_each = length(lookup(element(var.selections, count.index), "selection_tag", {})) == 0 ? [] : [lookup(element(var.selections, count.index), "selection_tag", {})]
75+
for_each = var.selection_tags
7876
content {
7977
type = lookup(selection_tag.value, "type", null)
8078
key = lookup(selection_tag.value, "key", null)

variables.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ variable "selection_tag_value" {
4242
default = null
4343
}
4444

45-
variable "selections" {
46-
description = "A list of selection maps"
45+
variable "selection_tags" {
46+
description = "A list of selection tags map"
4747
type = list
4848
default = []
4949
}

0 commit comments

Comments
 (0)