Skip to content

Commit 56efe46

Browse files
docs(gcp): update the main readme file
1 parent 667f165 commit 56efe46

File tree

2 files changed

+130
-18
lines changed

2 files changed

+130
-18
lines changed

gcp/README.md

Lines changed: 129 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,147 @@ 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+
}
2831
29-
module "datadog-agentless-scanner" {
30-
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp"
32+
variable "datadog_api_key" {
33+
description = "Datadog API key with Remote Configuration enabled"
34+
type = string
35+
sensitive = true
36+
}
3137
32-
site = "datadoghq.com"
33-
vpc_name = "datadog-agentless-scanner"
34-
api_key = var.datadog-api-key
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+
}
47+
48+
module "datadog_agentless_scanner" {
49+
source = "git::https://github.com/DataDog/terraform-module-datadog-agentless-scanner//gcp?ref=<COMMIT_HASH>"
50+
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+
The diagram above shows a typical deployment where:
122+
- The scanner infrastructure runs in a dedicated VPC with private instances
123+
- Scanner instances are distributed across multiple zones in a Managed Instance Group
124+
- Service account impersonation enables scanning of resources in the same project and cross-project
125+
- All scanner communication goes through Cloud NAT for outbound connectivity to Datadog
126+
127+
### Module Relationships
128+
129+
```mermaid
130+
flowchart TD
131+
subgraph "GCP Project A - Scanner Project"
132+
subgraph "Main Module"
133+
VPC[VPC Module]
134+
INST[Instance Module]
135+
VPC --> INST
136+
end
137+
138+
SSA[Scanner Service Account]
139+
SSA --> INST
140+
141+
ISA_A[Impersonated Service Account A]
142+
SSA -.impersonates.-> ISA_A
143+
ISA_A -.scans.-> RES_A[Compute Resources A]
144+
end
145+
146+
subgraph "GCP Project B - Other Project"
147+
ISA_B[Impersonated Service Account B]
148+
SSA -.impersonates.-> ISA_B
149+
ISA_B -.scans.-> RES_B[Compute Resources B]
150+
end
151+
```
152+
153+
### How It Works
154+
155+
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.
156+
157+
2. **Service Account Impersonation**: The scanner uses GCP's service account impersonation feature:
158+
- The scanner service account (attached to instances) impersonates the target service account
159+
- The target service account has the necessary permissions to read and scan compute resources
160+
- This allows for fine-grained access control and cross-project scanning
161+
162+
3. **High Availability**: Instances are deployed in a regional Managed Instance Group distributed across multiple zones, with auto-healing enabled.
47163

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.
164+
4. **Secure Credential Management**: The Datadog API key is stored in Google Secret Manager and accessed securely by the scanner instances.
54165

55166
<!-- BEGIN_TF_DOCS -->
56167
## Requirements

gcp/agentless_gcp_architecture.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)