diff --git a/builtin/providers/google/resource_google_project_services.go b/builtin/providers/google/resource_google_project_services.go index e28456593..3a9c66730 100644 --- a/builtin/providers/google/resource_google_project_services.go +++ b/builtin/providers/google/resource_google_project_services.go @@ -163,14 +163,19 @@ func getConfigServices(d *schema.ResourceData) (services []string) { func getApiServices(pid string, config *Config) ([]string, error) { apiServices := make([]string, 0) // Get services from the API - svcResp, err := config.clientServiceMan.Services.List().ConsumerId("project:" + pid).Do() - if err != nil { - return apiServices, err - } - for _, v := range svcResp.Services { - if _, ok := ignore[v.ServiceName]; !ok { - apiServices = append(apiServices, v.ServiceName) + token := "" + for paginate := true; paginate; { + svcResp, err := config.clientServiceMan.Services.List().ConsumerId("project:" + pid).PageToken(token).Do() + if err != nil { + return apiServices, err } + for _, v := range svcResp.Services { + if _, ok := ignore[v.ServiceName]; !ok { + apiServices = append(apiServices, v.ServiceName) + } + } + token = svcResp.NextPageToken + paginate = token != "" } return apiServices, nil } diff --git a/builtin/providers/google/resource_google_project_services_test.go b/builtin/providers/google/resource_google_project_services_test.go index 155a297c7..238298e41 100644 --- a/builtin/providers/google/resource_google_project_services_test.go +++ b/builtin/providers/google/resource_google_project_services_test.go @@ -164,6 +164,61 @@ func TestAccGoogleProjectServices_ignoreUnenablableServices(t *testing.T) { }) } +func TestAccGoogleProjectServices_manyServices(t *testing.T) { + skipIfEnvNotSet(t, + []string{ + "GOOGLE_ORG", + "GOOGLE_BILLING_ACCOUNT", + }..., + ) + + billingId := os.Getenv("GOOGLE_BILLING_ACCOUNT") + pid := "terraform-" + acctest.RandString(10) + services := []string{ + "bigquery-json.googleapis.com", + "cloudbuild.googleapis.com", + "cloudfunctions.googleapis.com", + "cloudresourcemanager.googleapis.com", + "cloudtrace.googleapis.com", + "compute-component.googleapis.com", + "container.googleapis.com", + "containerregistry.googleapis.com", + "dataflow.googleapis.com", + "dataproc.googleapis.com", + "deploymentmanager.googleapis.com", + "dns.googleapis.com", + "endpoints.googleapis.com", + "iam.googleapis.com", + "logging.googleapis.com", + "ml.googleapis.com", + "monitoring.googleapis.com", + "pubsub.googleapis.com", + "replicapool.googleapis.com", + "replicapoolupdater.googleapis.com", + "resourceviews.googleapis.com", + "runtimeconfig.googleapis.com", + "servicecontrol.googleapis.com", + "servicemanagement.googleapis.com", + "sourcerepo.googleapis.com", + "spanner.googleapis.com", + "storage-api.googleapis.com", + "storage-component.googleapis.com", + } + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccGoogleProjectAssociateServicesBasic_withBilling(services, pid, pname, org, billingId), + Check: resource.ComposeTestCheckFunc( + testProjectServicesMatch(services, pid), + ), + }, + }, + }) +} + func testAccGoogleProjectAssociateServicesBasic(services []string, pid, name, org string) string { return fmt.Sprintf(` resource "google_project" "acceptance" {