Skip to content

Commit

Permalink
Merge pull request #26 from lgallard/fix/selection-tags
Browse files Browse the repository at this point in the history
Add support for several selection tags
  • Loading branch information
lgallard authored Apr 7, 2021
2 parents 5dee4c7 + 75acc0d commit 92c9d86
Show file tree
Hide file tree
Showing 12 changed files with 95 additions and 89 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 0.9.0 (April 7, 2021)

FIXES:

* Add support for several selection tags
* Remove `selection_tag_type`, `selection_tag_key` and `selection_tag_value` in favour of a `selection_tags` list variable
* Update README and examples folder to include several selection tags examples

## 0.8.0 (April 7, 2021)

ENHANCEMENTS:
Expand Down
26 changes: 15 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,22 @@ module "aws_backup_example" {
{
name = "selection-1"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table1"]
selection_tag = {
type = "STRINGEQUALS"
key = "Environment"
value = "production"
}
selection_tag = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "production"
},
{
type = "STRINGEQUALS"
key = "Owner"
value = "production"
}
]
},
{
name = "selection-2"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table2"]
selection_tag = {}
name = "selection-2"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table2"]
},
]
Expand Down Expand Up @@ -145,9 +151,7 @@ No Modules.
| rules | A list of rule maps | `any` | `[]` | no |
| selection\_name | The display name of a resource selection document | `string` | `null` | no |
| selection\_resources | An array of strings that either contain Amazon Resource Names (ARNs) or match patterns of resources to assign to a backup plan | `list` | `[]` | no |
| selection\_tag\_key | The key in a key-value pair | `string` | `null` | no |
| 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 |
| selection\_tag\_value | The value in a key-value pair | `string` | `null` | no |
| selection\_tags | List of tags for `selection_name` var, when using variable definition. | `list` | `[]` | no |
| selections | A list of selction maps | `any` | `[]` | no |
| tags | A mapping of tags to assign to the resource | `map(string)` | `{}` | no |
| vault\_kms\_key\_arn | The server-side encryption key that is used to protect your backups | `string` | `null` | no |
Expand Down
23 changes: 15 additions & 8 deletions examples/complete_plan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,27 @@ module "aws_backup_example" {
{
name = "selection-1"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table1"]
selection_tag = {
type = "STRINGEQUALS"
key = "Environment"
value = "production"
}
selection_tag = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "production"
},
{
type = "STRINGEQUALS"
key = "Owner"
value = "production"
}
]
},
{
name = "selection-2"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table2"]
name = "selection-2"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table2"]
},
]
tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
19 changes: 13 additions & 6 deletions examples/complete_plan/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ module "aws_backup_example" {
{
name = "selection-1"
resources = ["arn:aws:dynamodb:us-east-1:123456789101:table/mydynamodb-table1"]
selection_tag = {
type = "STRINGEQUALS"
key = "Environment"
value = "production"
}
selection_tag = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "production"
},
{
type = "STRINGEQUALS"
key = "Owner"
value = "production"
}
]
},
{
name = "selection-2"
Expand All @@ -75,7 +82,7 @@ module "aws_backup_example" {
]

tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
34 changes: 16 additions & 18 deletions examples/selection_by_tags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,27 @@ module "aws_backup_example" {
]
# Multiple selections
# - Selection-1: Environment = prod
# - Selection-2: Backup = critical
# - Selection-1: By tags: Environment = prod, Owner = devops
selections = [
{
name = "selection-1"
selection_tag = {
type = "STRINGEQUALS"
key = "Environment"
value = "prod"
}
},
{
name = "selection-2"
selection_tag = {
type = "STRINGEQUALS"
key = "Backup"
value = "critial"
}
},
name = "selection-1"
selection_tag = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "production"
},
{
type = "STRINGEQUALS"
key = "Owner"
value = "devops"
}
]
}
]
tags = {
Owner = "backup team"
Owner = "devops"
Environment = "prod"
Terraform = true
}
Expand Down
34 changes: 16 additions & 18 deletions examples/selection_by_tags/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,27 @@ module "aws_backup_example" {
]

# Multiple selections
# - Selection-1: Environment = prod
# - Selection-2: Backup = critical
# - Selection-1: By tags: Environment = prod, Owner = devops
selections = [
{
name = "selection-1"
selection_tag = {
type = "STRINGEQUALS"
key = "Environment"
value = "prod"
}
},
{
name = "selection-2"
selection_tag = {
type = "STRINGEQUALS"
key = "Backup"
value = "critial"
}
},
name = "selection-1"
selection_tag = [
{
type = "STRINGEQUALS"
key = "Environment"
value = "production"
},
{
type = "STRINGEQUALS"
key = "Owner"
value = "devops"
}
]
}
]

tags = {
Owner = "backup team"
Owner = "devops"
Environment = "prod"
Terraform = true
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_plan/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module "aws_backup_example" {
]
tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_plan/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ module "aws_backup_example" {
]

tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_plan_using_variables/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module "aws_backup_example" {
# Tags
tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_plan_using_variables/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ module "aws_backup_example" {

# Tags
tags = {
Owner = "backup team"
Owner = "devops"
Environment = "production"
Terraform = true
}
Expand Down
12 changes: 4 additions & 8 deletions selection.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_backup_selection" "ab_selection" {
resources = lookup(element(local.selections, count.index), "resources", null)

dynamic "selection_tag" {
for_each = length(lookup(element(local.selections, count.index), "selection_tag", {})) == 0 ? [] : [lookup(element(local.selections, count.index), "selection_tag", {})]
for_each = length(lookup(element(local.selections, count.index), "selection_tag", [])) == 0 ? [] : lookup(element(local.selections, count.index), "selection_tag", [])
content {
type = lookup(selection_tag.value, "type", null)
key = lookup(selection_tag.value, "key", null)
Expand All @@ -23,13 +23,9 @@ locals {
# Selection
selection = var.selection_name == null ? [] : [
{
name = var.selection_name
resources = var.selection_resources
selection_tag = var.selection_tag_type == null ? {} : {
type = var.selection_tag_type
key = var.selection_tag_key
value = var.selection_tag_value
}
name = var.selection_name
resources = var.selection_resources
selection_tag = var.selection_tags
}
]

Expand Down
20 changes: 4 additions & 16 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,10 @@ variable "selection_resources" {
default = []
}

variable "selection_tag_type" {
description = "An operation, such as StringEquals, that is applied to a key-value pair used to filter resources in a selection"
type = string
default = null
}

variable "selection_tag_key" {
description = "The key in a key-value pair"
type = string
default = null
}

variable "selection_tag_value" {
description = "The value in a key-value pair"
type = string
default = null
variable "selection_tags" {
description = "List of tags for `selection_name` var, when using variable definition."
type = list
default = []
}

# Selection
Expand Down

0 comments on commit 92c9d86

Please sign in to comment.