I'm trying to pass toleration values into helm using terraform. But I have got different error messages.
Default values of the chart are here.
...
tolerations:
[]
...
I use this code.
locals {
victoria_tolerations = [{ "key" : "k8s-app", "operator" : "Equal", "value" : "grafana", "effect" : "NoSchedule" }]
}
resource "helm_release" "victoria_metrics" {
name = var.vm_release_name
chart = var.vm_chart
repository = var.vm_chart_repository_url
version = var.vm_chart_version
namespace = local.namespace_victoria
max_history = var.max_history
set {
name = "vmselect.tolerations"
value = jsonencode(local.victoria_tolerations)
}
}
And have got the error message:
Error: failed parsing key "vmselect.tolerations" with value [{"effect":"NoSchedule","key":"k8s-app","operator":"Equal","value":"grafana"}], key "\"key\":\"k8s-app\"" has no value (cannot end with ,)
If I use this variable
victoria_tolerations = <<EOF
- key: k8s-app
operator: Equal
value: grafana
effect: NoSchedule
EOF
I have got this error:
Error: unable to build kubernetes objects from release manifest: error validating "": error validating data: ValidationError(Deployment.spec.template.spec.tolerations): invalid type for io.k8s.api.core.v1.PodSpec.tolerations: got "string", expected "array"
P.S.
Also, I tried to pass as values
. This doesn't work in this case.
locals {
victoria_values = {
"tolerations" : [
{
"key" : "k8s-app",
"operator" : "Equal",
"value" : "grafana",
"effect" : "NoSchedule"
}
]
}
}
resource "helm_release" "victoria_metrics" {
name = var.vm_release_name
...
values = [
yamlencode(local.victoria_values)
]
}
Try dynamic block
dynamic "toleration" {
for_each = var.tolerations
content {
key = toleration.value["key"]
operator = toleration.value["operator"]
value = toleration.value["value"]
effect = toleration.value["effect"]
}
}
var file
variable "tolerations" {
type = list(map(string))
default = []
description = "Tolerations to apply to deployment"
}
arg
tolerations = [
{
key = "node.kubernetes.io/role",
operator = "Equal",
value = "true",
effect = "NoSchedule"
}
]
Similar to @Rostyslav Malenko's answer but without dynamic
for_each
loops.
resource "helm_release" "victoria_metrics" {
name = var.vm_release_name
chart = var.vm_chart
repository = var.vm_chart_repository_url
version = var.vm_chart_version
namespace = local.namespace_victoria
max_history = var.max_history
set {
name = "vmselect.tolerations[0].key"
value= "k8s-app"
}
set {
name = "vmselect.tolerations[0].value"
value= "grafana"
}
set {
name = "vmselect.tolerations[0].operator"
value= "Equal"
}
set {
name = "vmselect.tolerations[0].effect"
value= "NoSchedule"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With