The common way this seems to get done, is via something like
count = "${length(split(",", var.private_subnets))}" However, this results in either needing trailing commas, or being unable to handle the 0 case:
Eg:
${length(split(",", ""))}is 1${length(split(",", "foo"))}is 1${length(split(",", "foo,bar"))}is 2${length(split(",", "")) -1 }is 0${length(split(",", "foo")) - 1}is 0${length(split(",", "foo,")) - 1}is 1${length(split(",", "foo,bar")) - 1}is 1
neither of those is very satisfying
the
compact function was somewhat recently added to deal with empty strings when splitting so, for example:${length(compact(split(",", "")))}should be 0${length(compact(split(",", "foo")))}should be 1${length(compact(split(",", "foo,bar")))}should be 2
Comments
Post a Comment