Terraform output not working on

Hello folks,

I’m trying to output the content of a local.files_map to better understand for/for_each loops by running terraform output. I’m getting the following error:

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.

Here is the code (Using Terraform v0.12.7):

variable "local_files" {
  type = list(object({
    content  = string
    filename = string
  default =[
      content  = "a",
      filename = "a-name"
      content  = "b",
      filename = "b-name"
      content  = "c",
      filename = "c-name"

locals {
  files_map = {
    for f in var.local_files:
      f.filename => f

resource "local_file" "foo" {
  for_each  = local.files_map
  content   = each.value.content
  filename  = each.value.content

The code runs fine but I’m not getting any output. Ideas?

Thanks in advance,

Hi @acambera-nearsoft,

You don’t seem to have any output values declared in this configuration.

To see the files_map value in terraform output, declare an output value for it like this:

output "files_map" {
  value = local.files_map

Hello Martin,

I forgot to add that part to my question, my bad. I found out the issue, it was that I was trying to send output from a module not from root. Updated the code to output from root and it worked.

Thanks a lot,