provider/google: Add pagination for reading project services (#13758)
This commit is contained in:
parent
f4b7d9c53b
commit
8ae5ad46e0
|
@ -163,7 +163,9 @@ func getConfigServices(d *schema.ResourceData) (services []string) {
|
||||||
func getApiServices(pid string, config *Config) ([]string, error) {
|
func getApiServices(pid string, config *Config) ([]string, error) {
|
||||||
apiServices := make([]string, 0)
|
apiServices := make([]string, 0)
|
||||||
// Get services from the API
|
// Get services from the API
|
||||||
svcResp, err := config.clientServiceMan.Services.List().ConsumerId("project:" + pid).Do()
|
token := ""
|
||||||
|
for paginate := true; paginate; {
|
||||||
|
svcResp, err := config.clientServiceMan.Services.List().ConsumerId("project:" + pid).PageToken(token).Do()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return apiServices, err
|
return apiServices, err
|
||||||
}
|
}
|
||||||
|
@ -172,6 +174,9 @@ func getApiServices(pid string, config *Config) ([]string, error) {
|
||||||
apiServices = append(apiServices, v.ServiceName)
|
apiServices = append(apiServices, v.ServiceName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
token = svcResp.NextPageToken
|
||||||
|
paginate = token != ""
|
||||||
|
}
|
||||||
return apiServices, nil
|
return apiServices, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
func testAccGoogleProjectAssociateServicesBasic(services []string, pid, name, org string) string {
|
||||||
return fmt.Sprintf(`
|
return fmt.Sprintf(`
|
||||||
resource "google_project" "acceptance" {
|
resource "google_project" "acceptance" {
|
||||||
|
|
Loading…
Reference in New Issue