Skip to content

Commit e533608

Browse files
Merge pull request #245 from DataDog/mohamed.challal/add-gcp-scan-options-providers
[K9VULN-8133] feat(gcp): create the scan options with the TF provider Co-authored-by: mohamed-challal <[email protected]>
2 parents 6bf41ce + 8b3ae27 commit e533608

File tree

8 files changed

+93
-2
lines changed

8 files changed

+93
-2
lines changed

gcp/examples/cross_project/README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,14 @@ Use this **advanced** deployment model when:
8181
1. **Review the deployment plan**. You will need to:
8282
- Set the project ID where the scanner will be deployed
8383
- Set your Datadog [API key](https://docs.datadoghq.com/account_management/api-app-keys/)
84+
- Set your Datadog [APP key](https://docs.datadoghq.com/account_management/api-app-keys/)
8485
- Set your Datadog site
8586

8687
```sh
8788
terraform plan \
8889
-var="scanner_project_id=my-scanner-project" \
8990
-var="datadog_api_key=$DD_API_KEY" \
91+
-var="datadog_app_key=$DD_APP_KEY" \
9092
-var="datadog_site=datadoghq.com"
9193
```
9294

@@ -95,6 +97,7 @@ Use this **advanced** deployment model when:
9597
terraform apply \
9698
-var="scanner_project_id=my-scanner-project" \
9799
-var="datadog_api_key=$DD_API_KEY" \
100+
-var="datadog_app_key=$DD_APP_KEY" \
98101
-var="datadog_site=datadoghq.com"
99102
```
100103

@@ -122,11 +125,17 @@ terraform init
122125
terraform plan \
123126
-var="scanned_project_id=my-other-project" \
124127
-var="scanner_service_account_email_us=$SCANNER_SA_US" \
125-
-var="scanner_service_account_email_eu=$SCANNER_SA_EU"
128+
-var="scanner_service_account_email_eu=$SCANNER_SA_EU" \
129+
-var="datadog_api_key=$DD_API_KEY" \
130+
-var="datadog_app_key=$DD_APP_KEY" \
131+
-var="datadog_site=datadoghq.com"
126132
terraform apply \
127133
-var="scanned_project_id=my-other-project" \
128134
-var="scanner_service_account_email_us=$SCANNER_SA_US" \
129-
-var="scanner_service_account_email_eu=$SCANNER_SA_EU"
135+
-var="scanner_service_account_email_eu=$SCANNER_SA_EU" \
136+
-var="datadog_api_key=$DD_API_KEY" \
137+
-var="datadog_app_key=$DD_APP_KEY" \
138+
-var="datadog_site=datadoghq.com"
130139
```
131140

132141
Repeat Step 2 for each additional project you want to scan.

gcp/examples/cross_project/other_project/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 5.0"
88
}
9+
datadog = {
10+
source = "DataDog/datadog"
11+
version = ">= 3.80.0"
12+
}
913
}
1014
}
1115

1216
provider "google" {
1317
project = var.scanned_project_id
1418
}
1519

20+
provider "datadog" {
21+
api_key = var.datadog_api_key
22+
app_key = var.datadog_app_key
23+
api_url = "https://api.${var.datadog_site}/"
24+
}
25+
26+
# Enable agentless scanning for this project
27+
resource "datadog_agentless_scanning_gcp_scan_options" "scanned_project" {
28+
gcp_project_id = var.scanned_project_id
29+
vuln_host_os = true
30+
vuln_containers_os = true
31+
}
32+
1633
# Create impersonated service accounts for each scanner service account (US and EU)
1734
# This allows both the US and EU scanners to scan resources in this project
1835

gcp/examples/cross_project/other_project/variables.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,20 @@ variable "scanner_service_account_email_eu" {
1212
description = "Email of the EU scanner service account from the scanner project (output from scanner_project deployment)"
1313
type = string
1414
}
15+
16+
variable "datadog_api_key" {
17+
description = "Datadog API key with Remote Configuration enabled"
18+
type = string
19+
sensitive = true
20+
}
21+
22+
variable "datadog_app_key" {
23+
description = "Datadog APP key needed to enable the product"
24+
type = string
25+
sensitive = true
26+
}
27+
28+
variable "datadog_site" {
29+
description = "The Datadog site of your organization where scanner data will be sent (for example, datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, ap1.datadoghq.com, ddog-gov.com). See https://docs.datadoghq.com/getting_started/site/"
30+
type = string
31+
}

gcp/examples/cross_project/scanner_project/main.tf

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 5.0"
88
}
9+
datadog = {
10+
source = "DataDog/datadog"
11+
version = ">= 3.80.0"
12+
}
913
}
1014
}
1115

@@ -21,6 +25,19 @@ provider "google" {
2125
alias = "eu"
2226
}
2327

28+
provider "datadog" {
29+
api_key = var.datadog_api_key
30+
app_key = var.datadog_app_key
31+
api_url = "https://api.${var.datadog_site}/"
32+
}
33+
34+
# Enable agentless scanning for the scanner project
35+
resource "datadog_agentless_scanning_gcp_scan_options" "scanner_project" {
36+
gcp_project_id = var.scanner_project_id
37+
vuln_host_os = true
38+
vuln_containers_os = true
39+
}
40+
2441
# Deploy the scanner infrastructure in US region
2542
module "datadog_agentless_scanner_us" {
2643
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp?ref=0.11.12"

gcp/examples/cross_project/scanner_project/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ variable "datadog_api_key" {
99
sensitive = true
1010
}
1111

12+
variable "datadog_app_key" {
13+
description = "Datadog APP key needed to enable the product"
14+
type = string
15+
sensitive = true
16+
}
17+
1218
variable "datadog_site" {
1319
description = "The Datadog site of your organization where scanner data will be sent (for example, datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, ap1.datadoghq.com, ddog-gov.com). See https://docs.datadoghq.com/getting_started/site/"
1420
type = string

gcp/examples/single_region/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ To deploy a Datadog agentless scanner:
3838
1. **Review the deployment plan**. You will need to:
3939
- Set your GCP project ID
4040
- Set your Datadog [API key](https://docs.datadoghq.com/account_management/api-app-keys/)
41+
- Set your Datadog [APP key](https://docs.datadoghq.com/account_management/api-app-keys/)
4142
- Set your Datadog site
4243

4344
```sh
4445
terraform plan \
4546
-var="project_id=my-gcp-project" \
4647
-var="datadog_api_key=$DD_API_KEY" \
48+
-var="datadog_app_key=$DD_APP_KEY" \
4749
-var="datadog_site=datadoghq.com"
4850
```
4951

@@ -52,6 +54,7 @@ To deploy a Datadog agentless scanner:
5254
terraform apply \
5355
-var="project_id=my-gcp-project" \
5456
-var="datadog_api_key=$DD_API_KEY" \
57+
-var="datadog_app_key=$DD_APP_KEY" \
5558
-var="datadog_site=datadoghq.com"
5659
```
5760

gcp/examples/single_region/main.tf

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ terraform {
66
source = "hashicorp/google"
77
version = ">= 5.0"
88
}
9+
datadog = {
10+
source = "DataDog/datadog"
11+
version = ">= 3.80.0"
12+
}
913
}
1014
}
1115

@@ -14,6 +18,18 @@ provider "google" {
1418
region = "us-central1"
1519
}
1620

21+
provider "datadog" {
22+
api_key = var.datadog_api_key
23+
app_key = var.datadog_app_key
24+
api_url = "https://api.${var.datadog_site}/"
25+
}
26+
27+
resource "datadog_agentless_scanning_gcp_scan_options" "scan_options" {
28+
gcp_project_id = var.project_id
29+
vuln_host_os = true
30+
vuln_containers_os = true
31+
}
32+
1733
module "datadog_agentless_scanner" {
1834
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp?ref=0.11.12"
1935

gcp/examples/single_region/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ variable "datadog_api_key" {
99
sensitive = true
1010
}
1111

12+
variable "datadog_app_key" {
13+
description = "Datadog APP key needed to enable the product"
14+
type = string
15+
sensitive = true
16+
}
17+
1218
variable "datadog_site" {
1319
description = "The Datadog site of your organization where scanner data will be sent (for example, datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, ap1.datadoghq.com, ddog-gov.com). See https://docs.datadoghq.com/getting_started/site/"
1420
type = string

0 commit comments

Comments
 (0)