Skip to content

Failed setting visibility=internal on a newly created repo from template #925

Closed

Description

@damir-dezeljin

Hi there,

Terraform Version

1.0.5

Affected Resource(s)

  • github_repository

Terraform Configuration Files

# create github repository for the domain under domain team
resource "github_repository" "domain" {
  name = lower("${var.domain}-domain")

  visibility = "internal"

  template {
    owner      = "our-enterprise-org-id"
    repository = "tf-domain-template"
  }
}

Debug Output

Gist: https://gist.github.com/damir-dezeljin/e9de28e11aa7de8d7a60fc2e123794f6

NOTE: I removed the sensible parts from the logs. Still, I think the logs shows what's the actual issue. Let me recap it here:

  • We're using TF to create a GitHub repo out of a template.
  • The template repo visibility is set to Internal.
  • The newly created repo visibility should be Internal as well.
  • The repo gets created, but it remains Private and the visibility setup phase fails with error 422.

Panic Output

n/a

Expected Behavior

I'd expect a new repo with visibility Internal being created.

Actual Behavior

The terraform apply fails with error code 422 on visibility change step.

Steps to Reproduce

Please list the steps required to reproduce the issue, for example:

  1. Set org policy to prevent users from changing repos visibility.
  2. Create a template repo with visibility Internal
  3. Use the provided TF code for creating a new repo with visibility Internal out of the template one.
  4. Use a GitHub App identity with scopes listed below.
  5. Run terraform apply.

Important Factoids

  • We're running TF with GitHub Apps credentials with following scopes:
    • Repository access: All repositories
    • Repository permissions:
      • Administration: r/w
      • Contents: r/w
      • Metadata: ro
      • Secrets: r/w
    • Organization permissions:
      • Members: r/w
      • Administration: r/w
  • Our Enterprise has an Org.Policy set that prevents users from creating Public repos, as well only Org.Owners are allowed to change repos visibility.

References

n/a

Activity

  1. erzz commented on Oct 13, 2021

    @erzz

    Basically a me too post - but just to add that I get the same result from the same TF config using 1.0.7 too

  2. parviste-fortum commented on Feb 10, 2022

    @parviste-fortum

    The issue seems to be due to a limitation in the Github API which only supports public and private creation from a template: https://docs.github.com/en/rest/reference/repos#create-a-repository-using-a-template

    Of course, it might be nice if terraform would give and error or at least warning when trying to set visibility to internal, instead of sillently ignoring it:

    if visibility == "private" || visibility == "internal" {
    isPrivate = true

  3. parviste-fortum commented on Feb 11, 2022

    @parviste-fortum
  4. JafoFett commented on May 27, 2022

    @JafoFett

    Hoping there is a way to create 'internal' repo's from template repo using Terraform...is there a workaround for the API limitation? Or a flat out no go?

  5. github-actions commented on Feb 22, 2023

    @github-actions

    👋 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!

  6. added
    Status: Stale
    on Feb 22, 2023
  7. damir-dezeljin commented on Feb 22, 2023

    @damir-dezeljin
    Author

    How can I set the Status: Pinned label? I think this is quite a serious flow for Enterprise Cloud customers requiring no repository is set to Public and therefore setting an Org policy for that, but on the other hand wanting all terraformed repositories being accessible to all employees.

    I'd appreciate a feedback from GitHub on the matter.

  8. removed
    Status: Stale
    on Feb 23, 2023
  9. added
    Type: Bug
    Status: Up for grabs
    Status: Pinned
    on Feb 28, 2023
  10. kfcampbell commented on Feb 28, 2023

    @kfcampbell
    Contributor

    @damir-dezeljin apologies, the SDK team is spread pretty thin at the moment. We've got a little bit of content here about our prioritization process, but realistically, the best way to address this problem is to submit a PR following our contributing guidelines to this project. We appreciate all contributions!

  11. ZarakiKenpachi7 commented on Aug 1, 2025

    @ZarakiKenpachi7

    Hi - ANy updates here? It has been more than 2 years.

  12. deiga commented on Jan 18, 2026

    @deiga
    Collaborator

    @ZarakiKenpachi7 I just tried creating an internal repo from template and had no issues. Could you provide a config example of what is failing for you and some debug output?

  13. mungojam commented on Jan 18, 2026

    @mungojam

    @deiga did you do this step in the repro?

    Set org policy to prevent users from changing repos visibility.

  14. FlaviusRaducu commented on Jan 26, 2026

    @FlaviusRaducu

    Same problem here, visibility defaults to public; it looks like the bug was fixed in v4.9.4 with this PR but reintroduced in v6.10.0 with this PR.

    v6.9.1

    Image

    >= v6.10.0

    Image
  15. added this to the v6.11.0 Release milestone on Jan 27, 2026
  16. moved this from Backlog to In Progress in Terraform Provideron Jan 27, 2026
  17. moved this from In Progress to Done in Terraform Provideron Jan 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: PinnedStatus: Up for grabsType: BugVisibility

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions