Repository navigation
Closed
Description
Expected Behavior
The fork parameter can be set to true to track the forked status of pre-existing github_repository resources that manage fork repositories, or left blank to prevent terraform from recreating the repository.
Actual Behavior
Terraform tries to recreate pre-existing github_repository resources that manage fork repositories on newer versions of the provider when the fork parameter is set to true.
Terraform Version
Terraform v1.5.7
on linux_amd64
- provider registry.terraform.io/integrations/github v6.8.3
Affected Resource(s)
github_repository
Terraform Configuration Files
terraform {
required_version = ">= 1.5.7"
required_providers {
github = {
source = "integrations/github"
version = "6.8.3"
}
}
}
provider "github" {
owner = "owner-here"
}
resource "github_repository" "repository" {
name = "fork-bug-terraform-provider-github"
allow_update_branch = false
auto_init = false
description = "Repository forked to troubleshoot provider issue when reading repository properties"
has_discussions = false
has_downloads = true
has_issues = false
has_projects = true
has_wiki = false
homepage_url = "https://www.terraform.io/docs/providers/github/"
# Added after upgrading to v6.8.3 from 6.7.5
fork = true
source_repo = "terraform-provider-github"
source_owner = "integrations"
}Steps to Reproduce
- Manually fork a repository using the Github Web UI
- Import the repository to a
github_repositoryin a terraform-provider-github version previous to feat(core): add fork functionality #2678 (6.7.5 was used in this case) - Run a successful apply that imports the resource, then upgrade to terraform-provider-github version 6.8.3
- Set the resource
fork,source_ownerandsource_repoparameters accordingly, then runterraform plan
Debug Output
Terraform will perform the following actions:
# github_repository.repository must be replaced
-/+ resource "github_repository" "repository" {
~ default_branch = "main" -> (known after apply)
~ etag = "W/\"...\"" -> (known after apply)
+ fork = true # forces replacement
~ full_name = "owner-here/fork-bug-terraform-provider-github" -> (known after apply)
~ git_clone_url = "git://github.com/owner-here/fork-bug-terraform-provider-github.git" -> (known after apply)
~ html_url = "https://github.com/owner-here/fork-bug-terraform-provider-github" -> (known after apply)
~ http_clone_url = "https://github.com/owner-here/fork-bug-terraform-provider-github.git" -> (known after apply)
~ id = "fork-bug-terraform-provider-github" -> (known after apply)
- is_template = false -> null
name = "fork-bug-terraform-provider-github"
~ node_id = "..." -> (known after apply)
~ primary_language = "Go" -> (known after apply)
~ private = false -> (known after apply)
~ repo_id = ... -> (known after apply)
+ source_owner = "integrations" # forces replacement
+ source_repo = "terraform-provider-github" # forces replacement
~ ssh_clone_url = "[email protected]:owner-here/fork-bug-terraform-provider-github.git" -> (known after apply)
~ svn_url = "https://github.com/owner-here/fork-bug-terraform-provider-github" -> (known after apply)
~ topics = [] -> (known after apply)
~ visibility = "public" -> (known after apply)
~ vulnerability_alerts = false -> (known after apply)
# (20 unchanged attributes hidden)
- security_and_analysis {
- secret_scanning {
- status = "enabled" -> null
}
- secret_scanning_push_protection {
- status = "enabled" -> null
}
}
}
Plan: 1 to add, 0 to change, 1 to destroy.Panic Output
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
Type: BugSomething isn't working as documented
Type
Projects
- StatusShow more project fieldsDone
Activity
deiga commentedon Nov 30, 2025
Hey @julianr-am 👋
Thanks for raising this.
Based on the PR description I understand that using the
forkattribute is only for creating a new fork. Existing forks should be recognised without doing anything.Are you able to confirm how this acts following the same steps without adding the
forkattributes after upgrade?brianmichel commentedon Dec 2, 2025
Yesterday we had updated to the 6.8.x provider version and had a forked repo get destroyed and recreated for some reason. In the workflow run that produced this diff, there was no terraform changes, and this repo has been in terraform state for years at this point so I found this extremely surprising (this caused an internal incident obviously).
Interestingly, we had never been setting the
forkparameter at all (our provider was older then 6.8.0 which introduced the fork concept).Terraform Version: v1.10.2
Provider Version: v6.8.3
For repos that we have under terraform management, the resource definition looks like this, and has for a long time:
Terraform Output:
Is it possible there is still some issue with the forking logic?
julianr-am commentedon Dec 2, 2025
Hi @deiga ! Not adding the fork parameter results in a plan with no changes when using the example I listed to reproduce the issue.
However we came across this issue because of a situation exactly like the one stated by the persone above. Some of our repositories reported that they would be recreated after we upgraded the provider due to this parameter not being set (I haven't been able to reproduce this yet). We tried setting it but it resulted in the issue I reported, where other repositories were planned to be recreated even though they were indeed a fork.
deiga commentedon Dec 2, 2025
Thank you for providing these details! That definitely looks like a nasty bug and shouldn't be happening.
nickfloyd commentedon Dec 2, 2025
This is no good. So sorry for the trouble here @julianr-am . I think I found the issue.
ForceNew: truewas added tofork,source_owner, andsource_repo.If, like in your case, terraform detects a state change then it will force new the fields above. ForceNew should only apply when creating a fork and no other time.
We need to remove
ForceNewfrom these fields and probably add aCustomizeDiffto compare the schema resource diff.@deiga & @diofeher can y'all check me on this line of thinking?
mhegazy commentedon Dec 3, 2025
@nickfloyd - related to the comment above (#2954 (comment)). We are seeing another repo now considered by the provider to be deleted, same symptoms as the OP.
The question is why the provider updates these at seemingly random times? I would assume that in one plan all repos that are marked as forks would be destroyed. but we are seeing it happen one repo every other day. any idea what is going on?
here is the plan from today:
diofeher commentedon Dec 3, 2025
@mhegazy That's strange, but your issue is the same as this one. We have an open PR at #2959 to fix this.
diofeher commentedon Dec 3, 2025
@mhegazy @julianr-am Can you upgrade your
terraform-provider-githubversion and see if this issue persists?julianr-am commentedon Dec 5, 2025
@diofeher After using a locally built version of the provider (from the master branch) that includes this fix I can confirm that Terraform is no longer trying to re-create the resource.