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

move deleted project check into project service read #1937

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/3350.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
* serviceusage: fixed issue where `google_project_services` attempted to read a project before enabling the API that allows that read
```
15 changes: 1 addition & 14 deletions google-beta/resource_google_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)).
Expand Down
16 changes: 15 additions & 1 deletion google-beta/resource_google_project_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -154,14 +155,27 @@ 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 {
return handleNotFoundError(err, d, fmt.Sprintf("Project Service %s", d.Id()))
}
servicesList := servicesRaw.(map[string]struct{})

srv := d.Get("service").(string)
if _, ok := servicesList[srv]; ok {
d.Set("project", project)
d.Set("service", srv)
Expand Down