Skip to content

[BUG]: github_repository.name change should always be applied last to prevent errors #2451

@garysassano

Description

@garysassano

Expected Behavior

I had a Terraform plan with the following two resources:

  • github_repository
  • github_repository_collaborators

I modified both github_repository.name and github_repository_collaborators.team

The plan showed the following:

! github_repository.this["my-repo"] will be updated in-place
! github_repository_collaborators.repository_teams["my-repo"] must be replaced

I applied and expected everything to work just fine.

Actual Behavior

  1. The GitHub repository was renamed.
  2. Terraform tried to update the collaborators on the repository, but since the repository had been renamed in the previous step, Terraform could no longer find it and threw the following error:
Error: DELETE https://api.github.com/orgs/<ORG_NAME>/teams/<TEAM_SLUG>/repos/<ORG_NAME>/<REPO_NAME>: 404 Not Found []

To avoid this issue, the GitHub Terraform provider should implement the following logic:

  1. Check if the Terraform plan is trying to modify the github_repository.name attribute.
  2. If the plan is modifying the repository name, review all the other resources in the plan that reference that GitHub repository.
  3. Apply the changes to all the dependent resources first, and then apply the change to the github_repository resource last.

This ensures that no resources will try to interact with a GitHub repository that no longer exists, as you've already updated all the references to the old repository name before actually renaming the repository in the final step.

Terraform Version

v1.9.8

Affected Resource(s)

  • github_repository
  • github_repository_collaborators

Terraform Configuration Files

No response

Steps to Reproduce

No response

Debug Output

No response

Panic Output

No response

Code of Conduct

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: BugSomething isn't working as documented

    Type

    No type

    Projects

    Status

    ✅ Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions