Skip to content

Commit a42b848

Browse files
committed
Update Read to combine Invites and Collaborator users
This is to prevent drift when external users have not accepted invites yet. Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 18178b1 commit a42b848

3 files changed

Lines changed: 13 additions & 16 deletions

File tree

github/resource_github_repository_collaborators.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ func resourceGithubRepositoryCollaboratorsRead(ctx context.Context, d *schema.Re
255255
return diag.FromErr(err)
256256
}
257257

258-
if err := d.Set("user", ghUsers.flatten()); err != nil {
259-
return diag.FromErr(err)
260-
}
261-
262258
if isOrg {
263259
ghTeams, err := listTeamCollaborators(ctx, client, owner, repoName, inTeams, inIgnoreTeams)
264260
if err != nil {
@@ -280,6 +276,11 @@ func resourceGithubRepositoryCollaboratorsRead(ctx context.Context, d *schema.Re
280276
return diag.FromErr(err)
281277
}
282278

279+
combinedUsersAndInvitations := slices.Concat(ghUsers, ghInvitations)
280+
if err := d.Set("user", combinedUsersAndInvitations.flatten()); err != nil {
281+
return diag.FromErr(err)
282+
}
283+
283284
if err = d.Set("invitation_ids", ghInvitations.flattenInvitations()); err != nil {
284285
return diag.FromErr(err)
285286
}

github/resource_github_repository_collaborators_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ resource "github_repository_collaborators" "test" {
5757
}
5858
`, repoName, teamName0, teamName1, collaboratorUser)
5959

60-
resource.Test(t, resource.TestCase{
60+
resource.ParallelTest(t, resource.TestCase{
6161
PreCheck: func() { skipUnlessHasOrgs(t) },
6262
ProviderFactories: providerFactories,
6363
Steps: []resource.TestStep{
@@ -118,14 +118,14 @@ resource "github_repository_collaborators" "test" {
118118
}
119119
`, repoName, testAccConf.testExternalUser)
120120

121-
resource.Test(t, resource.TestCase{
121+
resource.ParallelTest(t, resource.TestCase{
122122
PreCheck: func() { skipUnauthenticated(t) },
123123
ProviderFactories: providerFactories,
124124
Steps: []resource.TestStep{
125125
{
126126
Config: config,
127127
ConfigStateChecks: []statecheck.StateCheck{
128-
statecheck.ExpectKnownValue("github_repository_collaborators.test", tfjsonpath.New("user"), knownvalue.SetSizeExact(0)),
128+
statecheck.ExpectKnownValue("github_repository_collaborators.test", tfjsonpath.New("user"), knownvalue.SetSizeExact(1)),
129129
statecheck.ExpectKnownValue("github_repository_collaborators.test", tfjsonpath.New("team"), knownvalue.SetSizeExact(0)),
130130
statecheck.ExpectKnownValue("github_repository_collaborators.test", tfjsonpath.New("invitation_ids"), knownvalue.MapSizeExact(1)),
131131
},
@@ -196,7 +196,7 @@ resource "github_repository_collaborators" "test" {
196196
}
197197
`, configPre)
198198

199-
resource.Test(t, resource.TestCase{
199+
resource.ParallelTest(t, resource.TestCase{
200200
PreCheck: func() { skipUnlessHasOrgs(t) },
201201
ProviderFactories: providerFactories,
202202
Steps: []resource.TestStep{
@@ -270,7 +270,7 @@ resource "github_repository_collaborators" "test" {
270270
}
271271
`, configPre)
272272

273-
resource.Test(t, resource.TestCase{
273+
resource.ParallelTest(t, resource.TestCase{
274274
PreCheck: func() { skipUnauthenticated(t) },
275275
ProviderFactories: providerFactories,
276276
Steps: []resource.TestStep{
@@ -336,7 +336,7 @@ resource "github_repository_collaborators" "test" {
336336
}
337337
`, configPre)
338338

339-
resource.Test(t, resource.TestCase{
339+
resource.ParallelTest(t, resource.TestCase{
340340
PreCheck: func() { skipUnlessHasOrgs(t) },
341341
ProviderFactories: providerFactories,
342342
Steps: []resource.TestStep{
@@ -397,7 +397,7 @@ resource "github_repository_collaborators" "test" {
397397
}
398398
`, configPre)
399399

400-
resource.Test(t, resource.TestCase{
400+
resource.ParallelTest(t, resource.TestCase{
401401
PreCheck: func() { skipUnlessHasOrgs(t) },
402402
ProviderFactories: providerFactories,
403403
Steps: []resource.TestStep{
@@ -451,7 +451,7 @@ resource "github_repository_collaborators" "test" {
451451
}
452452
`, repoName, teamName)
453453

454-
resource.Test(t, resource.TestCase{
454+
resource.ParallelTest(t, resource.TestCase{
455455
PreCheck: func() { skipUnlessHasOrgs(t) },
456456
ProviderFactories: providerFactories,
457457
Steps: []resource.TestStep{

github/util_user.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ func (u userCollaborator) flatten() any {
2121
"permission": u.permission,
2222
}
2323

24-
if u.invitationID != nil {
25-
m["invitation_id"] = *u.invitationID
26-
}
27-
2824
return m
2925
}
3026

0 commit comments

Comments
 (0)