Skip to content

Commit

Permalink
fix: add copy_actions variable
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmacedot committed Nov 8, 2024
1 parent eb852ff commit 144ea00
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions variables.tf → _variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ variable "rules" {
cold_storage_after = optional(number)
delete_after = optional(number, 30)
}))
copy_actions = optional(list(object({
destination_vault_arn = optional(string)
lifecycle = optional(object({
cold_storage_after = optional(number)
delete_after = optional(number, 30)
}), {})
})), [])
}))
default = [{
rule_name = "backup-rule"
Expand Down
6 changes: 3 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ resource "aws_backup_plan" "backup_plan" {
dynamic "copy_action" {
for_each = lookup(rule.value, "copy_actions", [])
content {
destination_vault_arn = lookup(copy_action.value, "vault_arn", aws_backup_vault.backup_vault.arn)
destination_vault_arn = lookup(copy_action.value, "destination_vault_arn", aws_backup_vault.backup_vault.arn)

# Copy Action Lifecycle
dynamic "lifecycle" {
for_each = length(lookup(copy_action.value, "lifecycle", {})) == 0 ? [] : [lookup(copy_action.value, "lifecycle", {})]
content {
cold_storage_after = lookup(rule.value, "enable_continuous_backup", false) == true ? null : lookup(lifecycle.value, "cold_storage_after", 7)
cold_storage_after = lookup(rule.value, "enable_continuous_backup", false) == true ? null : lookup(lifecycle.value, "cold_storage_after", 7)
delete_after = try(lifecycle.value.delete_after, 35)
}
}
Expand Down Expand Up @@ -85,7 +85,7 @@ resource "aws_backup_selection" "tag" {
# AWS Backup selection - resources arn
resource "aws_backup_selection" "resources" {
count = var.enabled ? length(var.selection_resources) > 0 && var.account_type == local.account_type.workload ? length(var.selection_resources) : 0 : 0
name = replace("${element(split(":", var.selection_resources[count.index]), 2)}-${element(split(":", var.selection_resources[count.index]), length(split(":", var.selection_resources[count.index])) - 1)}-${count.index}", "/", "-")
name = replace("${element(split(":", var.selection_resources[count.index]), 2)}-${element(split(":", var.selection_resources[count.index]), length(split(":",var.selection_resources[count.index]))-1)}-${count.index}", "/", "-")
iam_role_arn = aws_iam_role.backup_role[0].arn
plan_id = aws_backup_plan.backup_plan[0].id
resources = [var.selection_resources[count.index]]
Expand Down

0 comments on commit 144ea00

Please sign in to comment.