Lesson 42. Count output not working

main.tf
resource "local_file" "pet" {
  filename = var.filename[count.index]
  count = length(var.filename)
  content = "file created"
} 

output "pets" {
  value = local_file.pet
  sensitive = true
}

variable "filename" {
  default = [
    "/home/admin/udemy-terraform/dogs.txt",
    "/home/admin/udemy-terraform/cats.txt",
   ]
}

terraform output

│ Warning: No outputs found

│ The state file either has no outputs defined, or all the defined outputs
│ are empty. Please define an output in your configuration with the output
│ keyword and run terraform refresh for it to become available. If you are
│ using interpolation, please verify the interpolated value is not empty.
│ You can use the terraform console command to assist.

Tried terraform refresh…Didn’t work. Tried terraform init again, didn’t work.

Why am I not getting the output values?

Hi @ficestat

There’s no outputs because there is no resource local_file.pet

You used count in the resource, and you have 2 items in the list, therefore the resources that were actually created were local_file.pet[0] and local_file.pet[1]

output "pets" {
  value = local_file.pet[*]   # will get all pet resources as a list
  sensitive = true
}

should make the error go, but you won’t actually see the values because they are sensitive.