From 1f059ba2f05124c24295c02d53ced92a4f0150ce Mon Sep 17 00:00:00 2001 From: ziyeqf <51212351+ziyeqf@users.noreply.github.com> Date: Thu, 4 Jan 2024 10:58:43 +0800 Subject: [PATCH] `azurerm_iothub` - fix a bug for `local_auth_enabled` (#24326) --- internal/services/iothub/iothub_resource.go | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/internal/services/iothub/iothub_resource.go b/internal/services/iothub/iothub_resource.go index d3ffb8dcf01f..fe0f2a2c401c 100644 --- a/internal/services/iothub/iothub_resource.go +++ b/internal/services/iothub/iothub_resource.go @@ -9,6 +9,7 @@ import ( "net/url" "regexp" "sort" + "strconv" "strings" "time" @@ -971,6 +972,31 @@ func resourceIotHubUpdate(d *pluginsdk.ResourceData, meta interface{}) error { return fmt.Errorf("waiting for update of %q: %+v", id, err) } + // When the `local_authentication_enabled` updated, GET on the resource is returned with 404 for a while. + // Tracked on https://github.com/Azure/azure-rest-api-specs/issues/27183 + timeout, _ := ctx.Deadline() + stateConf := &pluginsdk.StateChangeConf{ + Pending: []string{"404"}, + Target: []string{"200"}, + Refresh: func() (result interface{}, state string, err error) { + resp, err := client.Get(ctx, id.ResourceGroup, id.Name) + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + return resp, strconv.Itoa(resp.StatusCode), nil + } + return resp, strconv.Itoa(resp.StatusCode), err + } + return resp, strconv.Itoa(resp.StatusCode), nil + }, + Delay: 1 * time.Minute, + PollInterval: 1 * time.Minute, + Timeout: time.Until(timeout), + } + + if _, err := stateConf.WaitForStateContext(ctx); err != nil { + return fmt.Errorf("waiting for creation/update of %q: %+v", id, err) + } + d.SetId(id.ID()) return resourceIotHubRead(d, meta)