I need to raise exception if my dynamically created list is not empty, followed by this https://github.com/hashicorp/terraform/issues/15469 I've created code below, it should fail with error if list is not empty, as you see list constructed from null_resource list, and it always throws assertion:
resource "null_resource" "empty_string" {
count = "10"
triggers = {
value = ""
}
}
locals {
compacted_list_length = "${length(compact(null_resource.empty_string.*.triggers.value))}"
}
resource "null_resource" "is_array_empty" {
count = "${local.compacted_list_length}"
"Lsit is not empty" = true
}
output "compacted_list_length" {
value = "${local.compacted_list_length}"
}
If you'll comment following, output will show 0
resource "null_resource" "is_array_empty" {
count = "${local.compacted_list_length}"
"Lsit is not empty" = true
}
No assertion if we'll set locals to:
locals {
compacted_list_length = 0
}
Even this code will work fine:
locals {
empty_list = ["", "", ""]
compacted_list_length = "${length(compact(local.empty_list))}"
}
resource "null_resource" "is_array_empty" {
count = "${local.compacted_list_length}"
"Lsit is not empty" = true
}
output "compacted_list_length" {
value = "${local.compacted_list_length}"
}
Where is my mistake?
null_resource
fits here. It seems like it should be replaced with something else, but it is unclear what the goal is here.local-exec
provisioner instead, which makes more sense to me also.