Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds serviceusage api in precheck function #7447

Merged
merged 7 commits into from
Oct 8, 2020
11 changes: 11 additions & 0 deletions google/resource_google_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@ func resourceGoogleProjectCheckPreRequisites(config *Config, d *schema.ResourceD
if !stringInSlice(resp.Permissions, perm) {
return fmt.Errorf("missing permission on %q: %v", ba, perm)
}
errExpected := "googleapi: Error 403: Project '00000000000' not found or permission denied., forbidden"
thiagonache marked this conversation as resolved.
Show resolved Hide resolved
errAPINotEnabled := "accessNotConfigured"
thiagonache marked this conversation as resolved.
Show resolved Hide resolved
if !d.Get("auto_create_network").(bool) {
_, err := config.NewServiceUsageClient(userAgent).Services.Get("projects/00000000000/services/serviceusage.googleapis.com").Do()
switch {
case err.Error() == errExpected:
return nil
case strings.Contains(err.Error(), errAPINotEnabled):
return fmt.Errorf("API serviceusage not enabled.\nFound error: %v", err)
}
}
return nil
}

Expand Down