Skip to content

Commit dd27afb

Browse files
EvalleCecile Robert-Michon
authored andcommitted
Add a missing code to skip NSG deletion if the vnet is unmanaged
1 parent 1a1269a commit dd27afb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

cloud/services/securitygroups/securitygroups.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@ func (s *Service) Delete(ctx context.Context) error {
140140
ctx, span := tele.Tracer().Start(ctx, "securitygroups.Service.Delete")
141141
defer span.End()
142142

143+
if !s.Scope.IsVnetManaged() {
144+
s.Scope.V(4).Info("Skipping network security group delete in custom VNet mode")
145+
return nil
146+
}
147+
143148
for _, nsgSpec := range s.Scope.NSGSpecs() {
144149
s.Scope.V(2).Info("deleting security group", "security group", nsgSpec.Name)
145150
err := s.client.Delete(ctx, s.Scope.ResourceGroup(), nsgSpec.Name)

cloud/services/securitygroups/securitygroups_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ func TestDeleteSecurityGroups(t *testing.T) {
283283
})
284284
s.ResourceGroup().AnyTimes().Return("my-rg")
285285
s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New())
286+
s.IsVnetManaged().Return(true)
286287
m.Delete(gomockinternal.AContext(), "my-rg", "nsg-one")
287288
m.Delete(gomockinternal.AContext(), "my-rg", "nsg-two")
288289
},
@@ -302,11 +303,19 @@ func TestDeleteSecurityGroups(t *testing.T) {
302303
})
303304
s.ResourceGroup().AnyTimes().Return("my-rg")
304305
s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New())
306+
s.IsVnetManaged().Return(true)
305307
m.Delete(gomockinternal.AContext(), "my-rg", "nsg-one").
306308
Return(autorest.NewErrorWithResponse("", "", &http.Response{StatusCode: 404}, "Not found"))
307309
m.Delete(gomockinternal.AContext(), "my-rg", "nsg-two")
308310
},
309311
},
312+
{
313+
name: "skipping network security group delete in custom VNet mode",
314+
expect: func(s *mock_securitygroups.MockNSGScopeMockRecorder, m *mock_securitygroups.MockclientMockRecorder) {
315+
s.IsVnetManaged().Return(false)
316+
s.V(gomock.AssignableToTypeOf(2)).AnyTimes().Return(klogr.New())
317+
},
318+
},
310319
}
311320
for _, tc := range testcases {
312321
tc := tc

0 commit comments

Comments
 (0)