Skip to content

Commit

Permalink
Delete google_project_services in 3.0.0. (#2403)
Browse files Browse the repository at this point in the history
  • Loading branch information
nat-henderson authored and slevenick committed Nov 12, 2019
1 parent db1907b commit 0b611e7
Show file tree
Hide file tree
Showing 16 changed files with 99 additions and 977 deletions.

This file was deleted.

8 changes: 4 additions & 4 deletions third_party/terraform/resources/resource_cloudiot_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ func resourceCloudIoTRegistry() *schema.Resource {
Removed: "Please use event_notification_configs instead",
},
"event_notification_configs": {
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 10,
Type: schema.TypeList,
Optional: true,
Computed: true,
MaxItems: 10,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"pubsub_topic_name": {
Expand Down
72 changes: 72 additions & 0 deletions third_party/terraform/resources/resource_google_project.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package google

import (
"context"
"fmt"
"log"
"regexp"
Expand All @@ -13,6 +14,7 @@ import (
"google.golang.org/api/cloudbilling/v1"
"google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/googleapi"
"google.golang.org/api/serviceusage/v1"
)

// resourceGoogleProject returns a *schema.Resource that allows a customer
Expand Down Expand Up @@ -492,6 +494,76 @@ func enableServiceUsageProjectServices(services []string, project string, config
return waitForServiceUsageEnabledServices(services, project, config, timeout)
}

func doEnableServicesRequest(services []string, project string, config *Config, timeout time.Duration) error {
var op *serviceusage.Operation

err := retryTimeDuration(func() error {
var rerr error
if len(services) == 1 {
// BatchEnable returns an error for a single item, so just enable
// using service endpoint.
name := fmt.Sprintf("projects/%s/services/%s", project, services[0])
req := &serviceusage.EnableServiceRequest{}
op, rerr = config.clientServiceUsage.Services.Enable(name, req).Do()
} else {
// Batch enable for multiple services.
name := fmt.Sprintf("projects/%s", project)
req := &serviceusage.BatchEnableServicesRequest{ServiceIds: services}
op, rerr = config.clientServiceUsage.Services.BatchEnable(name, req).Do()
}
return handleServiceUsageRetryableError(rerr)
}, timeout)
if err != nil {
return errwrap.Wrapf("failed to send enable services request: {{err}}", err)
}
// Poll for the API to return
waitErr := serviceUsageOperationWait(config, op, fmt.Sprintf("Enable Project %q Services: %+v", project, services))
if waitErr != nil {
return waitErr
}
return nil
}

// Retrieve a project's services from the API
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 {
ctx := context.Background()
return config.clientServiceUsage.Services.
List(fmt.Sprintf("projects/%s", project)).
Fields("services/name,nextPageToken").
Filter("state:ENABLED").
Pages(ctx, func(r *serviceusage.ListServicesResponse) error {
for _, v := range r.Services {
// services are returned as "projects/PROJECT/services/NAME"
name := GetResourceNameFromSelfLink(v.Name)
if _, ok := ignoredProjectServicesSet[name]; !ok {
apiServices[name] = struct{}{}
}
}
return nil
})
}, timeout)
if err != nil {
return nil, errwrap.Wrapf(fmt.Sprintf("Failed to list enabled services for project %s: {{err}}", project), err)
}
return apiServices, nil
}

// waitForServiceUsageEnabledServices doesn't resend enable requests - it just
// waits for service enablement status to propagate. Essentially, it waits until
// all services show up as enabled when listing services on the project.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var renamedServicesByNewServiceNames = reverseStringMap(renamedServices)
// renamedServices expressed as both old -> new and new -> old
var renamedServicesByOldAndNewServiceNames = mergeStringMaps(renamedServices, renamedServicesByNewServiceNames)

const maxServiceUsageBatchSize = 20

func resourceGoogleProjectService() *schema.Resource {
return &schema.Resource{
Create: resourceGoogleProjectServiceCreate,
Expand Down
Loading

0 comments on commit 0b611e7

Please sign in to comment.