Skip to content

Commit

Permalink
move deleted project check into project service read (#3350)
Browse files Browse the repository at this point in the history
* move deleted project check into project service read

* compile
  • Loading branch information
danawillow authored Apr 7, 2020
1 parent bbaa9fd commit 788a4d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
15 changes: 1 addition & 14 deletions third_party/terraform/resources/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
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

0 comments on commit 788a4d4

Please sign in to comment.