Skip to content

Commit 4a21a68

Browse files
authored
Merge pull request #99 from lgallard/fix/retention-days-validations
fix: retention days validations
2 parents 2940f0b + 86ff7b0 commit 4a21a68

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

main.tf

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,16 @@ resource "aws_backup_vault" "ab_vault" {
66
kms_key_arn = var.vault_kms_key_arn
77
force_destroy = var.vault_force_destroy
88
tags = var.tags
9-
10-
lifecycle {
11-
precondition {
12-
condition = !var.locked || (var.min_retention_days != null && var.max_retention_days != null && var.min_retention_days <= var.max_retention_days)
13-
error_message = "When vault locking is enabled, min_retention_days and max_retention_days must be provided and min_retention_days must be less than or equal to max_retention_days."
14-
}
15-
}
169
}
1710

1811
# AWS Backup vault lock configuration
1912
resource "aws_backup_vault_lock_configuration" "ab_vault_lock_configuration" {
20-
count = var.locked && var.vault_name != null ? 1 : 0
13+
count = var.enabled && var.vault_name != null && var.locked ? 1 : 0
2114

2215
backup_vault_name = aws_backup_vault.ab_vault[0].name
23-
changeable_for_days = var.changeable_for_days
24-
max_retention_days = var.max_retention_days
2516
min_retention_days = var.min_retention_days
17+
max_retention_days = var.max_retention_days
18+
changeable_for_days = var.changeable_for_days
2619
}
2720

2821
# AWS Backup plan

variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ variable "locked" {
4242
description = "Change to true to add a lock configuration for the backup vault"
4343
type = bool
4444
default = false
45+
46+
validation {
47+
condition = !var.locked || (var.min_retention_days != null && var.max_retention_days != null && var.min_retention_days <= var.max_retention_days)
48+
error_message = "When vault locking is enabled (locked = true), min_retention_days and max_retention_days must be provided and min_retention_days must be less than or equal to max_retention_days."
49+
}
4550
}
4651

4752
variable "changeable_for_days" {

0 commit comments

Comments
 (0)