Skip to content

Commit 68741e0

Browse files
authored
fix: Only send allow_forking on change (#3174)
Signed-off-by: Steve Hipwell <[email protected]>
1 parent 64cb030 commit 68741e0

2 files changed

Lines changed: 74 additions & 20 deletions

File tree

github/resource_github_repository.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,11 @@ func resourceGithubRepositoryObject(d *schema.ResourceData) *github.Repository {
630630
}
631631

632632
// only configure allow forking if repository is not public
633-
if allowForking, ok := d.GetOkExists("allow_forking"); ok && visibility != "public" { //nolint:staticcheck,SA1019 // We sometimes need to use GetOkExists for booleans
634-
if val, ok := allowForking.(bool); ok {
635-
repository.AllowForking = github.Ptr(val)
633+
if visibility != "public" && (d.IsNewResource() || d.HasChange("allow_forking")) {
634+
if allowForking, ok := d.GetOkExists("allow_forking"); ok { //nolint:staticcheck,SA1019 // We sometimes need to use GetOkExists for booleans
635+
if val, ok := allowForking.(bool); ok {
636+
repository.AllowForking = github.Ptr(val)
637+
}
636638
}
637639
}
638640

github/resource_github_repository_test.go

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,20 +1078,15 @@ resource "github_repository" "test" {
10781078
}
10791079
`, testRepoName)
10801080

1081-
check := resource.ComposeTestCheckFunc(
1082-
resource.TestCheckResourceAttr(
1083-
"github_repository.private", "visibility",
1084-
"private",
1085-
),
1086-
)
1087-
10881081
resource.Test(t, resource.TestCase{
10891082
PreCheck: func() { skipUnauthenticated(t) },
10901083
ProviderFactories: providerFactories,
10911084
Steps: []resource.TestStep{
10921085
{
1093-
Config: config,
1094-
Check: check,
1086+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1087+
Check: resource.ComposeTestCheckFunc(
1088+
resource.TestCheckResourceAttr("github_repository.private", "visibility", "private"),
1089+
),
10951090
},
10961091
},
10971092
})
@@ -1107,20 +1102,15 @@ resource "github_repository" "test" {
11071102
}
11081103
`, testRepoName)
11091104

1110-
check := resource.ComposeTestCheckFunc(
1111-
resource.TestCheckResourceAttr(
1112-
"github_repository.test", "visibility",
1113-
"internal",
1114-
),
1115-
)
1116-
11171105
resource.Test(t, resource.TestCase{
11181106
PreCheck: func() { skipUnlessMode(t, enterprise) },
11191107
ProviderFactories: providerFactories,
11201108
Steps: []resource.TestStep{
11211109
{
11221110
Config: config,
1123-
Check: check,
1111+
Check: resource.ComposeTestCheckFunc(
1112+
resource.TestCheckResourceAttr("github_repository.test", "visibility", "internal"),
1113+
),
11241114
},
11251115
},
11261116
})
@@ -1327,6 +1317,68 @@ resource "github_repository" "test" {
13271317
},
13281318
})
13291319
})
1320+
1321+
t.Run("check_allow_forking_not_set", func(t *testing.T) {
1322+
t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting forking at the repo level.")
1323+
1324+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1325+
testRepoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
1326+
1327+
config := `
1328+
resource "github_repository" "private" {
1329+
name = "%s"
1330+
description = "%s"
1331+
visibility = "private"
1332+
}
1333+
`
1334+
1335+
resource.Test(t, resource.TestCase{
1336+
PreCheck: func() { skipUnauthenticated(t) },
1337+
ProviderFactories: providerFactories,
1338+
Steps: []resource.TestStep{
1339+
{
1340+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1341+
Check: resource.ComposeTestCheckFunc(
1342+
resource.TestCheckResourceAttr("github_repository.private", "allow_forking", "false"),
1343+
),
1344+
},
1345+
{
1346+
Config: fmt.Sprintf(config, testRepoName, "bar"),
1347+
},
1348+
},
1349+
})
1350+
})
1351+
1352+
t.Run("check_vulnerability_alerts_not_set", func(t *testing.T) {
1353+
t.Skip("This test should be run manually after confirming that the test organization has been correctly configured to disable setting vulnerability alerts at the repo level.")
1354+
1355+
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
1356+
testRepoName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
1357+
1358+
config := `
1359+
resource "github_repository" "private" {
1360+
name = "%s"
1361+
description = "%s"
1362+
visibility = "public"
1363+
}
1364+
`
1365+
1366+
resource.Test(t, resource.TestCase{
1367+
PreCheck: func() { skipUnauthenticated(t) },
1368+
ProviderFactories: providerFactories,
1369+
Steps: []resource.TestStep{
1370+
{
1371+
Config: fmt.Sprintf(config, testRepoName, "foo"),
1372+
Check: resource.ComposeTestCheckFunc(
1373+
resource.TestCheckResourceAttr("github_repository.private", "vulnerability_alerts", "true"),
1374+
),
1375+
},
1376+
{
1377+
Config: fmt.Sprintf(config, testRepoName, "bar"),
1378+
},
1379+
},
1380+
})
1381+
})
13301382
}
13311383

13321384
func Test_expandPages(t *testing.T) {

0 commit comments

Comments
 (0)