How to get remote state file for my latest terraform(Enterprise) run?

Hi,

I want to get the latest run for my workspace and grab its terraform state file. We are using terraform enterprise.

I did the below and I got get the payload:

https://ptfe-dev.company.com.au/api/v2/organizations/organization-name/workspaces/workspace1

I get output but information of the workspace id etc, but that is what not what I want.

With the above output, I get workspace id and I ran the query below:

https://ptfe-dev.companyname.com.au/api/v2/organizations/organization-name/workspaces/workspace1/current-state-version

However, the above query returns
orry, the page /api/v2/organizations/rganization-name/workspaces/workspace1/states/sv-DKBZ2AFoV5mwY4kP could not be found.

This error could mean one of two things:

  • The resource doesn’t exist
  • The resource exists, but you do not have permission to access it

If someone has linked you to this resource, ensure that they have given you proper permissions to access it.

I can, however, access the same resource (workspace1) state file via TFE UI.

Can anyone please advise me what I am doing wrong here?

Hello, and welcome!

The current-state-version URL you posted above appears to use the workspace name, but fetching the current state version for a workspace in the State Versions API requires the ID of the workspace; did you use the workspace name or the ID?