I’m developing a runtask that have to read the Terraform version in use in the workspace that triggered it.
I’ve written the following Go code snippet to achieve this (slightly modified for this post, we do not panic()
in prod :)):
r := request.RunTaskRequest{}
err := json.Unmarshal([]byte(event.Body), &r)
if err != nil {
panic(err)
}
// ...
c := &tfe.Config{
Address: "https://" + tfeDomain,
Token: r.AccessToken,
RetryServerErrors: true,
}
client, err := tfe.NewClient(c)
if err != nil {
fmt.Printf("cannot create new tfe client: %w\n", err)
}
w, err := client.Workspaces.Read(context.Background(), r.OrganizationName, r.WorkspaceName)
if err != nil {
fmt.Printf("cannot read workspace: %w\n", err)
}
However, I’m encountering the error message:
cannot read workspace: resource not found
This indicates that client.Workspaces.Read()
is failing, yet I’m certain the workspace exists. I’ve also tried client.Workspaces.ReadByID
using r.WorkspaceID
, but the issue persists. The error message “resource not found” is quite vague. Does anyone have suggestions on what might be causing this, or how to resolve it?
Expected Behavior
I expect it to work because both the organization and the workspace exist; but at least a better error message indicating what has not been found.
Actual Behavior
Resource not found error message.
Additional Context
I tried a few things:
- replaced the
r.AccessToken
value by a random string, and got a new error (‘unauthorized’), so I think this isn’t a token-related issue; - tried both
r.WorkspaceID
andr.WorkspaceName
as parameter in theclient.Workspaces.ReadByID()
function;