@@ -212,16 +212,16 @@ func resourceBranchRestrictionsRead(ctx context.Context, d *schema.ResourceData,
212212 brRes , res , err := brApi .RepositoriesWorkspaceRepoSlugBranchRestrictionsIdGet (c .AuthContext , url .PathEscape (d .Id ()),
213213 d .Get ("repository" ).(string ), d .Get ("owner" ).(string ))
214214
215- if err != nil {
216- return diag .FromErr (err )
217- }
218-
219- if res .StatusCode == http .StatusNotFound {
215+ if res != nil && res .StatusCode == http .StatusNotFound {
220216 log .Printf ("[WARN] Branch Restrictions (%s) not found, removing from state" , d .Id ())
221217 d .SetId ("" )
222218 return nil
223219 }
224220
221+ if err != nil {
222+ return diag .FromErr (err )
223+ }
224+
225225 d .SetId (string (fmt .Sprintf ("%v" , brRes .Id )))
226226 d .Set ("kind" , brRes .Kind )
227227 d .Set ("pattern" , brRes .Pattern )
@@ -254,9 +254,14 @@ func resourceBranchRestrictionsDelete(ctx context.Context, d *schema.ResourceDat
254254 c := m .(Clients ).genClient
255255 brApi := c .ApiClient .BranchRestrictionsApi
256256
257- _ , err := brApi .RepositoriesWorkspaceRepoSlugBranchRestrictionsIdDelete (c .AuthContext , url .PathEscape (d .Id ()),
257+ res , err := brApi .RepositoriesWorkspaceRepoSlugBranchRestrictionsIdDelete (c .AuthContext , url .PathEscape (d .Id ()),
258258 d .Get ("repository" ).(string ), d .Get ("owner" ).(string ))
259259
260+ if res != nil && res .StatusCode == http .StatusNotFound {
261+ log .Printf ("[WARN] Branch Restrictions (%s) not found, removing from state" , d .Id ())
262+ return nil
263+ }
264+
260265 if err != nil {
261266 return diag .FromErr (err )
262267 }
0 commit comments