integrations / integrations/terraform-provider-github

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

Open
#2,503 5 comments 0 reactions 0 assignees View on GitHub
Status: Triage Type: Feature
Dominant language
Go
Stars
1.2k
Forks
1k
Avg merge
1d 14h
Merged PRs (30d)
8

Description

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 `/` 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

```terraform
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

```terraform
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:

```terraform
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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.