diff --git a/internal/services/network/network_manager_deployment_resource.go b/internal/services/network/network_manager_deployment_resource.go index 67ca8d136ffe..8fd5f223505e 100644 --- a/internal/services/network/network_manager_deployment_resource.go +++ b/internal/services/network/network_manager_deployment_resource.go @@ -6,6 +6,7 @@ package network import ( "context" "fmt" + "log" "time" "github.com/hashicorp/go-azure-helpers/lang/response" @@ -334,7 +335,7 @@ func resourceManagerDeploymentWaitForDeleted(ctx context.Context, client *networ _, err := state.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("waiting for the Deployment %s: %+v", *managerDeploymentId, err) + return fmt.Errorf("waiting for the %s: %+v", *managerDeploymentId, err) } return nil @@ -342,17 +343,26 @@ func resourceManagerDeploymentWaitForDeleted(ctx context.Context, client *networ func resourceManagerDeploymentWaitForFinished(ctx context.Context, client *networkmanagers.NetworkManagersClient, managerDeploymentId *parse.ManagerDeploymentId, d time.Duration) error { state := &pluginsdk.StateChangeConf{ - MinTimeout: 30 * time.Second, - Delay: 10 * time.Second, - Pending: []string{"NotStarted", "Deploying"}, - Target: []string{"Deployed"}, - Refresh: resourceManagerDeploymentResultRefreshFunc(ctx, client, managerDeploymentId), - Timeout: d, + MinTimeout: 30 * time.Second, + Delay: 10 * time.Second, + Pending: []string{"NotStarted", "Deploying"}, + Target: []string{"Deployed"}, + NotFoundChecks: 20, + Timeout: d, + Refresh: func() (interface{}, string, error) { + result, state, err := resourceManagerDeploymentResultRefreshFunc(ctx, client, managerDeploymentId)() + if state == "NotFound" { + // the deployment might not found after initial commit, https://github.com/Azure/azure-rest-api-specs/issues/27327 + // to serve NotFoundChecks, return nil result + return nil, state, err + } + return result, state, err + }, } _, err := state.WaitForStateContext(ctx) if err != nil { - return fmt.Errorf("waiting for the Deployment %s: %+v", *managerDeploymentId, err) + return fmt.Errorf("waiting for the %s: %+v", *managerDeploymentId, err) } return nil @@ -380,6 +390,7 @@ func resourceManagerDeploymentResultRefreshFunc(ctx context.Context, client *net } if resp.Model.Value == nil || len(*resp.Model.Value) == 0 || *(*resp.Model.Value)[0].ConfigurationIds == nil || len(*(*resp.Model.Value)[0].ConfigurationIds) == 0 { + log.Printf("[DEBUG] retrieving %s: listing deployments succeeds however the specific deployment was not found", *id) return resp, "NotFound", nil } diff --git a/internal/services/network/network_manager_resource_test.go b/internal/services/network/network_manager_resource_test.go index 65f8eaa6e614..a2529c37f5d7 100644 --- a/internal/services/network/network_manager_resource_test.go +++ b/internal/services/network/network_manager_resource_test.go @@ -21,7 +21,7 @@ type ManagerResource struct{} func TestAccNetworkManager(t *testing.T) { // NOTE: this is a combined test rather than separate split out tests due to - // Azure only being happy about provisioning one network manager per subscription at once + // Azure only being happy about provisioning one (connectivity or securityAdmin) network manager per subscription at once // (which our test suite can't easily work around) testCases := map[string]map[string]func(t *testing.T){