terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Both sides of ternary operator evaluated in extra_arguments block

Open jonwtech opened this issue 2 years ago • 1 comments

I am trying to conditionally set an environment variable depending on the value of a local variable. Simplified terragrunt.hcl:

locals {
  k8s_cluster = "mycluster"
}

terraform {
  extra_arguments "k8s_provider" {
    commands = ["init", "plan", "apply"]
    arguments = []
    env_vars = local.k8s_cluster == "mycluster" ? {
      KUBE_TOKEN = run_cmd("get_k8s_token.sh")
    } : {}
  }
}

What I am finding is, regardless of the value of local.mycluster, the run_cmd is always executed. Feels like a similar issue to https://github.com/gruntwork-io/terragrunt/issues/2172

I'm wondering whether Terragrunt still does Terraform <0.12-style ternary logic where both sides are evaluated and one discarded?

jonwtech avatar Nov 15 '22 16:11 jonwtech