Skip to content

[BUG]: Imported repos have drift on template item #2558

Closed as not planned
Closed as not planned

Description

@vlatko-b

Expected Behavior

My code works fine for creating new repos but if I import existing one it shows constant drift

  ~ resource "github_repository" "repo" {
        id                          = "pizza"
        name                        = "pizza"
        # (36 unchanged attributes hidden)

      + template {
          + include_all_branches = false
          + owner                = "XXX"
          + repository           = "github-repo-template"
        }
    }

Plan: 0 to add, 1 to change, 0 to destroy.

They are not created from a template. Is there a way to prevent this without creating a different resource for these that are not based on template?

Actual Behavior

There is no way to set template after repo is created on blank but TF tries to do it

Terraform Version

Terraform v1.4.6
on linux_amd64

  • provider registry.terraform.io/hashicorp/aws v3.76.1
  • provider registry.terraform.io/integrations/github v6.5.0

Affected Resource(s)

github_repository

Terraform Configuration Files

resource "github_repository" "repo" {
  name                        = var.name
   ...
  topics                      = ["managed-by-terraform"]

  template {
    owner                = "XXX"
    repository           = "github-repo-template"
    include_all_branches = false
  }
}

Steps to Reproduce

terraform plan

after a non templated repo is imported

Debug Output

Panic Output

Code of Conduct

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

Activity

  1. added
    Status: Triage
    Type: Bug
    on Feb 7, 2025
  2. vlatko-b commented on Feb 7, 2025

    @vlatko-b
    Author

    In a strange way after 2 TF apply commands the drift goes away

  3. moved this from 🆕 Triage to 🔥 Backlog in 🧰 Octokit Activeon Feb 27, 2025
  4. Blacksmoke16 commented on May 20, 2025

    @Blacksmoke16
    Contributor

    For a while, but always seems to come back eventually :/.

  5. gabrielsoltz commented on May 21, 2025

    @gabrielsoltz

    Also seeing this behaviour

  6. meraj-kashi commented on Aug 26, 2025

    @meraj-kashi

    I’ve experienced the same issue when creating a new repository from a template — the diff always appears.

  7. deiga commented on Jan 6, 2026

    @deiga
    Collaborator

    Let me see if I understand correctly:

    • You have a pre-existing repository in GitHub, which is not created from a template
    • You have a resource definition in Terraform which has the template block configured
    • You are importing the non-template repo into this resource

    @vlatko-b Is this correct?

    And you're expecting the template block to not show in diff, even though you've configured it?

  8. Blacksmoke16 commented on Jan 7, 2026

    @Blacksmoke16
    Contributor

    That would be ideal IMO yes. But FWIW I just handled this via a dynamic block where repos get opted-in by default, but can opt-out the older existing repos.

  9. deiga commented on Mar 22, 2026

    @deiga
    Collaborator

    Well, it's not really possible for the provider to support a case of mismatched config and upstream state. It might be possible that in the future we make it error instead of drift, since the provider can't know when a user intended to do something unsupported or when there is an actual problem.

    Using a dynamic block in lieu of a separate resource seems like the most reasonable solution

  10. moved this from 🔥 Backlog to ✅ Done in 🧰 Octokit Activeon Mar 22, 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: TriageType: Bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions