Skip to content

Commit 3521d5e

Browse files
nkraemer-sysdigNéstor SalcedaAlex
authored
feat: Initial cloud-bench implementation (#30)
* Initial cloud-bench implementation * rename viewer * Refactor to follow example structure * use locals * Simplify default regions * Simplify default regions * revert readme changes * Update main.tf * add GCP multiaccount example * add GCP multiaccount example * don't disable services on delete * reorganize singe-project to match org * support organizational cloud-bench Co-authored-by: Néstor Salceda <[email protected]> Co-authored-by: Alex <[email protected]>
1 parent c682701 commit 3521d5e

File tree

21 files changed

+353
-31
lines changed

21 files changed

+353
-31
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,16 @@ The following GCP APIs must be enabled to deply resources correctly
1616
> ##### APIs Required by Cloud Scanning
1717
>* Cloud Run API
1818
>* Eventarc API
19-
>* Secret Maanger API
19+
>* Secret Manger API
2020
>* Cloud Build API
2121
>* Identity and access management API
2222
23+
> ##### APIs Required by Cloud Benchmarks
24+
>* Identity and access management API
25+
>* IAM Service Account Credentials API
26+
>* Cloud Resource Manager API
27+
>* Security Token Service API
28+
2329
### Module Usage
2430

2531
```hcl

examples/organization/README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ This example deploys Cloud Connector into a GCP organizational GCP account.
1010
|------|---------|
1111
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 |
1212
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 3.67.0 |
13+
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 3.67.0 |
14+
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.21 |
1315

1416
## Providers
1517

@@ -21,11 +23,12 @@ This example deploys Cloud Connector into a GCP organizational GCP account.
2123

2224
| Name | Source | Version |
2325
|------|--------|---------|
24-
| <a name="module_cloud_connector"></a> [cloud\_connector](#module\_cloud\_connector) | ../../modules/services/cloud-connector | |
25-
| <a name="module_cloud_scanning"></a> [cloud\_scanning](#module\_cloud\_scanning) | ../../modules/services/cloud-scanning | |
26-
| <a name="module_connector_organization_sink"></a> [connector\_organization\_sink](#module\_connector\_organization\_sink) | ../../modules/infrastructure/organization_sink | |
27-
| <a name="module_scanning_organization_sink"></a> [scanning\_organization\_sink](#module\_scanning\_organization\_sink) | ../../modules/infrastructure/organization_sink | |
28-
| <a name="module_secure_secrets"></a> [secure\_secrets](#module\_secure\_secrets) | ../../modules/infrastructure/secrets | |
26+
| <a name="module_cloud_bench"></a> [cloud\_bench](#module\_cloud\_bench) | ../../modules/services/cloud-bench | n/a |
27+
| <a name="module_cloud_connector"></a> [cloud\_connector](#module\_cloud\_connector) | ../../modules/services/cloud-connector | n/a |
28+
| <a name="module_cloud_scanning"></a> [cloud\_scanning](#module\_cloud\_scanning) | ../../modules/services/cloud-scanning | n/a |
29+
| <a name="module_connector_organization_sink"></a> [connector\_organization\_sink](#module\_connector\_organization\_sink) | ../../modules/infrastructure/organization_sink | n/a |
30+
| <a name="module_scanning_organization_sink"></a> [scanning\_organization\_sink](#module\_scanning\_organization\_sink) | ../../modules/infrastructure/organization_sink | n/a |
31+
| <a name="module_secure_secrets"></a> [secure\_secrets](#module\_secure\_secrets) | ../../modules/infrastructure/secrets | n/a |
2932

3033
## Resources
3134

@@ -35,17 +38,20 @@ This example deploys Cloud Connector into a GCP organizational GCP account.
3538
| [google_organization_iam_member.organization_image_puller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_member) | resource |
3639
| [google_service_account.connector_sa](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
3740
| [google_service_account.scanning_sa](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
38-
| [google_project.project](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/project) | data source |
41+
| [google_organization.org](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/organization) | data source |
42+
| [google_projects.all_projects](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/projects) | data source |
3943

4044
## Inputs
4145

4246
| Name | Description | Type | Default | Required |
4347
|------|-------------|------|---------|:--------:|
48+
| <a name="input_benchmark_project_ids"></a> [benchmark\_project\_ids](#input\_benchmark\_project\_ids) | Google cloud project IDs to run Benchmarks on | `list(string)` | `[]` | no |
4449
| <a name="input_create_gcr_topic"></a> [create\_gcr\_topic](#input\_create\_gcr\_topic) | Deploys a PubSub topic called `gcr` as part of this stack, which is needed for GCR scanning. Set to `true` only if it doesn't exist yet. If this is not deployed, and no existing `gcr` topic is found, the GCR scanning is ommited and won't be deployed. For more info see [GCR PubSub topic](https://cloud.google.com/container-registry/docs/configuring-notifications#create_a_topic). | `bool` | `true` | no |
4550
| <a name="input_location"></a> [location](#input\_location) | Zone where the stack will be deployed | `string` | `"us-central1"` | no |
4651
| <a name="input_max_instances"></a> [max\_instances](#input\_max\_instances) | Max number of instances for the workloads | `number` | `1` | no |
4752
| <a name="input_naming_prefix"></a> [naming\_prefix](#input\_naming\_prefix) | Naming prefix for all the resources created | `string` | `"secure-for-cloud"` | no |
48-
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID | `string` | n/a | yes |
53+
| <a name="input_organization_domain"></a> [organization\_domain](#input\_organization\_domain) | Organization domain. e.g. sysdig.com | `string` | n/a | yes |
54+
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | organizational member project ID where the secure-for-cloud workload is going to be deployed | `string` | n/a | yes |
4955
| <a name="input_sysdig_secure_api_token"></a> [sysdig\_secure\_api\_token](#input\_sysdig\_secure\_api\_token) | Sysdig's Secure API Token | `string` | n/a | yes |
5056
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |
5157

examples/organization/main.tf

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,40 @@ EOT
99
}
1010

1111
provider "google" {
12-
project = var.project_id
13-
region = var.location
12+
region = var.location
1413
}
1514

16-
data "google_project" "project" {
17-
project_id = var.project_id
15+
provider "google-beta" {
16+
region = var.location
17+
}
18+
19+
provider "sysdig" {
20+
sysdig_secure_url = var.sysdig_secure_endpoint
21+
sysdig_secure_api_token = var.sysdig_secure_api_token
22+
sysdig_secure_insecure_tls = !local.verify_ssl
23+
}
24+
25+
data "google_organization" "org" {
26+
domain = var.organization_domain
27+
}
28+
29+
data "google_projects" "all_projects" {
30+
filter = "parent.id:${data.google_organization.org.org_id} parent.type:organization"
1831
}
1932

2033
#######################
2134
# CONNECTOR #
2235
#######################
2336
resource "google_service_account" "connector_sa" {
24-
account_id = "${var.naming_prefix}-cloud-connector"
37+
account_id = "${var.naming_prefix}-connector"
2538
display_name = "Service account for cloud-connector"
2639
}
2740

2841
module "connector_organization_sink" {
2942
source = "../../modules/infrastructure/organization_sink"
3043

31-
organization_id = data.google_project.project.org_id
32-
naming_prefix = "${var.naming_prefix}-cloud-connector"
44+
organization_id = data.google_organization.org.org_id
45+
naming_prefix = "${var.naming_prefix}-connector"
3346
filter = local.connector_filter
3447
}
3548

@@ -41,6 +54,7 @@ module "cloud_connector" {
4154
sysdig_secure_endpoint = var.sysdig_secure_endpoint
4255
connector_pubsub_topic_id = module.connector_organization_sink.pubsub_topic_id
4356
max_instances = var.max_instances
57+
project_id = var.project_id
4458

4559
#defaults
4660
naming_prefix = var.naming_prefix
@@ -51,13 +65,13 @@ module "cloud_connector" {
5165
# SCANNING #
5266
#######################
5367
resource "google_service_account" "scanning_sa" {
54-
account_id = "${var.naming_prefix}-cloud-scanning"
68+
account_id = "${var.naming_prefix}-scanning"
5569
display_name = "Service account for cloud-scanning"
5670
}
5771

5872

5973
resource "google_organization_iam_custom_role" "org_gcr_image_puller" {
60-
org_id = data.google_project.project.org_id
74+
org_id = data.google_organization.org.org_id
6175

6276
role_id = "${var.naming_prefix}_gcr_image_puller"
6377
title = "Sysdig GCR Image Puller"
@@ -66,7 +80,7 @@ resource "google_organization_iam_custom_role" "org_gcr_image_puller" {
6680
}
6781

6882
resource "google_organization_iam_member" "organization_image_puller" {
69-
org_id = data.google_project.project.org_id
83+
org_id = data.google_organization.org.org_id
7084

7185
role = google_organization_iam_custom_role.org_gcr_image_puller.id
7286
member = "serviceAccount:${google_service_account.scanning_sa.email}"
@@ -75,8 +89,8 @@ resource "google_organization_iam_member" "organization_image_puller" {
7589
module "scanning_organization_sink" {
7690
source = "../../modules/infrastructure/organization_sink"
7791

78-
organization_id = data.google_project.project.org_id
79-
naming_prefix = "${var.naming_prefix}-cloud-scanning"
92+
organization_id = data.google_organization.org.org_id
93+
naming_prefix = "${var.naming_prefix}-scanning"
8094
filter = local.scanning_filter
8195
}
8296

@@ -100,6 +114,21 @@ module "cloud_scanning" {
100114
cloud_scanning_sa_email = google_service_account.scanning_sa.email
101115
create_gcr_topic = var.create_gcr_topic
102116
scanning_pubsub_topic_id = module.connector_organization_sink.pubsub_topic_id
117+
project_id = var.project_id
103118

104119
max_instances = var.max_instances
105120
}
121+
122+
#######################
123+
# BENCHMARKS #
124+
#######################
125+
locals {
126+
benchmark_projects_ids = length(var.benchmark_project_ids) == 0 ? [for p in data.google_projects.all_projects.projects : p.project_id] : var.benchmark_project_ids
127+
}
128+
129+
module "cloud_bench" {
130+
for_each = toset(local.benchmark_projects_ids)
131+
source = "../../modules/services/cloud-bench"
132+
133+
project_id = each.key
134+
}

examples/organization/variables.tf

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ variable "sysdig_secure_api_token" {
44
description = "Sysdig's Secure API Token"
55
}
66

7+
variable "organization_domain" {
8+
type = string
9+
description = "Organization domain. e.g. sysdig.com"
10+
}
11+
712
variable "project_id" {
813
type = string
9-
description = "Project ID"
14+
description = "organizational member project ID where the secure-for-cloud workload is going to be deployed"
1015
}
1116

1217
# Vars with defaults
@@ -34,6 +39,12 @@ variable "max_instances" {
3439
default = 1
3540
}
3641

42+
variable "benchmark_project_ids" {
43+
default = []
44+
type = list(string)
45+
description = "Google cloud project IDs to run Benchmarks on"
46+
}
47+
3748
variable "create_gcr_topic" {
3849
type = bool
3950
description = "Deploys a PubSub topic called `gcr` as part of this stack, which is needed for GCR scanning. Set to `true` only if it doesn't exist yet. If this is not deployed, and no existing `gcr` topic is found, the GCR scanning is ommited and won't be deployed. For more info see [GCR PubSub topic](https://cloud.google.com/container-registry/docs/configuring-notifications#create_a_topic)."

examples/organization/versions.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 3.67.0"
88
}
9+
google-beta = {
10+
source = "hashicorp/google-beta"
11+
version = ">= 3.67.0"
12+
}
13+
sysdig = {
14+
source = "sysdiglabs/sysdig"
15+
version = ">= 0.5.21"
16+
}
917
}
1018
}

examples/single-project/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ This example deploys Cloud Connector and Cloud Scanning into a GCP account.
1111
|------|---------|
1212
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.14.0 |
1313
| <a name="requirement_google"></a> [google](#requirement\_google) | >= 3.67.0 |
14+
| <a name="requirement_google-beta"></a> [google-beta](#requirement\_google-beta) | >= 3.67.0 |
15+
| <a name="requirement_sysdig"></a> [sysdig](#requirement\_sysdig) | >= 0.5.21 |
1416

1517
## Providers
1618

@@ -22,11 +24,12 @@ This example deploys Cloud Connector and Cloud Scanning into a GCP account.
2224

2325
| Name | Source | Version |
2426
|------|--------|---------|
25-
| <a name="module_cloud_connector"></a> [cloud\_connector](#module\_cloud\_connector) | ../../modules/services/cloud-connector | |
26-
| <a name="module_cloud_scanning"></a> [cloud\_scanning](#module\_cloud\_scanning) | ../../modules/services/cloud-scanning | |
27-
| <a name="module_connector_project_sink"></a> [connector\_project\_sink](#module\_connector\_project\_sink) | ../../modules/infrastructure/project_sink | |
28-
| <a name="module_scanning_project_sink"></a> [scanning\_project\_sink](#module\_scanning\_project\_sink) | ../../modules/infrastructure/project_sink | |
29-
| <a name="module_secure_secrets"></a> [secure\_secrets](#module\_secure\_secrets) | ../../modules/infrastructure/secrets | |
27+
| <a name="module_cloud_bench"></a> [cloud\_bench](#module\_cloud\_bench) | ../../modules/services/cloud-bench | n/a |
28+
| <a name="module_cloud_connector"></a> [cloud\_connector](#module\_cloud\_connector) | ../../modules/services/cloud-connector | n/a |
29+
| <a name="module_cloud_scanning"></a> [cloud\_scanning](#module\_cloud\_scanning) | ../../modules/services/cloud-scanning | n/a |
30+
| <a name="module_connector_project_sink"></a> [connector\_project\_sink](#module\_connector\_project\_sink) | ../../modules/infrastructure/project_sink | n/a |
31+
| <a name="module_scanning_project_sink"></a> [scanning\_project\_sink](#module\_scanning\_project\_sink) | ../../modules/infrastructure/project_sink | n/a |
32+
| <a name="module_secure_secrets"></a> [secure\_secrets](#module\_secure\_secrets) | ../../modules/infrastructure/secrets | n/a |
3033

3134
## Resources
3235

examples/single-project/main.tf

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@ EOT
88
EOT
99
}
1010

11-
12-
#######################
13-
# CONNECTOR #
14-
#######################
1511
provider "google" {
1612
project = var.project_id
1713
region = var.location
1814
}
1915

16+
provider "google-beta" {
17+
project = var.project_id
18+
region = var.location
19+
}
20+
21+
provider "sysdig" {
22+
sysdig_secure_url = var.sysdig_secure_endpoint
23+
sysdig_secure_api_token = var.sysdig_secure_api_token
24+
sysdig_secure_insecure_tls = !local.verify_ssl
25+
}
26+
27+
#######################
28+
# CONNECTOR #
29+
#######################
2030
resource "google_service_account" "connector_sa" {
2131
account_id = "${var.naming_prefix}-cloud-connector"
2232
display_name = "Service account for cloud-connector"
@@ -37,6 +47,7 @@ module "cloud_connector" {
3747
sysdig_secure_api_token = var.sysdig_secure_api_token
3848
sysdig_secure_endpoint = var.sysdig_secure_endpoint
3949
connector_pubsub_topic_id = module.connector_project_sink.pubsub_topic_id
50+
project_id = var.project_id
4051

4152
#defaults
4253
naming_prefix = var.naming_prefix
@@ -47,7 +58,6 @@ module "cloud_connector" {
4758
#######################
4859
# SCANNING #
4960
#######################
50-
5161
resource "google_service_account" "scanning_sa" {
5262
account_id = "${var.naming_prefix}-cloud-scanning"
5363
display_name = "Service account for cloud-scanning"
@@ -74,6 +84,7 @@ module "cloud_scanning" {
7484
cloud_scanning_sa_email = google_service_account.scanning_sa.email
7585
scanning_pubsub_topic_id = module.scanning_project_sink.pubsub_topic_id
7686
create_gcr_topic = var.create_gcr_topic
87+
project_id = var.project_id
7788

7889
secure_api_token_secret_id = module.secure_secrets.secure_api_token_secret_name
7990
sysdig_secure_api_token = var.sysdig_secure_api_token
@@ -83,3 +94,11 @@ module "cloud_scanning" {
8394
naming_prefix = var.naming_prefix
8495
verify_ssl = local.verify_ssl
8596
}
97+
98+
99+
#######################
100+
# BENCHMARKS #
101+
#######################
102+
module "cloud_bench" {
103+
source = "../../modules/services/cloud-bench"
104+
}

examples/single-project/variables.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ variable "location" {
1515
default = "us-central1"
1616
description = "Zone where the stack will be deployed"
1717
}
18+
1819
variable "sysdig_secure_endpoint" {
1920
type = string
2021
default = "https://secure.sysdig.com"

examples/single-project/versions.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,13 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 3.67.0"
88
}
9+
google-beta = {
10+
source = "hashicorp/google-beta"
11+
version = ">= 3.67.0"
12+
}
13+
sysdig = {
14+
source = "sysdiglabs/sysdig"
15+
version = ">= 0.5.21"
16+
}
917
}
1018
}

0 commit comments

Comments
 (0)