Skip to content

Commit f8f87fa

Browse files
committed
fixup flakey test by fixing delete prerequisits
1 parent 135c273 commit f8f87fa

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

internal/services/conditionalaccess/named_location_resource.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,10 @@ func namedLocationResourceDelete(ctx context.Context, d *pluginsdk.ResourceData,
295295

296296
return tf.ErrorDiagF(err, "updating %s prior to deletion", id)
297297
}
298+
299+
if err = consistency.WaitForUpdate(ctx, ipNamedLocationTrustedDeleteWait(client, id)); err != nil {
300+
return tf.ErrorDiagF(err, "waiting for removal of trusted status on %s", id)
301+
}
298302
}
299303

300304
resp, err := client.DeleteConditionalAccessNamedLocation(ctx, *id, conditionalaccessnamedlocation.DefaultDeleteConditionalAccessNamedLocationOperationOptions())
@@ -358,6 +362,30 @@ func ipNamedLocationWait(client *conditionalaccessnamedlocation.ConditionalAcces
358362
}
359363
}
360364

365+
func ipNamedLocationTrustedDeleteWait(client *conditionalaccessnamedlocation.ConditionalAccessNamedLocationClient, id *stable.IdentityConditionalAccessNamedLocationId) consistency.ChangeFunc {
366+
return func(ctx context.Context) (*bool, error) {
367+
resp, err := client.GetConditionalAccessNamedLocation(ctx, *id, conditionalaccessnamedlocation.DefaultGetConditionalAccessNamedLocationOperationOptions())
368+
if err != nil {
369+
return nil, err
370+
}
371+
372+
if resp.Model == nil {
373+
return nil, errors.New("returned model was nil")
374+
}
375+
376+
namedLocation, ok := resp.Model.(stable.IPNamedLocation)
377+
if !ok {
378+
return nil, errors.New("returned model was not an IPNamedLocation")
379+
}
380+
381+
if pointer.From(namedLocation.IsTrusted) {
382+
return pointer.To(false), nil
383+
}
384+
385+
return pointer.To(true), nil
386+
}
387+
}
388+
361389
func countryNamedLocationWait(client *conditionalaccessnamedlocation.ConditionalAccessNamedLocationClient, id *stable.IdentityConditionalAccessNamedLocationId, v interface{}) consistency.ChangeFunc {
362390
return func(ctx context.Context) (*bool, error) {
363391
resp, err := client.GetConditionalAccessNamedLocation(ctx, *id, conditionalaccessnamedlocation.DefaultGetConditionalAccessNamedLocationOperationOptions())

0 commit comments

Comments
 (0)