diff --git a/third_party/terraform/resources/resource_google_project.go b/third_party/terraform/resources/resource_google_project.go index f1434177a198..5bf38d717e17 100644 --- a/third_party/terraform/resources/resource_google_project.go +++ b/third_party/terraform/resources/resource_google_project.go @@ -573,22 +573,9 @@ func doEnableServicesRequest(services []string, project string, config *Config, // forms of the service. LIST responses are expected to return only the old or // new form, but we'll always return both. func listCurrentlyEnabledServices(project string, config *Config, timeout time.Duration) (map[string]struct{}, error) { - // Verify project for services still exists - p, err := config.clientResourceManager.Projects.Get(project).Do() - if err != nil { - return nil, err - } - if p.LifecycleState == "DELETE_REQUESTED" { - // Construct a 404 error for handleNotFoundError - return nil, &googleapi.Error{ - Code: 404, - Message: "Project deletion was requested", - } - } - log.Printf("[DEBUG] Listing enabled services for project %s", project) apiServices := make(map[string]struct{}) - err = retryTimeDuration(func() error { + err := retryTimeDuration(func() error { ctx := context.Background() return config.clientServiceUsage.Services. List(fmt.Sprintf("projects/%s", project)). diff --git a/third_party/terraform/resources/resource_google_project_service.go b/third_party/terraform/resources/resource_google_project_service.go index d015200f4c2e..8b1589d166cd 100644 --- a/third_party/terraform/resources/resource_google_project_service.go +++ b/third_party/terraform/resources/resource_google_project_service.go @@ -7,6 +7,7 @@ import ( "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "google.golang.org/api/googleapi" "google.golang.org/api/serviceusage/v1" ) @@ -154,7 +155,19 @@ func resourceGoogleProjectServiceRead(d *schema.ResourceData, meta interface{}) if err != nil { return err } - srv := d.Get("service").(string) + + // Verify project for services still exists + p, err := config.clientResourceManager.Projects.Get(project).Do() + if err != nil { + return err + } + if p.LifecycleState == "DELETE_REQUESTED" { + // Construct a 404 error for handleNotFoundError + return &googleapi.Error{ + Code: 404, + Message: "Project deletion was requested", + } + } servicesRaw, err := BatchRequestReadServices(project, d, config) if err != nil { @@ -162,6 +175,7 @@ func resourceGoogleProjectServiceRead(d *schema.ResourceData, meta interface{}) } servicesList := servicesRaw.(map[string]struct{}) + srv := d.Get("service").(string) if _, ok := servicesList[srv]; ok { d.Set("project", project) d.Set("service", srv)