|
5 | 5 | ############################################################################## |
6 | 6 |
|
7 | 7 | locals { |
8 | | - kp_backup_crn = var.backup_encryption_key_crn != null ? var.backup_encryption_key_crn : var.key_protect_key_crn |
| 8 | + kp_backup_crn = var.backup_encryption_key_crn != null ? var.backup_encryption_key_crn : var.key_protect_key_crn |
| 9 | + auto_scaling_enabled = var.auto_scaling == null ? [] : [1] |
9 | 10 | } |
10 | 11 |
|
11 | 12 | # Create postgresql database |
@@ -48,34 +49,41 @@ resource "ibm_database" "postgresql_db" { |
48 | 49 | allocation_count = var.members |
49 | 50 | } |
50 | 51 | } |
51 | | - auto_scaling { |
52 | | - cpu { |
53 | | - rate_increase_percent = var.auto_scaling.cpu.rate_increase_percent |
54 | | - rate_limit_count_per_member = var.auto_scaling.cpu.rate_limit_count_per_member |
55 | | - rate_period_seconds = var.auto_scaling.cpu.rate_period_seconds |
56 | | - rate_units = var.auto_scaling.cpu.rate_units |
57 | | - } |
58 | | - disk { |
59 | | - capacity_enabled = var.auto_scaling.disk.capacity_enabled |
60 | | - free_space_less_than_percent = var.auto_scaling.disk.free_space_less_than_percent |
61 | | - io_above_percent = var.auto_scaling.disk.io_above_percent |
62 | | - io_enabled = var.auto_scaling.disk.io_enabled |
63 | | - io_over_period = var.auto_scaling.disk.io_over_period |
64 | | - rate_increase_percent = var.auto_scaling.disk.rate_increase_percent |
65 | | - rate_limit_mb_per_member = var.auto_scaling.disk.rate_limit_mb_per_member |
66 | | - rate_period_seconds = var.auto_scaling.disk.rate_period_seconds |
67 | | - rate_units = var.auto_scaling.disk.rate_units |
68 | | - } |
69 | | - memory { |
70 | | - io_above_percent = var.auto_scaling.memory.io_above_percent |
71 | | - io_enabled = var.auto_scaling.memory.io_enabled |
72 | | - io_over_period = var.auto_scaling.memory.io_over_period |
73 | | - rate_increase_percent = var.auto_scaling.memory.rate_increase_percent |
74 | | - rate_limit_mb_per_member = var.auto_scaling.memory.rate_limit_mb_per_member |
75 | | - rate_period_seconds = var.auto_scaling.memory.rate_period_seconds |
76 | | - rate_units = var.auto_scaling.memory.rate_units |
| 52 | + |
| 53 | + ## This for_each block is NOT a loop to attach to multiple auto_scaling blocks. |
| 54 | + ## This block is only used to conditionally add auto_scaling block depending on var.auto_scaling |
| 55 | + dynamic "auto_scaling" { |
| 56 | + for_each = local.auto_scaling_enabled |
| 57 | + content { |
| 58 | + cpu { |
| 59 | + rate_increase_percent = var.auto_scaling.cpu.rate_increase_percent |
| 60 | + rate_limit_count_per_member = var.auto_scaling.cpu.rate_limit_count_per_member |
| 61 | + rate_period_seconds = var.auto_scaling.cpu.rate_period_seconds |
| 62 | + rate_units = var.auto_scaling.cpu.rate_units |
| 63 | + } |
| 64 | + disk { |
| 65 | + capacity_enabled = var.auto_scaling.disk.capacity_enabled |
| 66 | + free_space_less_than_percent = var.auto_scaling.disk.free_space_less_than_percent |
| 67 | + io_above_percent = var.auto_scaling.disk.io_above_percent |
| 68 | + io_enabled = var.auto_scaling.disk.io_enabled |
| 69 | + io_over_period = var.auto_scaling.disk.io_over_period |
| 70 | + rate_increase_percent = var.auto_scaling.disk.rate_increase_percent |
| 71 | + rate_limit_mb_per_member = var.auto_scaling.disk.rate_limit_mb_per_member |
| 72 | + rate_period_seconds = var.auto_scaling.disk.rate_period_seconds |
| 73 | + rate_units = var.auto_scaling.disk.rate_units |
| 74 | + } |
| 75 | + memory { |
| 76 | + io_above_percent = var.auto_scaling.memory.io_above_percent |
| 77 | + io_enabled = var.auto_scaling.memory.io_enabled |
| 78 | + io_over_period = var.auto_scaling.memory.io_over_period |
| 79 | + rate_increase_percent = var.auto_scaling.memory.rate_increase_percent |
| 80 | + rate_limit_mb_per_member = var.auto_scaling.memory.rate_limit_mb_per_member |
| 81 | + rate_period_seconds = var.auto_scaling.memory.rate_period_seconds |
| 82 | + rate_units = var.auto_scaling.memory.rate_units |
| 83 | + } |
77 | 84 | } |
78 | 85 | } |
| 86 | + |
79 | 87 | lifecycle { |
80 | 88 | ignore_changes = [ |
81 | 89 | # Ignore changes to these because a change will destroy and recreate the instance |
|
0 commit comments