@@ -98,41 +98,21 @@ func resourceGitlabPipelineScheduleRead(ctx context.Context, d *schema.ResourceD
98
98
99
99
log .Printf ("[DEBUG] read gitlab PipelineSchedule %s/%d" , project , pipelineScheduleID )
100
100
101
- opt := & gitlab.ListPipelineSchedulesOptions {
102
- Page : 1 ,
103
- PerPage : 20 ,
104
- }
105
-
106
- found := false
107
- for {
108
- pipelineSchedules , resp , err := client .PipelineSchedules .ListPipelineSchedules (project , opt , gitlab .WithContext (ctx ))
109
- if err != nil {
110
- return diag .FromErr (err )
111
- }
112
- for _ , pipelineSchedule := range pipelineSchedules {
113
- if pipelineSchedule .ID == pipelineScheduleID {
114
- d .Set ("description" , pipelineSchedule .Description )
115
- d .Set ("ref" , pipelineSchedule .Ref )
116
- d .Set ("cron" , pipelineSchedule .Cron )
117
- d .Set ("cron_timezone" , pipelineSchedule .CronTimezone )
118
- d .Set ("active" , pipelineSchedule .Active )
119
- found = true
120
- break
121
- }
122
- }
123
-
124
- if found || resp .CurrentPage >= resp .TotalPages {
125
- break
101
+ pipelineSchedule , _ , err := client .PipelineSchedules .GetPipelineSchedule (project , pipelineScheduleID , gitlab .WithContext (ctx ))
102
+ if err != nil {
103
+ if is404 (err ) {
104
+ log .Printf ("[DEBUG] PipelineSchedule %d in project %s does not exist, removing from state" , pipelineScheduleID , project )
105
+ d .SetId ("" )
106
+ return nil
126
107
}
127
-
128
- opt .Page = resp .NextPage
129
- }
130
- if ! found {
131
- log .Printf ("[DEBUG] PipelineSchedule %d no longer exists in gitlab" , pipelineScheduleID )
132
- d .SetId ("" )
133
- return nil
108
+ return diag .FromErr (err )
134
109
}
135
110
111
+ d .Set ("description" , pipelineSchedule .Description )
112
+ d .Set ("ref" , pipelineSchedule .Ref )
113
+ d .Set ("cron" , pipelineSchedule .Cron )
114
+ d .Set ("cron_timezone" , pipelineSchedule .CronTimezone )
115
+ d .Set ("active" , pipelineSchedule .Active )
136
116
return nil
137
117
}
138
118
0 commit comments