Abhinav
Abhinav

Reputation: 81

Pass conditions in values.yaml through terraform

I have a helm chart that i am trying to deploy with terraform. I have a requirement where i need to pass a condition in the values like i need to pass annotation ["test=foo"] for us-east-1 region and ["test=bar","test=foo"] for us-east-2 region. My main.tf looks like below

resource "helm_release" "chart_name" {
name       = "resource-name"
chart      = "${path.module}"
namespace  = "namespcae_name"
values = [

{
  flag = var.region == "us-east-1" ? ["test=foo"] : ["test=foo","test=bar"]
}

]

but i am getting an error Error: Invalid expression

Upvotes: 0

Views: 39

Answers (1)

Matthew Schuchard
Matthew Schuchard

Reputation: 28774

The values parameter should be a list(string) type, and not a list(map(string)) type. You need to modify the value to a list(string) where each string is in "raw YAML format" (most easily accomplished with yamlencode function to encode from HCL2):

values = [yamlencode({flag = var.region == "us-east-1" ? ["test=foo"] : ["test=foo","test=bar"]})]

Upvotes: 1

Related Questions