Terraform: conditional statements not working with dynamic lists generated using for loop

Created on 7 Jul 2019  ยท  3Comments  ยท  Source: hashicorp/terraform

Terraform Version

Terraform v0.12.3
+ provider.aws v2.18.0
+ provider.local v1.3.0

Terraform Configuration Files

variable "config" {
  type = object({
    container_secrets = list(string)
    custom_container_secrets = list(object({ # ECS secrets map
      name      = string
      valueFrom = string
    }))
  })
}

variable "environment" {}

locals {
  secrets = [
    # Generate ECS secrets map
    for secret in var.config["container_secrets"] :
    {
      name      = secret
      valueFrom = join("/", ["/services", local.service_name, var.environment, secret])
    }
  ]
  service_name = "xyz"
}

resource "local_file" "foo" {
  content  = jsonencode(var.config["custom_container_secrets"] == null ? local.secrets : concat(local.secrets, var.config["custom_container_secrets"]))
  filename = "${path.module}/foo.bar"
}

Debug Output

Crash Output

Expected Behavior

foo.bar file to be created with content []

Actual Behavior

Empty foo.bar file is created.

Steps to Reproduce

bug config

All 3 comments

Hi @vermdeep,

This looks similar to, and should also be fixed by #21957.
It is turning up in a slightly different place however, so I'll leave this open until we can confirm.

This appears to be working as expected in 0.12.4.

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.

Was this page helpful?
0 / 5 - 0 ratings