integrations / integrations/terraform-provider-github

[BUG]: github_repository creation fails when organization enforces required custom properties (no way to set them at create time)

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

Description

### Expected Behavior

When an organization has custom properties marked as `required = true` (via `github_organization_custom_properties`), it should be possible to create a repository with `github_repository` and provide the required property values during the same `terraform apply`. This aligns with GitHub's documented organization setting **"Require this property for all repositories"**: https://docs.github.com/en/organizations/managing-organization-settings/managing-custom-properties-for-repositories-in-your-organization#setting-values-for-repositories-in-your-organization.

### Actual Behavior

Repository creation fails because required custom properties cannot be provided in the `github_repository` resource at create time.

Current flow creates a chicken-and-egg problem:

1. `github_repository` does not expose an argument/block to set custom property values during create.
2. `github_repository_custom_property` requires an existing repository (`repository` argument).
3. If org policy enforces required properties on creation, GitHub API rejects repository creation before `github_repository_custom_property` can run.

As a result, there is no valid Terraform path to create a new repository under that policy.

### Terraform Version

```text
Terraform v1.11.x
provider registry.terraform.io/integrations/github v6.6.0+
```

### Affected Resource(s)

- `github_repository`
- `github_repository_custom_property`

### Terraform Configuration Files

```hcl
resource "github_organization_custom_properties" "environment" {
property_name = "environment"
value_type = "single_select"
required = true
allowed_values = ["development", "staging", "production"]
}

resource "github_repository" "my_repo" {
name = "my-new-repo"
description = "A new repository"
visibility = "private"
auto_init = true

# No field currently exists to set required custom property values here
}

resource "github_repository_custom_property" "my_repo_env" {
repository = github_repository.my_repo.name
property_name = "environment"
property_type = "single_select"
property_value = ["production"]
}
```

### Steps to Reproduce

1. Define an organization custom property with `required = true`.
2. Attempt to create a new repository using `github_repository`.
3. Run `terraform apply`.
4. Observe repository create failing because required custom property value is missing.

### Debug Output

```shell
Error: POST https://api.github.com/orgs/{org}/repos: 422 Validation Failed
Required custom property 'environment' is missing.
```

### Panic Output

```shell
N/A

```

### 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.