Skip to content

Commit 5ae2c2f

Browse files
author
iru
authored
refactor!: remove provider (#74)
remove provider from examples added to example snippets
1 parent a9d4b42 commit 5ae2c2f

File tree

19 files changed

+95
-106
lines changed

19 files changed

+95
-106
lines changed

.pre-commit-config.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ repos:
88
args:
99
- '--args=--sort-by required'
1010
- id: terraform_tflint
11+
exclude: (test)|(examples-internal)\/.*$
1112
args:
1213
- '--args=--only=terraform_deprecated_interpolation'
1314
- '--args=--only=terraform_deprecated_index'

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ Notice that:
138138
A3: Do as the error says and activate CloudBuild API. Check the list of all the required APIs that need to be activated per feature module.
139139

140140

141-
<br/><br/>
141+
<br/><br/><br/>
142142
## Authors
143143

144144
Module is maintained and supported by [Sysdig](https://sysdig.com).

examples/organization/README.md

+14-12
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ Sysdig workload will be deployed in the `project_id` defined in the required inp
88

99
## Prerequisites
1010

11-
You **must** have following **roles** in your GCP organization/project credentials
12-
13-
* _Owner_
14-
* _Organization Admin_
15-
16-
Besides, the following GCP **APIs must be enabled** to deploy resources correctly for:
11+
1. Configure [Terraform **GCP** Provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs)
12+
2. Following **roles** are required in your GCP organization/project credentials
13+
* _Owner_
14+
* _Organization Admin_
15+
3. Besides, the following GCP **APIs must be enabled** to deploy resources correctly for:
1716

1817
### Cloud Connector
1918

@@ -42,13 +41,17 @@ Besides, the following GCP **APIs must be enabled** to deploy resources correctl
4241
For quick testing, use this snippet on your terraform files
4342

4443
```terraform
44+
provider "google" {
45+
project = "<PROJECT_ID>"
46+
region = "<REGION_ID>; ex. us-central-1"
47+
}
48+
4549
module "secure-for-cloud_example_organization" {
4650
source = "sysdiglabs/secure-for-cloud/google//examples/organization"
4751
48-
project_id = "your-project-id"
49-
repository_project_ids = ["project-to-scan-1", "project-to-scan-2"]
50-
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
51-
organization_domain = "your-domain.com"
52+
repository_project_ids = ["<PROJECT_SCAN_ID1>", "<PROJECT_SCAN_ID2>"]
53+
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
54+
organization_domain = "<ORG_DOMAIN>"
5255
}
5356
```
5457

@@ -85,6 +88,7 @@ module "secure-for-cloud_example_organization" {
8588
| [google_organization_iam_custom_role.org_gcr_image_puller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_custom_role) | resource |
8689
| [google_organization_iam_member.organization_image_puller](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/organization_iam_member) | resource |
8790
| [google_service_account.connector_sa](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
91+
| [google_client_config.current](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source |
8892
| [google_organization.org](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/organization) | data source |
8993
| [google_projects.all_projects](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/projects) | data source |
9094

@@ -93,13 +97,11 @@ module "secure-for-cloud_example_organization" {
9397
| Name | Description | Type | Default | Required |
9498
|------|-------------|------|---------|:--------:|
9599
| <a name="input_organization_domain"></a> [organization\_domain](#input\_organization\_domain) | Organization domain. e.g. sysdig.com | `string` | n/a | yes |
96-
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Organization member project ID where the secure-for-cloud workload is going to be deployed | `string` | n/a | yes |
97100
| <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 |
98101
| <a name="input_benchmark_project_ids"></a> [benchmark\_project\_ids](#input\_benchmark\_project\_ids) | Google cloud project IDs to run Benchmarks on. If empty, all organization projects will be defaulted. | `list(string)` | `[]` | no |
99102
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all regions by default. | `list(string)` | `[]` | no |
100103
| <a name="input_benchmark_role_name"></a> [benchmark\_role\_name](#input\_benchmark\_role\_name) | The name of the Service Account that will be created. | `string` | `"sysdigcloudbench"` | no |
101104
| <a name="input_deploy_bench"></a> [deploy\_bench](#input\_deploy\_bench) | whether benchmark module is to be deployed | `bool` | `true` | no |
102-
| <a name="input_location"></a> [location](#input\_location) | Zone where the stack will be deployed | `string` | `"us-central1"` | no |
103105
| <a name="input_max_instances"></a> [max\_instances](#input\_max\_instances) | Max number of instances for the workloads | `number` | `1` | no |
104106
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
105107
| <a name="input_repository_project_ids"></a> [repository\_project\_ids](#input\_repository\_project\_ids) | Projects were a `gcr`-named topic will be to subscribe to its repository events. If empty, all organization projects will be defaulted. | `list(string)` | `[]` | no |

examples/organization/data.tf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data "google_client_config" "current" {
2+
}

examples/organization/main.tf

+4-11
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,18 @@ EOT
66
repository_project_ids = length(var.repository_project_ids) == 0 ? [for p in data.google_projects.all_projects.projects : p.project_id] : var.repository_project_ids
77
}
88

9-
# This provider is project specific, and can only be used to provision resources in the
10-
# specified project. Primarily used for Cloud Connector and Cloud Scanning
11-
provider "google" {
12-
project = var.project_id
13-
region = var.location
14-
}
15-
169
# This provider is project agnostic, and can be used to provision resources in any project,
1710
# provided the project is specified on the resource. Primarily used for Benchmarks
1811
provider "google" {
1912
alias = "multiproject"
20-
region = var.location
13+
region = data.google_client_config.current.region
2114
}
2215

2316
# This provider is project agnostic, and can be used to provision resources in any project,
2417
# provided the project is specified on the resource. Primarily used for Benchmarks
2518
provider "google-beta" {
2619
alias = "multiproject"
27-
region = var.location
20+
region = data.google_client_config.current.region
2821
}
2922

3023
provider "sysdig" {
@@ -98,7 +91,7 @@ module "cloud_connector" {
9891
connector_pubsub_topic_id = module.connector_organization_sink.pubsub_topic_id
9992
secure_api_token_secret_id = module.secure_secrets.secure_api_token_secret_name
10093
max_instances = var.max_instances
101-
project_id = var.project_id
94+
project_id = data.google_client_config.current.project
10295

10396
#defaults
10497
name = "${var.name}-cloudconnector"
@@ -110,7 +103,7 @@ module "pubsub_http_subscription" {
110103
source = "../../modules/infrastructure/pubsub_push_http_subscription"
111104

112105
topic_project_id = each.key
113-
subscription_project_id = var.project_id
106+
subscription_project_id = data.google_client_config.current.project
114107
topic_name = "gcr"
115108
name = "${var.name}-gcr"
116109
service_account_email = google_service_account.connector_sa.email

examples/organization/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,9 @@ variable "organization_domain" {
99
description = "Organization domain. e.g. sysdig.com"
1010
}
1111

12-
variable "project_id" {
13-
type = string
14-
description = "Organization member project ID where the secure-for-cloud workload is going to be deployed"
15-
}
16-
1712
# --------------------------
1813
# optionals, with defaults
1914
# --------------------------
20-
variable "location" {
21-
type = string
22-
default = "us-central1"
23-
description = "Zone where the stack will be deployed"
24-
}
25-
2615
variable "sysdig_secure_endpoint" {
2716
type = string
2817
default = "https://secure.sysdig.com"

examples/single-project-k8s/README.md

+14-6
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ All the required resources and workloads will be run under the same GCP project.
1414

1515
Minimum requirements:
1616

17-
1. **GCP** profile credentials configuration
18-
2. **Kubernetes** cluster configured within your helm provider
17+
1. Configure [Terraform **GCP** Provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs)
18+
2. Configure [**Helm** Provider](https://registry.terraform.io/providers/hashicorp/helm/latest/docs) for **Kubernetes** cluster
1919
3. **Sysdig** Secure requirements, as input variable value
2020
```
2121
sysdig_secure_api_token=<SECURE_API_TOKEN>
@@ -26,11 +26,20 @@ Minimum requirements:
2626
For quick testing, use this snippet on your terraform files
2727
2828
```terraform
29+
provider "google" {
30+
project = "<PROJECT_ID>"
31+
region = "<REGION_ID>; ex. us-central-1"
32+
}
33+
34+
provider "helm" {
35+
kubernetes {
36+
config_path = "~/.kube/config"
37+
}
38+
}
39+
2940
module "secure_for_cloud_gcp_single_project_k8s" {
3041
source = "sysdiglabs/secure-for-cloud/google//examples/single-project-k8s"
31-
3242
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
33-
project_id = "your-project-id"
3443
}
3544
```
3645

@@ -73,15 +82,14 @@ Notice that:
7382
| [google_service_account.connector_sa](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
7483
| [google_service_account_key.connector_sa_key](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account_key) | resource |
7584
| [helm_release.cloud_connector](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource |
85+
| [google_client_config.current](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source |
7686

7787
## Inputs
7888

7989
| Name | Description | Type | Default | Required |
8090
|------|-------------|------|---------|:--------:|
81-
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID where the secure-for-cloud workload is going to be deployed | `string` | n/a | yes |
8291
| <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 |
8392
| <a name="input_cloud_connector_image"></a> [cloud\_connector\_image](#input\_cloud\_connector\_image) | Cloud-connector image to deploy | `string` | `"quay.io/sysdig/cloud-connector"` | no |
84-
| <a name="input_location"></a> [location](#input\_location) | Zone where the stack will be deployed | `string` | `"us-central1"` | no |
8593
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
8694
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |
8795

examples/single-project-k8s/cloud-connector.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ resource "helm_release" "cloud_connector" {
6565
rules: []
6666
ingestors:
6767
- gcp-auditlog-pubsub:
68-
project: ${var.project_id}
68+
project: ${data.google_client_config.current.project}
6969
subscription: ${google_pubsub_subscription.subscription.name}
7070
notifiers: []
7171
gcpCredentials: |

examples/single-project-k8s/data.tf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data "google_client_config" "current" {
2+
}

examples/single-project-k8s/main.tf

+1-13
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
11
locals {
22
verify_ssl = length(regexall("^https://.*?\\.sysdig.com/?", var.sysdig_secure_endpoint)) != 0
33
connector_filter = <<EOT
4-
logName=~"^projects/${var.project_id}/logs/cloudaudit.googleapis.com" AND -resource.type="k8s_cluster"
4+
logName=~"^projects/${data.google_client_config.current.project}/logs/cloudaudit.googleapis.com" AND -resource.type="k8s_cluster"
55
EOT
66
}
7-
8-
provider "google" {
9-
project = var.project_id
10-
region = var.location
11-
}
12-
13-
# TODO review ways to pass content as input var
14-
provider "helm" {
15-
kubernetes {
16-
config_path = "~/.kube/config"
17-
}
18-
}

examples/single-project-k8s/variables.tf

+1-12
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,9 @@ variable "sysdig_secure_api_token" {
44
description = "Sysdig's Secure API Token"
55
}
66

7-
variable "project_id" {
8-
type = string
9-
description = "Project ID where the secure-for-cloud workload is going to be deployed"
10-
}
11-
127
# --------------------------
138
# optionals, with defaults
14-
# --------------------------
15-
variable "location" {
16-
type = string
17-
default = "us-central1"
18-
description = "Zone where the stack will be deployed"
19-
}
20-
9+
# -------------------------
2110
variable "sysdig_secure_endpoint" {
2211
type = string
2312
default = "https://secure.sysdig.com"

examples/single-project/README.md

+15-9
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ All the resources will be run in a single project.
77

88
## Prerequisites
99

10-
You **must** have following **roles** in your GCP organization/project credentials
11-
* _Owner_
12-
13-
Besides, the following GCP **APIs must be enabled** to deploy resources correctly for:
10+
1. Configure [Terraform **GCP** Provider](https://registry.terraform.io/providers/hashicorp/google/latest/docs)
11+
1. Following **roles** are required in your GCP organization/project credentials
12+
* _Owner_
13+
1. Besides, the following GCP **APIs must be enabled** to deploy resources correctly for:
1414

1515
### Cloud Connector
1616
* [Cloud Pub/Sub API](https://console.cloud.google.com/marketplace/product/google/pubsub.googleapis.com)
@@ -37,12 +37,19 @@ Besides, the following GCP **APIs must be enabled** to deploy resources correctl
3737
For quick testing, use this snippet on your terraform files
3838

3939
```terraform
40-
module "secure-for-cloud_example_single-project" {
41-
source = "sysdiglabs/secure-for-cloud/google//examples/single-project"
40+
provider "google" {
41+
project = "<PROJECT_ID>"
42+
region = "<REGION_ID>; ex. us-central-1"
43+
}
4244
45+
provider "google-beta" {
46+
project = "<PROJECT_ID>"
47+
region = "<REGION_ID>; ex. us-central-1"
48+
}
4349
50+
module "secure-for-cloud_example_single-project" {
51+
source = "sysdiglabs/secure-for-cloud/google//examples/single-project"
4452
sysdig_secure_api_token = "00000000-1111-2222-3333-444444444444"
45-
project_id = "your-project-id"
4653
}
4754
```
4855

@@ -77,17 +84,16 @@ module "secure-for-cloud_example_single-project" {
7784
| Name | Type |
7885
|------|------|
7986
| [google_service_account.connector_sa](https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/service_account) | resource |
87+
| [google_client_config.current](https://registry.terraform.io/providers/hashicorp/google/latest/docs/data-sources/client_config) | data source |
8088

8189
## Inputs
8290

8391
| Name | Description | Type | Default | Required |
8492
|------|-------------|------|---------|:--------:|
85-
| <a name="input_project_id"></a> [project\_id](#input\_project\_id) | Project ID where the secure-for-cloud workload is going to be deployed | `string` | n/a | yes |
8693
| <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 |
8794
| <a name="input_benchmark_regions"></a> [benchmark\_regions](#input\_benchmark\_regions) | List of regions in which to run the benchmark. If empty, the task will contain all regions by default. | `list(string)` | `[]` | no |
8895
| <a name="input_benchmark_role_name"></a> [benchmark\_role\_name](#input\_benchmark\_role\_name) | The name of the Service Account that will be created. | `string` | `"sysdigcloudbench"` | no |
8996
| <a name="input_deploy_bench"></a> [deploy\_bench](#input\_deploy\_bench) | whether benchmark module is to be deployed | `bool` | `true` | no |
90-
| <a name="input_location"></a> [location](#input\_location) | Zone where the stack will be deployed | `string` | `"us-central1"` | no |
9197
| <a name="input_name"></a> [name](#input\_name) | Name to be assigned to all child resources. A suffix may be added internally when required. Use default value unless you need to install multiple instances | `string` | `"sfc"` | no |
9298
| <a name="input_sysdig_secure_endpoint"></a> [sysdig\_secure\_endpoint](#input\_sysdig\_secure\_endpoint) | Sysdig Secure API endpoint | `string` | `"https://secure.sysdig.com"` | no |
9399

examples/single-project/data.tf

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
data "google_client_config" "current" {
2+
}

examples/single-project/main.tf

+5-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
provider "google" {
2-
project = var.project_id
3-
region = var.location
4-
}
5-
6-
provider "google-beta" {
7-
project = var.project_id
8-
region = var.location
9-
}
10-
111
provider "sysdig" {
122
sysdig_secure_url = var.sysdig_secure_endpoint
133
sysdig_secure_api_token = var.sysdig_secure_api_token
@@ -17,7 +7,7 @@ provider "sysdig" {
177
locals {
188
verify_ssl = length(regexall("^https://.*?\\.sysdig.com/?", var.sysdig_secure_endpoint)) != 0
199
connector_filter = <<EOT
20-
logName=~"^projects/${var.project_id}/logs/cloudaudit.googleapis.com" AND -resource.type="k8s_cluster"
10+
logName=~"^projects/${data.google_client_config.current.project}/logs/cloudaudit.googleapis.com" AND -resource.type="k8s_cluster"
2111
EOT
2212
}
2313

@@ -55,7 +45,7 @@ module "cloud_connector" {
5545
sysdig_secure_endpoint = var.sysdig_secure_endpoint
5646
connector_pubsub_topic_id = module.connector_project_sink.pubsub_topic_id
5747
secure_api_token_secret_id = module.secure_secrets.secure_api_token_secret_name
58-
project_id = var.project_id
48+
project_id = data.google_client_config.current.project
5949

6050
#defaults
6151
verify_ssl = local.verify_ssl
@@ -64,8 +54,8 @@ module "cloud_connector" {
6454
module "pubsub_http_subscription" {
6555
source = "../../modules/infrastructure/pubsub_push_http_subscription"
6656

67-
topic_project_id = var.project_id
68-
subscription_project_id = var.project_id
57+
topic_project_id = data.google_client_config.current.project
58+
subscription_project_id = data.google_client_config.current.project
6959
topic_name = "gcr"
7060
name = "${var.name}-gcr"
7161
service_account_email = google_service_account.connector_sa.email
@@ -82,6 +72,6 @@ module "cloud_bench" {
8272

8373
is_organizational = false
8474
role_name = var.benchmark_role_name
85-
project_id = var.project_id
75+
project_id = data.google_client_config.current.project
8676
regions = var.benchmark_regions
8777
}

examples/single-project/variables.tf

-11
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,9 @@ variable "sysdig_secure_api_token" {
44
description = "Sysdig's Secure API Token"
55
}
66

7-
variable "project_id" {
8-
type = string
9-
description = "Project ID where the secure-for-cloud workload is going to be deployed"
10-
}
11-
127
# --------------------------
138
# optionals, with defaults
149
# --------------------------
15-
variable "location" {
16-
type = string
17-
default = "us-central1"
18-
description = "Zone where the stack will be deployed"
19-
}
20-
2110
variable "sysdig_secure_endpoint" {
2211
type = string
2312
default = "https://secure.sysdig.com"

0 commit comments

Comments
 (0)