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

Workspaces.Read should return "locked-by" relationship #267

Open
rmadamanchi opened this issue Oct 15, 2021 · 4 comments
Open

Workspaces.Read should return "locked-by" relationship #267

rmadamanchi opened this issue Oct 15, 2021 · 4 comments

Comments

@rmadamanchi
Copy link

The Workspace struct currently does not have a field to capture the "locked-by" relationship

https://www.terraform.io/docs/cloud/api/workspaces.html#locked_by

Happy to do a PR

@uturunku1
Copy link
Collaborator

@rmadamanchi Hi and thank you for bringing this up! If you are interested in working on this change, we definitely welcome your initiative. As you are making your changes and if you need assistance, please feel free to ping me directly on your PR and I'll come to your help! Does that sound good?

@uturunku1
Copy link
Collaborator

I have an update on this issue. The change you suggested will be included as part of this PR: https://github.com/hashicorp/go-tfe/pull/294/files . So no need to open a separate PR. Thank you for offering the help though!

@alex-ikse
Copy link
Contributor

alex-ikse commented Jun 1, 2022

You have added the include field for locked-by, but not changed the jsonapi struct model to read the LockedBy relationship. So this relationship is unusable

@nfagerlund
Copy link
Contributor

Previous commenter is correct — this is still an outstanding omission from the API! In fact, I just ran into a situation in Terraform's cloud integration where I needed it and couldn't have it. 😅 I'm going to re-open this, and make sure it gets a dupe on our jira board.

A notable difficulty with implementing this: locked_by is a polymorphic relationship in the API, and can be one of:

  • Team
  • User
  • Run
  • empty

(I just checked, and yes, org tokens are not allowed to lock a workspace, they get 404 even if they can read the ws.)

So, the actual value of the LockedBy relationship field on the struct will probably have to be a new "faked-up sum type", similar to what I was doing with cloud plan files in Terraform core:

  • Struct with three private fields, one for each concrete type.
  • Three getter methods that return something like (*tfe.User, bool), to push users to check the ok value before trying to interact with the returned value.
  • Workspace LockedBy field has a nil pointer for the whole shebang if it ain't locked.

@nfagerlund nfagerlund reopened this Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants