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

[FEATURE REQUEST] Data resource for query all repositories in a Github ORG #61

Closed
mechastorm opened this issue Nov 10, 2017 · 1 comment

Comments

@mechastorm
Copy link

mechastorm commented Nov 10, 2017

It would be useful if there was a terraform data resource to query the github org - specifically get a list of all repositories from the Github Org (or maybe even a user).

example

# Get all repositories that are part of example org 
data "github_repos" "example" {
  slug = "example-org"
}

# Get all repositories that are part of example user 
data "github_repos" "example" {
  slug = "example-user"
}

Using the output from that data resource, we can then iterate over them for actions like

  • attaching teams to a repository
  • setting a standardized github_branch_protection setting on all repositories.
@radeksimko
Copy link
Contributor

Hi @mechastorm
thanks for opening this issue.

I'm thinking we could implement this on top of the Search API which would give users the flexibility to query any repositories, whether scoped by an org, name, or anything else using the search syntax.

e.g.

data "github_repositories" "example" {
  search_query = "user:terraform-providers language:Go"
}

output "full_names" {
  value = "${data.github_repositories.example.full_names}"
}
full_names = [
  "terraform-providers/terraform-provider-aws",
  "terraform-providers/terraform-provider-azurerm",
  "terraform-providers/terraform-provider-google",
...
]

then if users need they can leverage the other data source (to get more data about each repository) which was merged recently:

data "github_repositories" "example" {
  search_query = "user:terraform-providers language:Go"
}

data "github_repository" "provider" {
  count     = "${length(data.github_repositories.providers.full_names)}"
  full_name = "${data.github_repositories.providers.full_names[count.index]}"
}

output "clone_urls" {
  value = "${data.github_repository.provider.*.ssh_clone_url}"
}
clone_urls = [
    [email protected]:terraform-providers/terraform-provider-vault.git,
    [email protected]:terraform-providers/terraform-provider-github.git,
    [email protected]:terraform-providers/terraform-provider-cloudflare.git,
...
]

or manage team permissions:

data "github_repositories" "example" {
  search_query = "user:terraform-providers language:Go"
}

resource "github_team_repository" "some_team_repo" {
  count     = "${length(data.github_repositories.providers.names)}"

  team_id    = "${github_team.example.id}"
  repository = "${data.github_repositories.providers.names[count.index]}"
  permission = "pull"
}

What do you think? Would that satisfy your use cases?

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