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

Update data sources to get by either ID or Name #1146

Open
daniel-edwards-nz opened this issue Nov 19, 2023 · 0 comments
Open

Update data sources to get by either ID or Name #1146

daniel-edwards-nz opened this issue Nov 19, 2023 · 0 comments

Comments

@daniel-edwards-nz
Copy link

Use-cases

Also relates to #778

The specific problem I'm trying to solve is to automatically set up dynamic credentials between Azure and Terraform Cloud, this requires me to build a subject identifier that contains both the Project and Workspace names. However most of the data sources only support searching by Name. For example when fetching the Workspace you only get the Project ID returned, likewise when getting the Project you only get the Workspace IDs returned. It isn't possible to then use those IDs to find the other related resources.

Attempted Solutions

As mentioned in issue #778 there are a few workarounds via things like terracurl to fetch information from the API directly.

Proposal

While my use case only relates to a couple of data sources, it feels like it would be better for consistency to update others at the same time too. As such I'd like to update all of the relevant data sources to make it so they can be queried by either the ID or the Name. This would involve adding appropriate logic to those data sources so they can determine whether the name or ID has been provided and then call the relevant API to fetch the information. As far as I can tell all of these Types in go-tfe have a Read() function that allows you to get by ID.

Fetching by ID would also have the benefit of being slightly more efficient as many of the existing data sources seem to first fetch a list, then iterate to find the one you want in that list.

The specific data sources I'd like to update are:

  • tfe_agent_pool
  • tfe_policy_set
  • tfe_project
  • tfe_ssh_key
  • tfe_team
  • tfe_variable_set
  • tfe_workspace

(let me know if I've missed any that should be included)

An example of the updated data source would probably look something like this:

data "tfe_workspace" "test" {
  workspace_id = "ws-abc123"
  organization    = "my-org-name"
}

I figured since this would change quite a few data sources I'd better check first. If this is a desirable change I'd be happy to submit a PR for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant