My goal is to get a list of workspaces in my terraform cloud account using the Go API Client. I've written some Go code, and whenever I run "go run main.go" in my terminal, the output shows numbers rather than the workspace names. Here is the go code...
package main
import (
"context"
"fmt"
"log"
tfe "github.com/hashicorp/go-tfe"
)
func main() {
config := &tfe.Config{
Token: "my-token",
}
client, err := tfe.NewClient(config)
if err != nil {
log.Fatal(err)
}
// Create a Context
ctx := context.Background()
orgs, err := client.Organizations.List(ctx, nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(orgs)
space, err := client.Workspaces.List(ctx, "orgname", &tfe.WorkspaceListOptions{})
if err != nil {
log.Fatal(err)
}
fmt.Println(space, "test")
}
The output:
&{0xc0002ae090 \[0xc0002b0000\]}
&{0xc00000baa0 \[0xc000400000 0xc0004001e0 0xc0004003c0 0xc0004005a0 0xc000400780 0xc000400960 0xc000400b40 0xc000400d20 0xc000400f00 0xc0004010e0 0xc0004012c0 0xc0004014a0 0xc000401680 0xc000401860 0xc000401a40 0xc000401c20 0xc000401e00 0xc0004d8000 0xc0004d81e0 0xc0000001e0\]} test
I tried changing the "orgname" to a made up name, the output of the cli is:
&{0xc0000b6ff0 \[0xc0000da580\]}
2022/03/23 18:10:29 resource not found
exit status 1
This tells me that the "orgname" I have works and is actually grabbing workspaces within the organization. Just the output are numbers instead of names.
What I expect:
companyname
[develop__us-east-1__global, develop__us-east-1__compute]
This happens because the object is not a stringer. You have some options:
String() string
and implement your logic