Syntax issues while upgrading from 11.14 to version 12

Here is my syntax that works just fine on 11.14:

security_groups = [ “${split(”,", var.webproxy_webpool_enabled ? join(",", local.test_webproxy_pool_sec_groups) : join(",", local.test_webproxy_sec_groups))}"]

After running terraform 0.12upgrade
Line is updated to look like so:
security_groups = split(
var.webproxy_webpool_enabled ? join(",", local.test_webproxy_pool_sec_groups) : join(",", local.test_webproxy_sec_groups),

Here is the error I am getting:
Error: Incorrect condition type

on line 24, in resource “aws_security_group” “test”:
24: var.haproxy_cloudpool_enabled ? join(",", local.test_webproxy_pool_sec_groups) : join(",", local.test_webproxy_sec_groups),
| var.webproxy_webpool_enabled is 1

The condition expression must be of type bool.

Hi @cptcrush,

It sounds like your webproxy_webpool_enabled variable is defined as a number rather than as a boolean. To fix it, you could redefine it as being a boolean value:

variable "webproxy_webpool_enabled" {
  type = bool

Then in module blocks that are calling this module, set the argument to true rather than to 1:

  webproxy_webpool_enabled = true

While you’re looking at this portion of code, it’s worth noting that this workaround of joining to a string and then splitting again in order to conditionally choose a list is no longer necessary in Terraform 0.12, so you could also simplify this expression:

  security_groups = var.webproxy_webpool_enabled ?
    local.test_webproxy_pool_sec_groups :

Hi, Thank you for your help.
I have now run into another problem. While setting my “webproxy_webpool_enabled” variable to boolean solves my issue with condition expression, it creates another. I use “var.webproxy_webpool_enabled” as count as well. Changing var.webproxy_webpool_enabled produces count error:
Error: Incorrect value type

on line 84, in resource “aws_iam_role” “webproxy_webpool”:
84: count = var.webproxy_webpool_enabled

Invalid expression value: number required.

Hi @cptcrush,

Use a conditional expression to select the count based on the variable:

  count = var.webproxy_webpool_enabled ? 1 : 0

This makes it explicit to a future reader that there will be one instance if this variable is true and no instances if it is false.