Skip to content

Can't count lists in local vars if they contain non-created resources #16712

Closed
@awilkins

Description

@awilkins

This works fine

$ terraform console 
> length(list("", "1", "")
3

But if you do

locals {
  list_of_things = [
    "${a_resource.one.id}",
    "${a_resource.two.id}",
    "${a_resource.three.id}"
  ]
}

Then this will fail as it's unable to compute the count... unless the items in list_of_things already exist, when it works. This means you can extend scripts that plan and run successfully but if you then destroy the resources and start from scratch they don't work.

resource "another_resource" "thing" {
  count = "${length(local.list_of_things)}"
}

Workaround : replace count with a literal count or local or var variable with a literal value.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions