Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conditional statements not working with dynamic lists generated using for loop #21996

Closed
vermdeep opened this issue Jul 7, 2019 · 3 comments
Closed

Comments

@vermdeep
Copy link

vermdeep commented Jul 7, 2019

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

Additional Context

On moving the conditional statement to a local variable and then concat two list works.
Following is working:

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])
    }
  ]
  custom_secrets = var.config["custom_container_secrets"] == null ? [] : var.config["custom_container_secrets"]
  service_name   = "xyz"
}

resource "local_file" "foo" {
  content  = jsonencode(concat(local.secrets, local.custom_secrets))
  filename = "${path.module}/foo.bar"
}

Also, the issue is happening in this case only. If custom_container_secrets is not null then both the code are working. Also, both the codes are working when custom_container_secrets is declared as a variable (not as a key of an object).

References

@vermdeep vermdeep changed the title for loop not working with conditional statements conditional statements not working with dynamic lists Jul 7, 2019
@vermdeep vermdeep changed the title conditional statements not working with dynamic lists conditional statements not working with dynamic lists generated using for loop Jul 7, 2019
@jbardin
Copy link
Member

jbardin commented Jul 8, 2019

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.

@jbardin
Copy link
Member

jbardin commented Jul 12, 2019

This appears to be working as expected in 0.12.4.

@jbardin jbardin closed this as completed Jul 12, 2019
@ghost
Copy link

ghost commented Aug 13, 2019

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.

@ghost ghost locked and limited conversation to collaborators Aug 13, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants