terraform-google-modules / terraform-google-project-factory

Creates an opinionated Google Cloud project by using Shared VPC, IAM, and Google Cloud APIs
https://registry.terraform.io/modules/terraform-google-modules/project-factory/google
Apache License 2.0
826 stars 535 forks source link

API Page size too small #193

Closed leone145 closed 5 years ago

leone145 commented 5 years ago

During preconditions check, if the seed project has a large number of APIs enabled, the python precondition check cannot page and preconditions fail. Suggest increasing the pageSize option as below.

        parent = "projects/" + self.project_id
        request = service.services().list(
            parent=parent,
            filter='state:ENABLED',
            pageSize='200'
        )

Error observed that led to the discovery. ': exit status 1. Output: [ { "type": "Required APIs on service account project", "name": "projects/project-abc123", "satisfied": [ "cloudresourcemanager.googleapis.com", "appengine.googleapis.com", "cloudbilling.googleapis.com", "admin.googleapis.com" ], "unsatisfied": [ "iam.googleapis.com" ] },

leone145 commented 5 years ago

Second suggestion would be to use services().get instead of services().list

        enabled = []
        for r in self.REQUIRED_APIS:
            request = service.services().get(
                name="projects/" + self.project_id + "/services/" + r
            )

            response = request.execute()

            if response['state'] == "ENABLED":
                enabled.append(r)
morgante commented 5 years ago

Thanks, good catch. We'd be happy to look at a PR for either fix.

aaron-lane commented 5 years ago

Fixed by #220.