terraform icon indicating copy to clipboard operation
terraform copied to clipboard

`terraform output` causes `Error: could not read state version outputs` on fresh project

Open dex4er opened this issue 2 years ago • 3 comments

Terraform Version

1.3.2

Terraform Configuration Files

# none

Debug Output

nothing special

Expected Behavior

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

Actual Behavior

│ Error: could not read state version outputs: resource not found
│ 
│ 

Steps to Reproduce

terraform {
  cloud {
    organization = "org"
    workspaces {
      name = "something"
    }
  }
}

then

terraform output

Additional Context

No response

References

No response

dex4er avatar Oct 12 '22 12:10 dex4er

Suggestion:

See https://github.com/hashicorp/terraform/blob/main/internal/cloud/state.go#L412-L422

Instead of throwing an error it should be (nil, nil) returned.

dex4er avatar Oct 12 '22 12:10 dex4er

:wave: Hi Piotr!

Thanks for submitting this issue. Most if not all of TFC's endpoints return 404s if either the user is not authorized or the resource itself was not found, see status code table for Show Current State Version Outputs for a Workspace. Unfortunately the client is unable to make this distinction, so we couldn't necessarily ignore a "not found" error here and return nil, nil.

Hopefully this clears things up for you! :smile:

sebasslash avatar Oct 14 '22 18:10 sebasslash

@sebasslash Ok, but there is still a bug: TFC behaves differently than Terraform without TFC when I run terraform output. It breaks my pipelines when I call terraform output after terraform plan for fresh projects without a stored state.

Is there any possibility to create a state version with Terraform just after a new workspace is created? I don't see anything like that in a documentation for terraform-provider-tfe

dex4er avatar Oct 15 '22 11:10 dex4er