Skip to content

Commit f9de96f

Browse files
Merge pull request #241 from DataDog/mohamed.challal/release-gcp-support
[K9VULN-9413] bump(gcp): release gcp support (ref=0.11.12)
2 parents 2ad7826 + f35003a commit f9de96f

File tree

14 files changed

+147
-65
lines changed

14 files changed

+147
-65
lines changed

examples/cross_account/other_account/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ provider "aws" {
1414
}
1515

1616
module "delegate_role" {
17-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
17+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
1818

1919
scanner_roles = [var.scanner_role_arn]
2020
}

examples/cross_account/scanner_account/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ provider "aws" {
1414
}
1515

1616
module "scanner_role" {
17-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
17+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
1818

1919
## By default the scanner can assume any role with the default naming
2020
## convention from any account.
@@ -40,20 +40,20 @@ module "scanner_role" {
4040
}
4141

4242
module "self_delegate_role" {
43-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
43+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
4444

4545
scanner_roles = [module.scanner_role.role.arn]
4646
}
4747

4848
module "agentless_scanner" {
49-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
49+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
5050

5151
api_key = var.datadog_api_key
5252
site = var.datadog_site
5353
instance_profile_name = module.scanner_role.instance_profile.name
5454
}
5555

5656
module "autoscaling_scanners" {
57-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
57+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
5858
datadog_integration_role = var.datadog_integration_role
5959
}

examples/custom_agent_configurations/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ provider "aws" {
1414
}
1515

1616
module "scanner_role" {
17-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
17+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
1818

1919
api_key_secret_arns = [module.agentless_scanner.api_key_secret_arn]
2020
}
2121

2222
module "delegate_role" {
23-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
23+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
2424

2525
scanner_roles = [module.scanner_role.role.arn]
2626
}
2727

2828
module "agentless_scanner" {
29-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
29+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
3030

3131
api_key = var.api_key
3232
instance_profile_name = module.scanner_role.instance_profile.name
@@ -73,6 +73,6 @@ module "agentless_scanner" {
7373
}
7474

7575
module "autoscaling_scanners" {
76-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
76+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
7777
datadog_integration_role = var.datadog_integration_role
7878
}

examples/custom_vpc/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ provider "aws" {
1414
}
1515

1616
module "agentless_scanner_role" {
17-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
17+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
1818
}
1919

2020
module "delegate_role" {
21-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
21+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
2222

2323
scanner_roles = [module.agentless_scanner_role.role.arn]
2424
}
2525

2626
module "user_data" {
27-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/user_data?ref=0.11.11"
27+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/user_data?ref=0.11.12"
2828

2929
hostname = "agentless-scanning-us-east-1"
3030
api_key = var.api_key
3131
}
3232

3333
module "instance" {
34-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/instance?ref=0.11.11"
34+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/instance?ref=0.11.12"
3535

3636
user_data = module.user_data.install_sh
3737
iam_instance_profile = module.agentless_scanner_role.profile.name
@@ -40,6 +40,6 @@ module "instance" {
4040
}
4141

4242
module "autoscaling_scanners" {
43-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
43+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
4444
datadog_integration_role = var.datadog_integration_role
4545
}

examples/multi_region/main.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ provider "aws" {
2020
}
2121

2222
module "agentless_scanner_role" {
23-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
23+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
2424

2525
api_key_secret_arns = [
2626
module.agentless_scanner_us.api_key_secret_arn,
@@ -29,13 +29,13 @@ module "agentless_scanner_role" {
2929
}
3030

3131
module "delegate_role" {
32-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
32+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
3333

3434
scanner_roles = [module.agentless_scanner_role.role.arn]
3535
}
3636

3737
module "agentless_scanner_us" {
38-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
38+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
3939

4040
providers = {
4141
aws = aws.us
@@ -46,7 +46,7 @@ module "agentless_scanner_us" {
4646
}
4747

4848
module "agentless_scanner_eu" {
49-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
49+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
5050

5151
providers = {
5252
aws = aws.eu
@@ -57,6 +57,6 @@ module "agentless_scanner_eu" {
5757
}
5858

5959
module "autoscaling_scanners" {
60-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
60+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
6161
datadog_integration_role = var.datadog_integration_role
6262
}

examples/rds_scanning/main.tf

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ provider "aws" {
2020
}
2121

2222
module "agentless_scanner_role" {
23-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
23+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
2424

2525
account_roles = [module.delegate_role.role.arn]
2626
api_key_secret_arns = [
@@ -30,14 +30,14 @@ module "agentless_scanner_role" {
3030
}
3131

3232
module "delegate_role" {
33-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
33+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
3434

3535
scanner_roles = [module.agentless_scanner_role.role.arn]
3636
sensitive_data_scanning_rds_enabled = true
3737
}
3838

3939
module "agentless_scanner_us" {
40-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
40+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
4141

4242
providers = {
4343
aws = aws.us
@@ -48,7 +48,7 @@ module "agentless_scanner_us" {
4848
}
4949

5050
module "agentless_scanner_eu" {
51-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
51+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
5252

5353
providers = {
5454
aws = aws.eu
@@ -60,7 +60,7 @@ module "agentless_scanner_eu" {
6060

6161

6262
module "agentless_s3_bucket_us" {
63-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-s3-bucket?ref=0.11.11"
63+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-s3-bucket?ref=0.11.12"
6464

6565
iam_delegate_role_name = module.delegate_role.role.name
6666
iam_rds_assume_role_arn = module.agentless_scanner_us.role.arn
@@ -71,7 +71,7 @@ module "agentless_s3_bucket_us" {
7171
}
7272

7373
module "agentless_s3_bucket_eu" {
74-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-s3-bucket?ref=0.11.11"
74+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-s3-bucket?ref=0.11.12"
7575

7676
iam_delegate_role_name = module.delegate_role.role.name
7777
iam_rds_assume_role_arn = module.agentless_scanner_eu.role.arn
@@ -82,6 +82,6 @@ module "agentless_s3_bucket_eu" {
8282
}
8383

8484
module "autoscaling_scanners" {
85-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
85+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
8686
datadog_integration_role = var.datadog_integration_role
8787
}

examples/single_region/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ resource "datadog_agentless_scanning_aws_scan_options" "scan_options" {
3434
}
3535

3636
module "scanner_role" {
37-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.11"
37+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanner-role?ref=0.11.12"
3838

3939
api_key_secret_arns = [module.agentless_scanner.api_key_secret_arn]
4040
}
4141

4242
module "delegate_role" {
43-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.11"
43+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/scanning-delegate-role?ref=0.11.12"
4444

4545
scanner_roles = [module.scanner_role.role.arn]
4646
}
4747

4848
module "agentless_scanner" {
49-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.11"
49+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner?ref=0.11.12"
5050

5151
api_key = var.datadog_api_key
5252
site = var.datadog_site
5353
instance_profile_name = module.scanner_role.instance_profile.name
5454
}
5555

5656
module "autoscaling_scanners" {
57-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.11"
57+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//modules/agentless-scanners-autoscaling?ref=0.11.12"
5858
datadog_integration_role = var.datadog_integration_role
5959
}

gcp/README.md

Lines changed: 97 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Before using this module, make sure you have the following:
88

99
1. [Terraform](https://www.terraform.io/) v1.0 or later installed on your local machine.
1010
2. The [Google Cloud CLI](https://cloud.google.com/sdk/docs/install) installed on your local machine.
11-
3. GCP credentials configured (`gcloud auth login`) with the necessary permissions to create:
11+
3. GCP credentials configured with the necessary permissions to create:
1212
- VPC networks and subnets
1313
- Compute Engine instances and instance templates
1414
- Service accounts and IAM bindings
@@ -21,36 +21,115 @@ Before using this module, make sure you have the following:
2121

2222
## Usage
2323

24-
To use this module in your Terraform configuration, add the following code in your existing Terraform code:
24+
This is a quick example showing how to use this module. For more detailed examples with different deployment scenarios, refer to the [examples](./examples/) directory.
2525

2626
```hcl
27-
variable "datadog-api-key" {}
27+
variable "project_id" {
28+
description = "GCP project ID"
29+
type = string
30+
}
31+
32+
variable "datadog_api_key" {
33+
description = "Datadog API key with Remote Configuration enabled"
34+
type = string
35+
sensitive = true
36+
}
37+
38+
variable "datadog_site" {
39+
description = "Datadog site (e.g., datadoghq.com, datadoghq.eu, us3.datadoghq.com, us5.datadoghq.com, ap1.datadoghq.com, ap2.datadoghq.com, ddog-gov.com)"
40+
type = string
41+
}
42+
43+
provider "google" {
44+
project = var.project_id
45+
region = "us-central1"
46+
}
2847
29-
module "datadog-agentless-scanner" {
30-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp"
48+
module "datadog_agentless_scanner" {
49+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp?ref=0.11.12"
3150
32-
site = "datadoghq.com"
33-
vpc_name = "datadog-agentless-scanner"
34-
api_key = var.datadog-api-key
51+
site = var.datadog_site
52+
vpc_name = "datadog-agentless-scanner"
53+
api_key = var.datadog_api_key
3554
}
3655
```
3756

3857
And run:
3958
```sh
4059
terraform init
41-
export GOOGLE_PROJECT="your-project-id"
42-
export GOOGLE_REGION="us-central1"
43-
terraform apply -var="datadog-api-key=$DD_API_KEY"
60+
terraform apply \
61+
-var="project_id=<your-project-id>" \
62+
-var="datadog_api_key=$DD_API_KEY" \
63+
-var="datadog_site=<your-datadog-site>"
4464
```
4565

46-
### Notes
66+
> [!IMPORTANT]
67+
> Datadog strongly recommends [pinning](https://developer.hashicorp.com/terraform/language/modules/sources#selecting-a-revision) the version of the module to keep repeatable deployment and to avoid unexpected changes. Use a specific tag instead of a branch name.
68+
69+
### Configuration Notes
70+
71+
- **`site`**: Must match the Datadog site parameter of your account (see [Datadog site documentation](https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site)). Common values: `datadoghq.com`, `datadoghq.eu`, `us3.datadoghq.com`, `us5.datadoghq.com`, `ap1.datadoghq.com`, `ap2.datadoghq.com`, `ddog-gov.com`.
72+
- **`vpc_name`**: Name prefix for the VPC resources where the Agentless scanner is created. For security reasons, this VPC should be reserved for the exclusive use of the scanner.
73+
- **`api_key`**: The Datadog API key is stored in Google Secret Manager and accessed by the scanner instances. Alternatively, you can use `api_key_secret_id` to reference an existing secret.
74+
- **Service Accounts**: The module automatically creates two service accounts:
75+
- **Scanner Service Account**: Attached to the compute instances, with permissions to read secrets and impersonate the target service account.
76+
- **Impersonated Service Account**: Used for scanning resources, with read permissions on compute disks and snapshots.
77+
78+
## Examples
79+
80+
For complete examples, refer to the [examples](./examples/) directory:
81+
82+
### [Single Region](./examples/single_region/) - Simple Setup
83+
Deploy scanners in a single GCP region and project. **Ideal for single-project setups.**
84+
85+
- ✅ Simple deployment model
86+
- ✅ Single project, single region
87+
- ✅ Multi-zone high availability
88+
89+
### [Cross Project](./examples/cross_project/) - Advanced Setup
90+
Deploy scanners across multiple regions and scan multiple projects. **For enterprise deployments.**
91+
92+
- ✅ Multi-region deployment (US + EU by default, customizable)
93+
- ✅ Cross-project scanning capability
94+
- ✅ Minimized cross-region costs
95+
- ✅ Centralized management
96+
97+
Each example includes detailed README instructions and complete Terraform code. **Start with single_region** if you're new to Agentless scanning.
98+
99+
## Uninstall
100+
101+
To uninstall, remove the Agentless scanner module from your Terraform code. Removing this module deletes all resources associated with the Agentless scanner. Alternatively, if you used a separate Terraform state for this setup, you can uninstall the Agentless scanner by executing `terraform destroy`.
102+
103+
> [!WARNING]
104+
> Exercise caution when deleting Terraform resources. Review the plan carefully to ensure everything is in order. Note that some resources like Secret Manager secrets may have deletion protection enabled.
105+
106+
## Architecture
107+
108+
The Agentless Scanner deployment on GCP is split into different modules to allow for more flexibility and customization. The following modules are available:
109+
110+
- **[agentless-scanner-service-account](./modules/agentless-scanner-service-account/)**: Creates the service account that runs on the scanner compute instances. This service account has permissions to read the Datadog API key from Secret Manager and to impersonate the target service account.
111+
- **[agentless-impersonated-service-account](./modules/agentless-impersonated-service-account/)**: Creates the target service account that is impersonated by the scanner for accessing and scanning GCP resources. This service account has read permissions on compute disks and snapshots.
112+
- **[instance](./modules/instance/)**: Creates the Managed Instance Group (MIG) with compute instances that run the agentless scanner. The MIG provides auto-healing and distributes instances across multiple zones for high availability.
113+
- **[vpc](./modules/vpc/)**: Creates the VPC network, subnet, Cloud Router, Cloud NAT, and firewall rules required for the agentless scanner. The scanner runs in a private subnet with outbound internet access through Cloud NAT.
114+
115+
The main module provided in this directory is a wrapper around these modules with simplified inputs. It creates a complete, production-ready deployment of the Agentless scanner.
116+
117+
### Architecture Diagram
118+
119+
![GCP Agentless Scanner Architecture](./agentless_gcp_architecture.svg)
120+
121+
### How It Works
122+
123+
1. **Network Isolation**: The scanner runs in a dedicated VPC with private instances that have no external IP addresses. Outbound connectivity is provided through Cloud NAT.
124+
125+
2. **Service Account Impersonation**: The scanner uses GCP's service account impersonation feature:
126+
- The scanner service account (attached to instances) impersonates the target service account
127+
- The target service account has the necessary permissions to read and scan compute resources
128+
- This allows for fine-grained access control and cross-project scanning
129+
130+
3. **High Availability**: Instances are deployed in a regional Managed Instance Group distributed across multiple zones, with auto-healing enabled.
47131

48-
- `site` must match the Datadog site parameter of your account (see [this table](https://docs.datadoghq.com/getting_started/site/#access-the-datadog-site)).
49-
- `vpc_name` is the name prefix for the VPC resources where the Agentless scanner
50-
is created. For security reasons, this VPC should be reserved for
51-
the exclusive use of the scanner.
52-
- The scanner requires a service account with appropriate permissions to scan disks
53-
in your GCP project. This module creates the necessary service accounts and IAM roles.
132+
4. **Secure Credential Management**: The Datadog API key is stored in Google Secret Manager and accessed securely by the scanner instances.
54133

55134
<!-- BEGIN_TF_DOCS -->
56135
## Requirements

gcp/agentless_gcp_architecture.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)