Getting Started With Basic Terraform Cloud Utility

Figured i might get a quick headstart with some help. I’ve wanted to pick up go for a while, and finally have a great use case for doing this with interacting with the terraform cloud sdk.

Right now I’m just starting simple with a task that focuses on initializing a Terraform Cloud Run without me using the REST api. Instead I’ve grabbed the json payload and converted it to a struct to get me started, and now am trying to break up some simple steps of getting the organization, getting the specific workspace, etc.


  • Learn some Go magic by using terraform cloud (enterprise) sdk instead of using REST based approach so I can use this in some automation tasks.


Is this the proper way to share it, via playground (seems like would be useless to others in the future as temporary?).


main issues

  • As I’m new to this not sure if I should pass around context to each function or create inside each function. I’ve seen examples of using WithContext when calling the function. I decided to ask to avoid overcomplicating it as a beginning.
  • I’m passing in a pointer to an initialized client object or just a as value scoped object? I was assuming I’d need the pointer but my first attempts failed.

Let me know if I should update this with the code too or just keep in playground and will update the thread with progress. Thanks for any help!


I have a few comments to the code:

  • passing the context to functions is OK. It helps with cancelations and timeouts etc.
  • you should create the root context in the main function
  • the context should be passed to GetOrg. Why? Imagine you want to add another function. You’ll create another context and so on and so on.
  • you shouldn’t call ctx.Done() that way. The Done() returns a channel you can listen to for cancelation/timeouts. So, just remove it from there :slight_smile:

The rest looks OK for me. Happy coding!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.