Skip to content

'resource not found' with SDK but not cURL #1079

@christianTragesser

Description

@christianTragesser

go-tfe version

v1.76.0

Description

I'm attempting to use this module to automate Workspaces configurations. I've configured a client according to the workspaces example however my client appears to only be able to interact with Organizations. In my initial trials with this sdk I'm merely attempting to list Organizations, Projects, and Workspaces. Listing Organizations works without issue however, when I attempt to list Projects or Workspaces I'm receiving an error stating, "resource not found". When researching this issue I've seen suggestions the TFC token being used probably does not have the required access to perform actions which result in the "resource not found" error. However, when using curl to perform the same query (using the same token) the request is successful. I hesitate to say there is such a drastic bug in the sdk, probably more on the side of ignorance from my perspective. I could use some assistance to learn where I'm going wrong.

Testing plan

My code so far. This fails with the message "failed to list projects":

package main

import (
	"context"
	"fmt"
	"os"

	tfe "github.com/hashicorp/go-tfe"
)

func main() {
	var orgID string
	var projID string
	ctx := context.Background()

	config := &tfe.Config{
		Token:             "my-tfc-token",
		RetryServerErrors: true,
	}
	client, err := tfe.NewClient(config)
	if err != nil {
		fmt.Println(err)
		fmt.Println("failed to create client")
		os.Exit(1)
	}

	orgs, err := client.Organizations.List(ctx, &tfe.OrganizationListOptions{})
	if err != nil {
		fmt.Println(err)
		fmt.Println("failed to list orgs")
		os.Exit(1)
	}
	for _, org := range orgs.Items {
		if org.Name == "my-org-name" {
			orgID = org.ExternalID
		}
	}

	projects, err := client.Projects.List(ctx, orgID, &tfe.ProjectListOptions{})
	if err != nil {
		fmt.Println(err)
		fmt.Println("failed to list projects")
		os.Exit(1)
	}
	for _, proj := range projects.Items {
		if proj.Name == "my-proj-name" {
			projID = proj.ID
		}
	}

	_, err = client.Workspaces.List(ctx, orgID, &tfe.WorkspaceListOptions{
		ProjectID: projID,
	})
	if err != nil {
		fmt.Println(err)
		fmt.Println("failed to list workspaces")
		os.Exit(1)
	}
}

Expected Behavior

Projects and Workspaces lists should be return. This is not an issue when using cURL with the same token.

Actual Behavior

I receive an error, "resource not found"

Additional Context

none

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions