Skip to content

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

@rodwill

Description

@rodwill

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

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

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

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

Panic Output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions