Skip to content

Commit ab6c7e6

Browse files
James Trankfcampbell
andauthored
Update security_and_analysis settings only when there are changes (#2397)
The `resourceGithubRepositoryUpdate` function currently passes the current state of security_and_analysis to the PATCH /repo request. If the repo has an enforced security configuration, this can result in the API returning a 422 response because changing security settings is not allowed in this case. Even though the security_and_analysis settings remain the same, and only some other settings are changed, the request will still fail. To avoid the request failing when security_and_analysis remains the same, we will only pass it in the request payload when changes have been made. Co-authored-by: Keegan Campbell <[email protected]>
1 parent f77aa4f commit ab6c7e6

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

github/resource_github_repository.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,11 @@ func resourceGithubRepositoryUpdate(d *schema.ResourceData, meta interface{}) er
752752
// handle visibility updates separately from other fields
753753
repoReq.Visibility = nil
754754

755+
if !d.HasChange("security_and_analysis") {
756+
repoReq.SecurityAndAnalysis = nil
757+
log.Print("[DEBUG] No security_and_analysis update required. Removing this field from the payload.")
758+
}
759+
755760
// The documentation for `default_branch` states: "This can only be set
756761
// after a repository has already been created". However, for backwards
757762
// compatibility we need to allow terraform configurations that set

0 commit comments

Comments
 (0)