Skip to content

Commit 091bc1a

Browse files
committed
2.3.1 fix hpa setup
1 parent 5f22a2e commit 091bc1a

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

18_horizontalPodAutoscaler.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "horizontalPodAutoscaler" {
1818
scale_target_ref {
1919
kind = var.podResourceType == "deployment" ? "Deployment" : "StatefulSet"
2020
name = var.podResourceType == "deployment" ? kubernetes_deployment_v1.deployment.0.metadata.0.name : kubernetes_stateful_set_v1.statefulset.0.metadata.0.name
21+
api_version = "apps/v1"
2122
}
2223

2324
dynamic "metric" {
@@ -40,8 +41,8 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "horizontalPodAutoscaler" {
4041
}
4142
target {
4243
type = metric.value.target.type
43-
average_value = metric.value.target.averageValue
44-
average_utilization = metric.value.target.averageUtilization
44+
average_value = metric.value.target.averageValue == 0 ? null : metric.value.target.averageValue
45+
average_utilization = metric.value.target.averageUtilization == 0 ? null : metric.value.target.averageUtilization
4546
value = metric.value.target.value
4647
}
4748
}
@@ -57,8 +58,8 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "horizontalPodAutoscaler" {
5758
}
5859
target {
5960
type = metric.value.target.type
60-
average_value = metric.value.target.averageValue
61-
average_utilization = metric.value.target.averageUtilization
61+
average_value = metric.value.target.averageValue == 0 ? null : metric.value.target.averageValue
62+
average_utilization = metric.value.target.averageUtilization == 0 ? null : metric.value.target.averageUtilization
6263
value = metric.value.target.value
6364
}
6465
}
@@ -69,8 +70,8 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "horizontalPodAutoscaler" {
6970
name = metric.value.name
7071
target {
7172
type = metric.value.target.type
72-
average_value = metric.value.target.averageValue
73-
average_utilization = metric.value.target.averageUtilization
73+
average_value = metric.value.target.averageValue == 0 ? null : metric.value.target.averageValue
74+
average_utilization = metric.value.target.averageUtilization == 0 ? null : metric.value.target.averageUtilization
7475
value = metric.value.target.value
7576
}
7677
}
@@ -86,8 +87,8 @@ resource "kubernetes_horizontal_pod_autoscaler_v2" "horizontalPodAutoscaler" {
8687
}
8788
target {
8889
type = metric.value.target.type
89-
average_value = metric.value.target.averageValue
90-
average_utilization = metric.value.target.averageUtilization
90+
average_value = metric.value.target.averageValue == 0 ? null : metric.value.target.averageValue
91+
average_utilization = metric.value.target.averageUtilization == 0 ? null : metric.value.target.averageUtilization
9192
value = metric.value.target.value
9293
}
9394
}

19_variables.tf

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -266,29 +266,29 @@ variable "horizontalPodAutoscaler" {
266266
}), null)
267267
target = optional(object({
268268
type = optional(string, "Utilization")
269-
averageValue = optional(string, 0)
270-
averageUtilization = optional(string, 75)
269+
averageValue = optional(number, 0)
270+
averageUtilization = optional(number, 75)
271271
value = optional(string, null)
272272
}), {})
273273
})), [{ type = "Resource", name = "cpu"}])
274274
behavior = optional(object({
275275
scaleDown = optional(object({
276-
stabilizationWindowSeconds = optional(string, 300)
276+
stabilizationWindowSeconds = optional(number, 300)
277277
selectPolicy = optional(string, "Min")
278278
policies = optional(list(object({
279-
periodSeconds = string
279+
periodSeconds = number
280280
type = optional(string, "Percent")
281-
value = string
282-
})), [{ periodSeconds = 60, value = "25"}])
281+
value = number
282+
})), [{ periodSeconds = 60, value = 25}])
283283
}), {})
284284
scaleUp = optional(object({
285-
stabilizationWindowSeconds = optional(string, 300)
285+
stabilizationWindowSeconds = optional(number, 0)
286286
selectPolicy = optional(string, "Max")
287287
policies = optional(list(object({
288-
periodSeconds = string
288+
periodSeconds = number
289289
type = optional(string, "Percent")
290-
value = string
291-
})), [{ periodSeconds = 15, value = "100"}])
290+
value = number
291+
})), [{ periodSeconds = 15, value = 100}])
292292
}), {})
293293
}), {})
294294
})

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## [2.3.1] - 2024-05-21
2+
3+
- fix kubernetes_horizontal_pod_autoscaler_v2 not working because of missing apiVersion config
4+
- adjust defaults for hpa
5+
6+
## [2.3.0] - 2024-04-22
7+
8+
- replace kubernetes_horizontal_pod_autoscaler_v2beta2 with kubernetes_horizontal_pod_autoscaler_v2
9+
110
## [2.2.0] - 2024-03-20
211

312
- added boolean `var.service.loadbalancer.forceNodePortType` to allow spawning lb service as type nodeport

0 commit comments

Comments
 (0)