Skip to main content

Posts

Showing posts with the label resource

Create a resource between 0 and N times terraform

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...

Create a resource between 0 and N times terraform

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...