[FEAT]: Add `owner` attribute to `github_repository` data source and resource
Blocked by https://github.com/integrations/terraform-provider-github/issues/2940
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
- [X] I agree to follow this project's Code of Conduct
@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?
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.
👋 Hey Friends, this issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Please add the Status: Pinned label if you feel that this issue needs to remain open/active. Thank you for your contributions and help in keeping things tidy!
Partially related to https://github.com/integrations/terraform-provider-github/pull/2528
@stevehipwell raised a good discussion about the design of using the owner field, so we probably need to discuss there first to be able to review this PR here: https://github.com/integrations/terraform-provider-github/issues/2940