Skip to content

Commit

Permalink
Simplify conflicting restore_to_point_in_time attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ericluria committed Jun 7, 2024
1 parent 5e88edd commit dff6433
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 18 deletions.
23 changes: 6 additions & 17 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,6 @@ locals {
is_regional_cluster = var.cluster_type == "regional"
is_serverless = var.engine_mode == "serverless"
ignore_admin_credentials = var.replication_source_identifier != "" || var.snapshot_identifier != null

# Only set one of `use_latest_restorable_time` and `restore_to_time` since they conflict.
# For backwards compatibility, `use_latest_restorable_time` defaults to true if both of these values are null.
restore_to_point_in_time_configuration = [for config in var.restore_to_point_in_time : {
source_cluster_identifier = config.source_cluster_identifier
restore_type = config.restore_type
use_latest_restorable_time = (
config.use_latest_restorable_time == null && config.restore_to_time == null ?
true :
coalesce(config.use_latest_restorable_time, true)
)
restore_to_time = config.restore_to_time
}]
}

data "aws_partition" "current" {
Expand Down Expand Up @@ -163,11 +150,13 @@ resource "aws_rds_cluster" "primary" {
}

dynamic "restore_to_point_in_time" {
for_each = local.restore_to_point_in_time_configuration
for_each = var.restore_to_point_in_time
content {
source_cluster_identifier = restore_to_point_in_time.value.source_cluster_identifier
restore_type = restore_to_point_in_time.value.restore_type
use_latest_restorable_time = restore_to_point_in_time.value.use_latest_restorable_time
source_cluster_identifier = restore_to_point_in_time.value.source_cluster_identifier
restore_type = restore_to_point_in_time.value.restore_type
# use_latest_restorable_time and restore_to_time are mutually exclusive.
# If restore_to_time is given, then we ignore use_latest_restorable_time
use_latest_restorable_time = restore_to_point_in_time.value.restore_to_time != null ? null : restore_to_point_in_time.value.use_latest_restorable_time
restore_to_time = restore_to_point_in_time.value.restore_to_time
}
}
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ variable "restore_to_point_in_time" {
type = list(object({
source_cluster_identifier = string
restore_type = optional(string, "copy-on-write")
use_latest_restorable_time = optional(bool, null)
use_latest_restorable_time = optional(bool, true)
restore_to_time = optional(string, null)
}))
default = []
Expand Down

0 comments on commit dff6433

Please sign in to comment.