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

dbtcloud_project data-source fetch by project name enhancement #189

Closed
justbldwn opened this issue Sep 8, 2023 · 3 comments
Closed

dbtcloud_project data-source fetch by project name enhancement #189

justbldwn opened this issue Sep 8, 2023 · 3 comments

Comments

@justbldwn
Copy link

we have a use-case where we are looking to use the dbtcloud_project data-source, but ideally are looking to pass in a project name to get back the project id. for example, for maintenance tasks like creating/updating dbtcloud_groups, we have the project name easily available to us, and would make it cleaner to understand which projects tie to which groups (instead of only having an id reference).

is there anyway this data-source could be updated to optionally allow for a project name to be passed in? or potentially a separate datasource to get project details based on name?

https://registry.terraform.io/providers/dbt-labs/dbtcloud/latest/docs/data-sources/project

thanks!

@b-per
Copy link
Collaborator

b-per commented Sep 10, 2023

Hi @justbldwn !

This is not the first time that I get this request but until now I was a bit reluctant to add the feature, just because dbt Cloud doesn't enforce uniqueness of project names, so it would be possible to get multiple projects (and project IDs) matching a given name.

I will think again about it and see if I add the feature and raise some errors if there is more than 1 project with the given name.

In the meantime, as a workaround, you can also use the http provider with the following logic:

data "http" "example" {
  url = "https://cloud.getdbt.com/api/v2/accounts/${var.dbt_account_id}/projects/"
  request_headers = {
    Authorization = "Token ${var.dbt_token}"
  }
}

locals {
	project_name = "Analytics"
	projects = jsondecode(data.http.example.response_body)
	project_id = [for project in local.projects.data: project.id if project.name == local.project_name][0]
}

data "dbt_cloud_project" "test_project" {
  project_id = local.project_id
}

output "name" {
	# getting back the same name as local.project_name
  	value = data.dbt_cloud_project.test_project.name
}

@b-per
Copy link
Collaborator

b-per commented Sep 21, 2023

Available in 0.2.10 that should be available in a few minutes on the TF registry

@b-per b-per closed this as completed Sep 21, 2023
@justbldwn
Copy link
Author

thanks so much!

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

2 participants