mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-07-09 03:28:29 +00:00
Retry while listing enabled services (#1573)
This fixes GH-1562 for realz
This commit is contained in:
parent
5f0dcf4787
commit
aff6bc6519
|
@ -187,31 +187,37 @@ func getConfigServices(d *schema.ResourceData) (services []string) {
|
||||||
|
|
||||||
// Retrieve a project's services from the API
|
// Retrieve a project's services from the API
|
||||||
func getApiServices(pid string, config *Config, ignore map[string]struct{}) ([]string, error) {
|
func getApiServices(pid string, config *Config, ignore map[string]struct{}) ([]string, error) {
|
||||||
var apiServices []string
|
|
||||||
|
|
||||||
if ignore == nil {
|
if ignore == nil {
|
||||||
ignore = make(map[string]struct{})
|
ignore = make(map[string]struct{})
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
var apiServices []string
|
||||||
if err := config.clientServiceUsage.Services.
|
|
||||||
List("projects/"+pid).
|
if err := retryTime(func() error {
|
||||||
Fields("services/name").
|
// Reset the list of apiServices in case of a retry. A partial page failure
|
||||||
Filter("state:ENABLED").
|
// could result in duplicate services.
|
||||||
Pages(ctx, func(r *serviceusage.ListServicesResponse) error {
|
apiServices = make([]string, 0, 10)
|
||||||
for _, v := range r.Services {
|
|
||||||
// services are returned as "projects/PROJECT/services/NAME"
|
ctx := context.Background()
|
||||||
parts := strings.Split(v.Name, "/")
|
return config.clientServiceUsage.Services.
|
||||||
if len(parts) > 0 {
|
List("projects/"+pid).
|
||||||
name := parts[len(parts)-1]
|
Fields("services/name").
|
||||||
if _, ok := ignore[name]; !ok {
|
Filter("state:ENABLED").
|
||||||
apiServices = append(apiServices, name)
|
Pages(ctx, func(r *serviceusage.ListServicesResponse) error {
|
||||||
|
for _, v := range r.Services {
|
||||||
|
// services are returned as "projects/PROJECT/services/NAME"
|
||||||
|
parts := strings.Split(v.Name, "/")
|
||||||
|
if len(parts) > 0 {
|
||||||
|
name := parts[len(parts)-1]
|
||||||
|
if _, ok := ignore[name]; !ok {
|
||||||
|
apiServices = append(apiServices, name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}); err != nil {
|
})
|
||||||
|
}, 10); err != nil {
|
||||||
return nil, errwrap.Wrapf("failed to list services: {{err}}", err)
|
return nil, errwrap.Wrapf("failed to list services: {{err}}", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user