Skip to content

[BUG]: Github Repository Template is also "applied" to existing repositories #2090

Closed as not planned

Description

Expected Behavior

Template is only used for creation of new repositories. Applying a template to an existing repository does nothing.

Actual Behavior

template is also applied to existing repositories
this seems to also stick for some time

but then after a few hours, terraform will see this as a difference and apply the template to existing repositories again

Terraform Version

v5.44.0

Affected Resource(s)

github_repository

Terraform Configuration Files

variable "repos" {
  type = list(object({
    name                = string
    owners              = optional(set(string), [])
    admins              = optional(set(string), [])
    enable_environments = optional(bool, true)
    enable_actions      = optional(bool, true)
    checks              = optional(set(string), [])
    type                = optional(string, "default")
    is_template         = optional(bool, false)
  }))
}

repos = [
  { name = "objego-client" }
]

locals {
  repos_by_name = {
    for r in var.repos : r.name => r
  }
}

resource "github_repository" "repository" {
  for_each = local.repos_by_name

  name       = each.key

  # this was added later, so new repos are set up with a template
  template {
    owner      = "objego"
    repository = "repository-template"
  }

}

Steps to Reproduce

Create a repository using terraform without a template
Change the repository configuration in terraform to include a template

Debug Output

# github_repository.repository["objego-client"] will be updated in-place
  ~ resource "github_repository" "repository" {
        id                          = "objego-client"
        name                        = "objego-client"
        # (34 unchanged attributes hidden)

      + template {
          + include_all_branches = false
          + owner                = "objego"
          + repository           = "repository-template"
        }
    }

Panic Output

No response

Code of Conduct

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

Activity

  1. added
    Status: Triage
    Type: Bug
    on Jan 10, 2024
  2. moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Activeon Jan 18, 2024
  3. added
    Status: Up for grabs
    and removed
    Status: Triage
    on Jan 18, 2024
  4. arunsathiya commented on Jan 23, 2024

    @arunsathiya
    Contributor

    Am I understanding correctly that with the template configuration, if the repository already exists, the request should fail and show an appropriate error?

  5. StefanLobbenmeierObjego commented on Jan 23, 2024

    @StefanLobbenmeierObjego
    Author

    Actually I would prefer it to be ignored for repository, since it makes it easier to manage new and existing repositories like this. It should just be considered for repository creation.

    As a workaround for now, I could add an extra parameter to my repository configuration whether this is a new repository and only apply the template in that case, but that is a really odd thing to store in configuration.

  6. nuclearsandwich commented on Apr 20, 2024

    @nuclearsandwich
    Contributor

    I was perusing the GitHub documentation to see whether the template repository used to create a repository is persisted after creation and the answer is, perhaps regrettably, yes but it's only visible in the GraphQL v4 API. (Edit: Nope, it's there in the REST API as well, I just didn't have a template repository to check against)

    I think this means that the behavior that @StefanLobbenmeierObjego prefers: template blocks are used to initialize a non-existent repository and ignored afterwards is preferred and probably the most straightforward thing to implement.

    If this provider were ever to switch to using the GraphQL API, the template repository provenance of a repository would be visible and we'd have to then decide how much to care about it.

    I can imagine a use-case where different behavior is configured if a repository was created from a specific template or not but I have no such use case as I want to treat all of mine the same whether they're generated from a template or from scratch.

    In my case, I'm managing an organization of 615 repositories (and growing) that are all managed in a massive for_each as they are all meant to be governed the same way. I've only just introduced the template repository so these 615 are all without a template and there will still be non-template repositories imported into this process on occasion as well. So having some way to handle this cleanly would cut down on plan churn in a big way.

  7. github-actions commented on Jan 16, 2025

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

  8. added
    Status: Stale
    on Jan 16, 2025
  9. brmb commented on Jan 16, 2025

    @brmb

    This bug makes a really bothersome Terraform plan.
    Is there any news on this guys?

  10. removed
    Status: Stale
    on Jan 17, 2025
  11. rejithwg commented on Jan 22, 2025

    @rejithwg

    Please let me know if you have any updates on the above scenario.

  12. gabrielsoltz commented on May 21, 2025

    @gabrielsoltz

    Any update on this one? I think it also relates to #2558

  13. stevehipwell commented on Jan 6, 2026

    @stevehipwell
    Collaborator

    I would expect that changing the template config for an existing repository would cause it to be recreated. It should be possible to only make this the case when the template is defined which would allow it to be cleared.

  14. removed
    Type: Bug
    on Feb 11, 2026
  15. deiga commented on Jul 3, 2026

    @deiga
    Collaborator

    As established by #2090 (comment)

    This is not a bug and in a future version we will make template stricter so that it will enforce each repo to be created from the configured template.
    It should not be possible to import a repo with a template config and not have it be created by that template

  16. moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Activeon Jul 3, 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: Up for grabs

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions