Quantcast
Channel: Terraform - HashiCorp Discuss
Viewing all articles
Browse latest Browse all 11468

Conditional and lists for a variable

$
0
0

@fauzigo wrote:

Greetings ladies and gentlemen,

I have a particular condition in one of my modules. Basically, I have a variable for a resource that the value is supposed to be a list, but I need the value to be set depending on a condition, the condition apparently can’t handle the resulted value of the condition and terraform ultimately exits.

To illustrate the issue:

input = "${data.aws_region.current.name == "us-east-1" ? var.availability_zones : list(data.aws_availability_zones.available.names)}"

When I run plan :

# terraform plan 
Running terraform plan   --var-file ./config.tfvars out plan.terraform /home/generic-commons/cloud-automation/tf_files/aws/eks/
gen3_aws_run terraform plan --var-file ./config.tfvars -out plan.terraform /home/generic-commons/cloud-automation/tf_files/aws/eks/

Error: module.eks.random_shuffle.az: input: should be a list

non zero exit code from terraform plan: 1 

For this particular case I’m running from “us-east-1” an the variable availability_zones should be the value for input. This is the variable configuration in variables.tf:

variable "availability_zones" {
  description = "AZ to be used by EKS nodes"
  type        = "list"
  default     = ["us-east-1a", "us-east-1c", "us-east-1d"]
}

I’m running:

$ terraform version 
Terraform v0.11.14

I can’t find a way to make it work. Hope this makes sense, but if not, please let me know.

Regards,

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 11468

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>