Hi there,
I have a list of s3 buckets to be initialized based on a check on a string variable for environment (dev or prod).
A sample of what I want is,
variable buckets_list = {type = "list" default = []}
buckets_list = "${var.env == "dev" ? list(var.bld_bucket, var.qa_bucket) : list(var.prd_bucket)}"
I get an error saying the conditionals cannot be applied on lists. Can someone please let me know how to achieve this?
Terraform v0.9.3
aws_iam_policy_document
Conditionals should work on lists too.
Conditionals are not working on lists too. Here is the exact error I am getting,
" conditional operator cannot be used with list values in:"
Please list the steps required to reproduce the issue, for example:
terraform planHi @fernandisvegas! Sorry this didn't work as expected.
Generalizing the behavior here is planned, but requires some changes to the interpolation language evaluator to support, and we decided to ship it with just support for primitive types at first rather than wait until the feature worked for all types. It will work as you expected in a later version.
For now, assuming your variables there contain strings that don't contain any spaces, you can work around this by smuggling the lists through as space-delimited strings and then converting them back again afterwards:
buckets_list = "${split(" ", var.env == "dev" ? "${var.bld_bucket} ${var.qa_bucket}" : var.prd_bucket)}"
That worked @apparentlymart :+1: Thanks :)
Great, @fernandisvegas! I'm glad the workaround worked for you for now.
Since we already have this issue on our radar, I'm going to close this out. That doesn't mean we don't plan to address this by actually supporting lists later, but it will come as part of some more fundamental changes to the configuration language that will be represented by separate issues/PRs later, as things get more concrete.
Was this ever officially fixed? If so, can anyone tell me what version the fix went out with please? I can't seem to find the original ticket tracking this issue.. Thanks
I would be very interested by this feature too.
In fact the workaround doesn't work in my context when I use the "element" function to parse Ids.
I do parse the variable "lb_backend_ids" as it's an output used as implicit dependency.
load_balancer_backend_address_pools_ids = "${split(" ", "${lookup(var.Linux_Vms[count.index], "Id_Lb")}" == "777" ? "" : "${element(var.lb_backend_ids,1)}" )}"
This prompts the following error ==>
Error: module.Create-AzureRmNetworkInterface-Apps.azurerm_network_interface.linux_vms_nics: ip_configuration.0.load_balancer_backend_address_pools_ids: should be a list
Instead of this cmdlt work with no error ==>
load_balancer_backend_address_pools_ids = "${split(" ", "${lookup(var.Linux_Vms[count.index], "Id_Lb")}" == "777" ? "" : "${local.lb_id}" )}"
@apparentlymart Have you got a workaround for this use case ? Would be very appreciated.
For info I am adding below my source code, it work perfectly for string input like "network_security_group_id" but can't find a way to make it work with list input like "load_balancer_backend_address_pools_ids" if using "element".
Code : https://github.com/JamesDLD/terraform/blob/master/modules/Create-AzureRmNetworkInterface/main.tf
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Was this ever officially fixed? If so, can anyone tell me what version the fix went out with please? I can't seem to find the original ticket tracking this issue.. Thanks