diff --git a/internal/services/containers/container_registry_task_schedule_run_now_resource.go b/internal/services/containers/container_registry_task_schedule_run_now_resource.go index 0ad4ba38b89d..3268902128de 100644 --- a/internal/services/containers/container_registry_task_schedule_run_now_resource.go +++ b/internal/services/containers/container_registry_task_schedule_run_now_resource.go @@ -87,36 +87,23 @@ func (r ContainerRegistryTaskScheduleResource) Create() sdk.ResourceFunc { registryId := registries.NewRegistryID(taskId.SubscriptionId, taskId.ResourceGroupName, taskId.RegistryName) registryClient := metadata.Client.Containers.ContainerRegistryClient_v2019_06_01_preview.Registries - _, err = registryClient.ScheduleRun(ctx, registryId, req) + scheduleResp, err := registryClient.ScheduleRun(ctx, registryId, req) if err != nil { return fmt.Errorf("scheduling the task: %+v", err) } - - runsClient := metadata.Client.Containers.ContainerRegistryClient_v2019_06_01_preview.Runs - run, err := runsClient.List(ctx, runs.RegistryId(registryId), runs.ListOperationOptions{}) - if err != nil { - return fmt.Errorf("retrieving runs for %s: %+v", taskId, err) - } - - if run.Model == nil { - return fmt.Errorf("model was nil for %s", registryId) + if scheduleResp.Model == nil { + return fmt.Errorf("ScheduleRun model was nil for taskID %s", taskId) } - - runName := "" - for _, v := range *run.Model { - if v.Properties != nil && pointer.From(v.Properties.Task) == taskId.TaskName { - runName = pointer.From(v.Name) - break - } - } - + runName := pointer.From(scheduleResp.Model.Name) if runName == "" { return fmt.Errorf("unexpected nil scheduled run name") } runId := runs.NewRunID(registryId.SubscriptionId, registryId.ResourceGroupName, registryId.RegistryName, runName) + runsClient := metadata.Client.Containers.ContainerRegistryClient_v2019_06_01_preview.Runs + timeout, _ := ctx.Deadline() stateConf := &pluginsdk.StateChangeConf{ Pending: []string{string(registries.RunStatusQueued), string(registries.RunStatusStarted), string(registries.RunStatusRunning)}, @@ -131,7 +118,7 @@ func (r ContainerRegistryTaskScheduleResource) Create() sdk.ResourceFunc { return nil, "", fmt.Errorf("model was nil for %s", runId) } - return run, string(*resp.Model.Properties.Status), nil + return resp, string(*resp.Model.Properties.Status), nil }, ContinuousTargetOccurence: 1, PollInterval: 5 * time.Second,