@@ -134,6 +134,7 @@ func resourceGithubBranchProtection() *schema.Resource {
134134 Type : schema .TypeSet ,
135135 Optional : true ,
136136 Computed : true ,
137+ Deprecated : "GitHub is deprecating the use of `contexts`. Use a `checks` array instead." ,
137138 Description : "The list of status checks to require in order to merge into this branch. No status checks are required by default." ,
138139 Elem : & schema.Schema {Type : schema .TypeString },
139140 },
@@ -294,6 +295,12 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta any) error
294295 }
295296 protection := query .Node .Node
296297
298+ if protection .Repository .IsArchived {
299+ log .Printf ("[INFO] Removing branch protection (%s) from state because the repository (%s) is archived" , d .Id (), protection .Repository .Name )
300+ d .SetId ("" )
301+ return nil
302+ }
303+
297304 err = d .Set (PROTECTION_PATTERN , protection .Pattern )
298305 if err != nil {
299306 log .Printf ("[DEBUG] Problem setting '%s' in %s %s branch protection (%s)" , PROTECTION_PATTERN , protection .Repository .Name , protection .Pattern , d .Id ())
@@ -367,6 +374,25 @@ func resourceGithubBranchProtectionRead(d *schema.ResourceData, meta any) error
367374}
368375
369376func resourceGithubBranchProtectionUpdate (d * schema.ResourceData , meta any ) error {
377+ var query struct {
378+ Node struct {
379+ Node BranchProtectionRule `graphql:"... on BranchProtectionRule"`
380+ } `graphql:"node(id: $id)"`
381+ }
382+ variables := map [string ]any {
383+ "id" : d .Id (),
384+ }
385+ ctx := context .WithValue (context .Background (), ctxId , d .Id ())
386+ client := meta .(* Owner ).v4client
387+ err := client .Query (ctx , & query , variables )
388+ if err == nil {
389+ protection := query .Node .Node
390+ if protection .Repository .IsArchived {
391+ log .Printf ("[INFO] Skipping update of branch protection (%s) because the repository (%s) is archived" , d .Id (), protection .Repository .Name )
392+ return nil
393+ }
394+ }
395+
370396 var mutate struct {
371397 UpdateBranchProtectionRule struct {
372398 BranchProtectionRule struct {
@@ -445,6 +471,25 @@ func resourceGithubBranchProtectionUpdate(d *schema.ResourceData, meta any) erro
445471}
446472
447473func resourceGithubBranchProtectionDelete (d * schema.ResourceData , meta any ) error {
474+ var query struct {
475+ Node struct {
476+ Node BranchProtectionRule `graphql:"... on BranchProtectionRule"`
477+ } `graphql:"node(id: $id)"`
478+ }
479+ variables := map [string ]any {
480+ "id" : d .Id (),
481+ }
482+ ctx := context .WithValue (context .Background (), ctxId , d .Id ())
483+ client := meta .(* Owner ).v4client
484+ err := client .Query (ctx , & query , variables )
485+ if err == nil {
486+ protection := query .Node .Node
487+ if protection .Repository .IsArchived {
488+ log .Printf ("[INFO] Skipping deletion of branch protection (%s) because the repository (%s) is archived" , d .Id (), protection .Repository .Name )
489+ return nil
490+ }
491+ }
492+
448493 var mutate struct {
449494 DeleteBranchProtectionRule struct { // Empty struct does not work
450495 ClientMutationId githubv4.ID
0 commit comments