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

[FEAT]: Add owner attribute to github_repository data source and resource #2503

Open
1 task done
gdavison opened this issue Dec 5, 2024 · 2 comments
Open
1 task done
Labels
Status: Triage This is being looked at and prioritized Type: Feature New feature or request

Comments

@gdavison
Copy link

gdavison commented Dec 5, 2024

Describe the need

The github_repository data source works in two "modes": authenticated or anonymous.

When authenticated, the owner can be implied from the current provider instance, so all that is needed to look up the repository is the name. The full_name is populated in the <organization>/<name> format.

When anonymous, the owner cannot be implied, so the full_name must be used. name is returned as the name portion of the full name.

I propose adding an Optional, Computed owner field to the data source. This could be used in the anonymous mode along with name to specify the repository. Otherwise, it would be populated with the owner of the repository.

This would also have the benefit of keeping all information about the repository contained within the data source object so that it could be used in e.g. a module. Currently, either the owner must be passed as a separate variable or the full_name must be split. This would make the owner a "first-class" field of the data source alongside name, rather than needing to derive it.

For parity between the data source and the resource, also add owner as a Computed field to the resource.

For example, a module can take the resource or data source as an object value. The object will have full_name and name as attributes, but if the owner is needed, it must either be passed separately or parsed from full_name.

Currently your module must be like either

variable "repository" {
  type = object({
    name = string
    ...
  })
}

variable "repository_owner" {
  type = string
}

# Do something with separate fields
...
  repo_owner = var.repository_owner
  repo_name  = var.repository.name

or

variable "repository" {
  type = object({
    full_name = string
    name      = string
    ...
  })
}

locals {
  repository_owner = split("/", var.repository.full_name)[0]
}

# Do something with separate fields
...
  repo_owner = local. repository_owner
  repo_name  = var.repository.name

If owner is added as a field, we could do the following:

variable "repository" {
  type = object({
    name  = string
    owner = string
    ...
  })
}

# Do something with separate fields
...
  repo_owner = var.repository.owner
  repo_name  = var.repository.name

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@gdavison gdavison added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Dec 5, 2024
@github-project-automation github-project-automation bot moved this to 🆕 Triage in 🧰 Octokit Active Dec 5, 2024
@stevehipwell
Copy link
Contributor

@gdavison are you just asking for a computed R/O owner attribute on the github_repository resource and data source so you don't have to split the full_name?

@gdavison
Copy link
Author

gdavison commented Dec 7, 2024

Yes, that was essentially it, because name is a field and the only way to get the owner is to split full_name. My use case is using the data source without authentication, since we only need a few fields from the data.github_repository. Adding the field to the resource was for parity with the data source.

Having put some more thought into it, I'm going to rework the proposed feature.

@gdavison gdavison changed the title [FEAT]: Add owner attribute to github_repository resource and data source [FEAT]: Add owner attribute to github_repository data source and resource Dec 7, 2024
@nickfloyd nickfloyd moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Active Dec 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Feature New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants