Skip to content

Commit

Permalink
Add table gcp_cloud_run_service Closes #479 (#497)
Browse files Browse the repository at this point in the history
  • Loading branch information
ParthaI authored Oct 4, 2023
1 parent 423b10e commit a759191
Show file tree
Hide file tree
Showing 4 changed files with 539 additions and 1 deletion.
134 changes: 134 additions & 0 deletions docs/tables/gcp_cloud_run_service.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
# Table: gcp_cloud_run_service

Google Cloud Run is a fully managed compute platform offered by Google Cloud Platform (GCP) that is designed for running containerized applications. It allows developers to deploy containerized applications quickly and easily without having to manage the underlying infrastructure. Cloud Run abstracts away many of the complexities of managing servers and scaling applications, making it an excellent choice for building and deploying microservices, APIs, web applications, and more.

## Examples

### Basic info

```sql
select
name,
description,
client,
client_version,
create_time,
creator,
generation,
launch_stage
from
gcp_cloud_run_service;
```

### Count of services by launch stage

```sql
select
launch_stage,
count(*)
from
gcp_cloud_run_service
group by
launch_stage;
```

### List cloud-run services that are reconciling

```sql
select
name,
description,
client,
client_version,
create_time,
creator,
generation,
launch_stage,
reconciling
from
gcp_cloud_run_service
where
reconciling;
```

### List services created in the last 30 days

```sql
select
name,
description,
create_time,
creator,
launch_stage
from
gcp_cloud_run_service
where
create_time >= now() - interval '30' day;
```

### List services of ingress type INGRESS_TRAFFIC_ALL

```sql
select
name,
description,
client,
client_version,
create_time,
ingress
from
gcp_cloud_run_service
where
ingress = 'INGRESS_TRAFFIC_ALL';
```

### Get condition details of services

```sql
select
name,
c ->> 'ExecutionReason' as execution_reason,
c ->> 'LastTransitionTime' as last_transition_time,
c ->> 'Message' as message,
c ->> 'Reason' as reason,
c ->> 'RevisionReason' as revision_reason,
c ->> 'State' as state,
c ->> 'Type' as type
from
gcp_cloud_run_service,
jsonb_array_elements(conditions) as c;
```

### Get template details of services

```sql
select
name,
template ->> 'Annotations' as template_annotations,
template ->> 'Containers' as containers,
template ->> 'EncryptionKey' as encryption_key,
template ->> 'ExecutionEnvironment' as execution_environment,
template ->> 'Revision' as revision,
template ->> 'Scaling' as scaling,
template ->> 'ServiceAccount' as service_account,
template ->> 'SessionAffinity' as session_affinity,
template ->> 'Timeout' as timeout,
template ->> 'Volumes' as volumes,
template ->> 'VpcAccess' as vpc_access
from
gcp_cloud_run_service;
```

### Get target traffic details of services

```sql
select
name,
t ->> 'Percent' as percent,
t ->> 'Revision' as revision,
t ->> 'Tag' as tag,
t ->> 'Type' as type
from
gcp_cloud_run_service,
jsonb_array_elements(traffic) as t;
```
1 change: 1 addition & 0 deletions gcp/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func Plugin(ctx context.Context) *plugin.Plugin {
"gcp_cloud_identity_group": tableGcpCloudIdentityGroup(ctx),
"gcp_cloud_identity_group_membership": tableGcpCloudIdentityGroupMembership(ctx),
"gcp_cloudfunctions_function": tableGcpCloudfunctionFunction(ctx),
"gcp_cloud_run_service": tableGcpCloudRunService(ctx),
"gcp_compute_address": tableGcpComputeAddress(ctx),
"gcp_compute_autoscaler": tableGcpComputeAutoscaler(ctx),
"gcp_compute_backend_bucket": tableGcpComputeBackendBucket(ctx),
Expand Down
24 changes: 23 additions & 1 deletion gcp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gcp
import (
"context"

redis "cloud.google.com/go/redis/apiv1"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"google.golang.org/api/accessapproval/v1"
"google.golang.org/api/apikeys/v2"
Expand All @@ -23,7 +24,7 @@ import (
"google.golang.org/api/logging/v2"
"google.golang.org/api/monitoring/v3"
"google.golang.org/api/pubsub/v1"
"cloud.google.com/go/redis/apiv1"
"google.golang.org/api/run/v2"
"google.golang.org/api/serviceusage/v1"
"google.golang.org/api/storage/v1"

Expand Down Expand Up @@ -177,6 +178,27 @@ func CloudResourceManagerService(ctx context.Context, d *plugin.QueryData) (*clo
return svc, nil
}

// CloudRunService returns the service connection for GCP Cloud Run service
func CloudRunService(ctx context.Context, d *plugin.QueryData) (*run.Service, error) {
// have we already created and cached the service?
serviceCacheKey := "CloudRunService"
if cachedData, ok := d.ConnectionManager.Cache.Get(serviceCacheKey); ok {
return cachedData.(*run.Service), nil
}

// To get config arguments from plugin config file
opts := setSessionConfig(ctx, d.Connection)

// so it was not in cache - create service
svc, err := run.NewService(ctx, opts...)
if err != nil {
return nil, err
}

d.ConnectionManager.Cache.Set(serviceCacheKey, svc)
return svc, nil
}

// EssentialContactService returns the service connection for GCP Cloud Organization Essential Contacts
func EssentialContactService(ctx context.Context, d *plugin.QueryData) (*essentialcontacts.Service, error) {
// have we already created and cached the service?
Expand Down
Loading

0 comments on commit a759191

Please sign in to comment.