Skip to content

Commit 81d9bd2

Browse files
authored
Merge pull request #101 from lgallard/fix/retention-days
fix: Improve validation and configuration for AWS Backup vault
2 parents adfe619 + 0478f0d commit 81d9bd2

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

.github/.release-please-config.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
},
2929
"release-search-depth": 10,
3030
"include-component-in-tag": false,
31-
"include-v-in-tag": true,
31+
"include-v-in-tag": false,
3232
"date-formats": {
3333
"changelogDate": "(%B %d, %Y)"
3434
}

main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ resource "aws_backup_vault_lock_configuration" "ab_vault_lock_configuration" {
1616
min_retention_days = var.min_retention_days
1717
max_retention_days = var.max_retention_days
1818
changeable_for_days = var.changeable_for_days
19+
20+
lifecycle {
21+
precondition {
22+
condition = local.check_retention_days
23+
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."
24+
}
25+
}
1926
}
2027

2128
# AWS Backup plan
@@ -133,4 +140,13 @@ locals {
133140
)
134141
])
135142
])
143+
144+
# Check retention days - handling null values properly
145+
check_retention_days = var.locked ? (
146+
var.min_retention_days == null ? false : (
147+
var.max_retention_days == null ? false : (
148+
var.min_retention_days <= var.max_retention_days
149+
)
150+
)
151+
) : true
136152
}

variables.tf

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ 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-
}
5045
}
5146

5247
variable "changeable_for_days" {
@@ -66,8 +61,8 @@ variable "max_retention_days" {
6661
default = null
6762

6863
validation {
69-
condition = var.max_retention_days == null ? true : var.max_retention_days >= 1 && var.max_retention_days <= 36500
70-
error_message = "The max_retention_days must be between 1 and 36500 days."
64+
condition = var.max_retention_days == null ? true : var.max_retention_days >= 1
65+
error_message = "The max_retention_days must be greater than or equal to 1."
7166
}
7267
}
7368

0 commit comments

Comments
 (0)