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

Adds polymorphic relationships for Workspaces, Tokens, and RunTriggers #816

Merged
merged 1 commit into from
Dec 18, 2023

Conversation

brandonc
Copy link
Collaborator

@brandonc brandonc commented Nov 13, 2023

This PR adds support for polymorphic fields that already exist in the API to Workspaces (locked-by), AuthenticationTokens (created-by), and RunTriggers (sourceable)

The purpose is to illustrate how the underlying jsonapi feature is used in go-tfe and also to run the upstream PR against a more elaborate test suite.

It uses this dependency PR so that should be merged and released before this PR is merged.

@brandonc brandonc requested a review from a team as a code owner November 13, 2023 18:12
nfagerlund
nfagerlund previously approved these changes Nov 14, 2023
Copy link
Member

@nfagerlund nfagerlund left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems great. I know it's "do not merge," but I'll register my approval for future reference.

If you're really feeling fired up, the one polymorphic relation that I REALLY got bit by lacking in the past was Workspace.LockedBy. I wanted to use it to give a more reliable error description when building out the saved cloud plans apply action in terraform core, but had to give up and give a "usually probably right" error instead.

I think the options for locked-by are user/team/run -- org token can't lock a workspace.

@brandonc
Copy link
Collaborator Author

brandonc commented Nov 15, 2023

@nfagerlund What a stroke of luck! Adding LockedBy revealed a bug in the jsonapi decoder when the field was omitted from the payload, which is the case when the workspace is not locked. I also added CHANGELOG entries and will merge this once we have a jsonapi release. Thanks for the suggestion!

@brandonc brandonc changed the title RFC: Adds polymorphic relationships for Tokens and RunTriggers RFC: Adds polymorphic relationships for Workspaces, Tokens, and RunTriggers Nov 15, 2023
@nfagerlund
Copy link
Member

🙌🏼!! (I had a hunch aiming it at something I tried to use in anger would turn up something interesting 😅)

@brandonc brandonc changed the title RFC: Adds polymorphic relationships for Workspaces, Tokens, and RunTriggers Adds polymorphic relationships for Workspaces, Tokens, and RunTriggers Nov 15, 2023
`LockedBy` and `CreatedBy` are new fields, but deprecates `Sourceable` on
the `RunTrigger` model
Copy link
Contributor

@sebasslash sebasslash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 -- Awesome work!

@brandonc brandonc merged commit a0264fe into main Dec 18, 2023
10 checks passed
@brandonc brandonc deleted the brandonc/poly-poc branch December 18, 2023 18:19
Copy link

Reminder to the contributor that merged this PR: if your changes have added important functionality or fixed a relevant bug, open a follow-up PR to update CHANGELOG.md with a note on your changes.

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

Successfully merging this pull request may close these issues.

3 participants