Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource not found error when running Workspaces.Read() #1024

Open
hugodocto opened this issue Jan 3, 2025 · 0 comments
Open

Resource not found error when running Workspaces.Read() #1024

hugodocto opened this issue Jan 3, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@hugodocto
Copy link

hugodocto commented Jan 3, 2025

go-tfe version

1.71.0

Description

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 and r.WorkspaceName as parameter in the client.Workspaces.ReadByID() function
@hugodocto hugodocto added the bug Something isn't working label Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant