Skip to content

[BUG]: Pre-existing fork repositories are recreated when fork set to true #2954

@julianr-am

Description

@julianr-am

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_repository in 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_owner and source_repo parameters accordingly, then run terraform 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               = "git@github.com: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

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions