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 #3350

Merged
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
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