Open lucymhdavies opened 1 year ago
Would be really nice if the API supported wildcard searching of projects similar to workspaces. Once you have that, then you could create a tfe_project_ids
data source similar to the workspace_ids
data source which can return a map of names to IDs of projects.
Also noticed that the API doesn't support getting a project by it's name (Similar to getting a workspace). I'm thinking we'd want to have that?
Yeah, this could stand to be more ergonomic.
We just added a ticket to prioritize for adding a tfe_project
data source — I've extended that ticket's description to note that we should consider how to make project ID/name conversions more ergonomic at the same time, since it might influence the design.
The tfe_project
data source does now exist, which is great :)
https://registry.terraform.io/providers/hashicorp/tfe/latest/docs/data-sources/project
However, the data source currently requires you to pass in the project name.
For my use-case, where I'm getting workspace details from the tfe_workspace_ids
and tfe_workspace
data sources, I know the ID but I don't yet know the name.
My initial thought was that we could update that so that it takes either a name or an ID.
(although... doing that for just tfe_project
feels unnecessary. If we're gonna do that sort of thing, then it's the sort of thing we'd want to do for all the data sources, not just one or two)
My next thought was similar to my initial thinking, i.e. update tfe_workspace
.
Looks like that would either require an update to the API (which does not currently return project name: https://developer.hashicorp.com/terraform/cloud-docs/api-docs/workspaces#show-workspace), or a second API call (which wouldn't necessarily be needed for everybody)
In my case, the reason why I'm looking to get the project name is so I can setup AWS Dynamic Creds: https://developer.hashicorp.com/terraform/tutorials/cloud/dynamic-credentials
So I do have a workaround in this case (which is to just use *
in place of the project name). But for other use-cases, it may be more important.
My current workaround...
The tfe_workspace
includes project_id
in the attributes.
So a terracurl to https://developer.hashicorp.com/terraform/cloud-docs/api-docs/projects#show-project with the Project ID is good enough for now
data "terracurl_request" "project_name_for_workspace" {
for_each = data.tfe_workspace.tagged
name = "project_name_for_workspace"
url = "https://app.terraform.io/api/v2/projects/${each.value.project_id}"
method = "GET"
headers = {
Authorization = "Bearer ${local.tfe_token}"
Content-Type = "application/vnd.api+json"
}
response_codes = [200]
}
Use-cases
I want to find all workspaces that match a certain tag. That's easily doable already.
however, by doing so, I can only find out the Project ID
That's useful, but... in this case, I actually do want to know the name of the project, not just the ID.
Attempted Solutions
A potential workaround would be to pipe those project IDs into a
for_each
on atfe_project
data source... but we don't have one of those in the provider yet.Proposal
A few things:
tfe_project
data sourceproject_name
with thetfe_workspace
data source, in addition toproject_id
tfe_workspace_ids
data source too