diff --git a/github/resource_github_repository_collaborators.go b/github/resource_github_repository_collaborators.go index 4a7d16392..fa1d9b089 100644 --- a/github/resource_github_repository_collaborators.go +++ b/github/resource_github_repository_collaborators.go @@ -27,7 +27,6 @@ func resourceGithubRepositoryCollaborators() *schema.Resource { "repository": { Type: schema.TypeString, Required: true, - ForceNew: true, }, "user": { Type: schema.TypeSet, @@ -98,6 +97,17 @@ func resourceGithubRepositoryCollaborators() *schema.Resource { customdiff.ComputedIf("invitation_ids", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool { return d.HasChange("user") }), + customdiff.ForceNewIf("repository", func(ctx context.Context, d *schema.ResourceDiff, meta interface{}) bool { + _, new := d.GetChange("repository") + repoID, err := getRepositoryID(fmt.Sprintf("%s", new), meta) + if err != nil { + // If we cannot get the repository ID, force new + return true + } + + // If the repository ID has changed, force new + return d.Id() != fmt.Sprintf("%d", repoID) + }), ), } } @@ -532,7 +542,12 @@ func resourceGithubRepositoryCollaboratorsCreate(d *schema.ResourceData, meta in return err } - d.SetId(repoName) + repoID, err := getRepositoryID(repoName, meta) + if err != nil { + return err + } + + d.SetId(fmt.Sprintf("%d", repoID)) return resourceGithubRepositoryCollaboratorsRead(d, meta) }