Skip to content

Commit 5e36dd2

Browse files
authored
Make backup_configuration optional (#14)
* Make backup_configuration optional * Typo
1 parent ad7e8d4 commit 5e36dd2

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

locals.tf renamed to _locals.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ locals {
1212

1313
# Helper vars for optional blocks. Will either be an empty set (no) or a
1414
# single item set (yes)
15-
needs_maintenance_window = var.primary_instance_name == null ? [0] : []
15+
needs_backup_configuration = var.primary_instance_name == null ? [0] : []
16+
needs_maintenance_window = var.primary_instance_name == null ? [0] : []
1617
}

outputs.tf renamed to _outputs.tf

File renamed without changes.

main.tf renamed to _terraform.tf

File renamed without changes.
File renamed without changes.

instance.tf

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ resource "google_sql_database_instance" "instance" {
1515
tier = local.tier
1616
user_labels = local.labels
1717

18-
backup_configuration {
19-
enabled = coalesce(var.backup_config.enabled, var.highly_available)
20-
start_time = var.backup_config.start_time
21-
point_in_time_recovery_enabled = var.backup_config.point_in_time_recovery_enabled
22-
location = coalesce(var.backup_config.enabled, var.highly_available) ? var.backup_config.location : null
23-
transaction_log_retention_days = var.backup_config.transaction_log_retention_days
24-
backup_retention_settings {
25-
retained_backups = var.backup_config.retained_backups
26-
retention_unit = "COUNT"
18+
dynamic "backup_configuration" {
19+
for_each = local.needs_backup_configuration
20+
21+
content {
22+
enabled = coalesce(var.backup_config.enabled, var.highly_available)
23+
start_time = var.backup_config.start_time
24+
point_in_time_recovery_enabled = var.backup_config.point_in_time_recovery_enabled
25+
location = coalesce(var.backup_config.enabled, var.highly_available) ? var.backup_config.location : null
26+
transaction_log_retention_days = var.backup_config.transaction_log_retention_days
27+
backup_retention_settings {
28+
retained_backups = var.backup_config.retained_backups
29+
retention_unit = "COUNT"
30+
}
2731
}
2832
}
2933

0 commit comments

Comments
 (0)