Skip to content

Terraform 0.14 crashes, Terraform 1.0 reports inconsistent data type only when array is in conditional statement #30866

@AndreiPotemkin

Description

@AndreiPotemkin

I think there might be an issue with the way Terraform handles list elements when in conditional statement compared to unconditional logic.
Actual problem has been encountered with Azure network security rule definitions but simplified code reproduces the problem.

Consider 2 local variables:

  a = {
    val = 1, arr = null
  }
  b = {
    val = null, arr = [1]
  }

if these 2 values are placed in an array unconditionally

c = [local.a, local.b]

it works fine but if same array is built conditionally

c = local.v ? [local.a, local.b] : []

it crashes Terraform 0.14 and in later versions reports error
│ │ local.a is object with 2 attributes
│ │ local.b is object with 2 attributes

To reproduce the issue attempt to execute 'terraform plan' on following:

locals {
  v = true
  a = {
    val = 1, arr = null
  }
  b = {
    val = null, arr = [1]
  }
  c = concat(
    [local.a,local.b],
    local.v ? [local.a,local.b]: []
  )
}

When v = false plan succeeds, when v = true plan fails

Possible solution to change definition of a to

  a = {
    val = 1, arr = []
  }

would pass Terraform check but will fail on apply as Azure network security rule only supports one of the 2 values to be provided, for example source_port_range and source_port_ranges (https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_rule#source_port_range)

Metadata

Metadata

Labels

bugconfigconfirmeda Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions