@@ -187,31 +187,37 @@ func getConfigServices(d *schema.ResourceData) (services []string) {
187
187
188
188
// Retrieve a project's services from the API
189
189
func getApiServices (pid string , config * Config , ignore map [string ]struct {}) ([]string , error ) {
190
- var apiServices []string
191
-
192
190
if ignore == nil {
193
191
ignore = make (map [string ]struct {})
194
192
}
195
193
196
- ctx := context .Background ()
197
- if err := config .clientServiceUsage .Services .
198
- List ("projects/" + pid ).
199
- Fields ("services/name" ).
200
- Filter ("state:ENABLED" ).
201
- Pages (ctx , func (r * serviceusage.ListServicesResponse ) error {
202
- for _ , v := range r .Services {
203
- // services are returned as "projects/PROJECT/services/NAME"
204
- parts := strings .Split (v .Name , "/" )
205
- if len (parts ) > 0 {
206
- name := parts [len (parts )- 1 ]
207
- if _ , ok := ignore [name ]; ! ok {
208
- apiServices = append (apiServices , name )
194
+ var apiServices []string
195
+
196
+ if err := retryTime (func () error {
197
+ // Reset the list of apiServices in case of a retry. A partial page failure
198
+ // could result in duplicate services.
199
+ apiServices = make ([]string , 0 , 10 )
200
+
201
+ ctx := context .Background ()
202
+ return config .clientServiceUsage .Services .
203
+ List ("projects/" + pid ).
204
+ Fields ("services/name" ).
205
+ Filter ("state:ENABLED" ).
206
+ Pages (ctx , func (r * serviceusage.ListServicesResponse ) error {
207
+ for _ , v := range r .Services {
208
+ // services are returned as "projects/PROJECT/services/NAME"
209
+ parts := strings .Split (v .Name , "/" )
210
+ if len (parts ) > 0 {
211
+ name := parts [len (parts )- 1 ]
212
+ if _ , ok := ignore [name ]; ! ok {
213
+ apiServices = append (apiServices , name )
214
+ }
209
215
}
210
216
}
211
- }
212
217
213
- return nil
214
- }); err != nil {
218
+ return nil
219
+ })
220
+ }, 10 ); err != nil {
215
221
return nil , errwrap .Wrapf ("failed to list services: {{err}}" , err )
216
222
}
217
223
0 commit comments