问题
I am very new to GCP with terraform and I want to deploy all my modules using centralized tools.
Is there any way to remove the step of enabling google API's every time so that deployment is not interrupted?
回答1:
There is a Terraform resource definition called "google_project_service" that allows one to enable a service (API). This is documented at google_project_service.
An example of usage appears to be:
resource "google_project_service" "project" {
project = "your-project-id"
service = "iam.googleapis.com"
}
回答2:
Yes , you can use google_project_service
resource to enable one API at a time. You can use count or other loop method to enable multiple APIs. You would need project editor/owner role to do this.
You can find the example here https://github.com/CloudNativeTech/gdg-terraform-gcp-workshop/blob/master/03-project/project.tf#L23
来源:https://stackoverflow.com/questions/59055395/can-i-automatically-enable-apis-when-using-gcp-cloud-with-terraform