Skip to content

Commit

Permalink
security center: fix acctest (#22871)
Browse files Browse the repository at this point in the history
* fix advanced threat protection flakey acctest

* update per comment

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>

* update per comment

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>

* ensure the ctx has deadline

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>

---------

Signed-off-by: ziyeqf <51212351+ziyeqf@users.noreply.github.com>
  • Loading branch information
ziyeqf committed Sep 5, 2023
1 parent 481240e commit c94bc43
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,39 @@ func resourceAdvancedThreatProtectionCreateUpdate(d *pluginsdk.ResourceData, met
return fmt.Errorf("updating Advanced Threat protection for %q: %+v", id.TargetResourceID, err)
}

deadline, ok := ctx.Deadline()
if !ok {
return fmt.Errorf("internal-error: context had no deadline")
}

// the API appears to be eventually consistent, tracked on https://github.com/Azure/azure-rest-api-specs/issues/25232
stateConf := &pluginsdk.StateChangeConf{
Pending: []string{"diff"},
Target: []string{"consistent"},
Refresh: func() (result interface{}, state string, err error) {
resp, err := client.Get(ctx, id.TargetResourceID)
if err != nil {
return resp, "error", err
}
if atpp := resp.AdvancedThreatProtectionProperties; atpp != nil {
respEnabled := atpp.IsEnabled != nil && *atpp.IsEnabled
if respEnabled == d.Get("enabled").(bool) {
return resp, "consistent", nil
} else {
return resp, "diff", nil
}
}
return resp, "error", fmt.Errorf("Properties was nil")
},
MinTimeout: 1 * time.Minute,
ContinuousTargetOccurence: 3,
Timeout: time.Until(deadline),
}

if _, err := stateConf.WaitForStateContext(ctx); err != nil {
return fmt.Errorf("waiting for provisioning state of advanced threat protection: %+v", err)
}

d.SetId(id.ID())
return resourceAdvancedThreatProtectionRead(d, meta)
}
Expand Down

0 comments on commit c94bc43

Please sign in to comment.