Skip to content

Commit

Permalink
azurerm_container_registry_task_schedule_run_now: fix state tracking (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
walkline authored Jan 23, 2024
1 parent 396e518 commit 43ffd70
Showing 1 changed file with 7 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)},
Expand All @@ -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,
Expand Down

0 comments on commit 43ffd70

Please sign in to comment.